Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix:added ellipsis for long value in breadcrumb
  • Loading branch information
TenzDelek committed Jul 21, 2024
commit 74c635753935190bbaace637015180fbd68a765c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.list {
@apply flex
w-full
items-center
gap-5;
gap-5
pl-2;
}
12 changes: 11 additions & 1 deletion apps/site/components/Common/Breadcrumbs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type BreadcrumbsProps = {
maxLength?: number;
hideHome?: boolean;
};
// Convert link.label to string and get its length

const Breadcrumbs: FC<BreadcrumbsProps> = ({
links = [],
Expand All @@ -28,6 +29,13 @@ const Breadcrumbs: FC<BreadcrumbsProps> = ({
const lengthOffset = maxLength - totalLength;
const isOverflow = lengthOffset < 0;

const formatLabelWithWordCount = (label: string, maxWords: number) => {
const words = label.split(' ');
if (words.length > maxWords) {
return <>{words.slice(0, maxWords).join(' ')} ...</>;
}
return label;
};
const items = useMemo(
() =>
links.map((link, index, items) => {
Expand All @@ -37,6 +45,8 @@ const Breadcrumbs: FC<BreadcrumbsProps> = ({
// We add 1 here to take into account of the truncated breadcrumb.
position <= Math.abs(lengthOffset) + 1 && isOverflow && !isLastItem;

const labelString = link.label.toString();
const formattedLabel = formatLabelWithWordCount(labelString, 6);
return (
<BreadcrumbItem
key={link.label.toString()}
Expand All @@ -45,7 +55,7 @@ const Breadcrumbs: FC<BreadcrumbsProps> = ({
position={position + +!hideHome}
>
<BreadcrumbLink href={link.href} active={isLastItem}>
{link.label}
<div className=" text-center">{formattedLabel}</div>
</BreadcrumbLink>
</BreadcrumbItem>
);
Expand Down