Skip to content

Commit

Permalink
Fix : DOM Nesting in BreadCrumbs.tsx (ohcnetwork#9942)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustix69 authored Jan 15, 2025
1 parent 31aac73 commit 3e98ab7
Showing 1 changed file with 64 additions and 61 deletions.
125 changes: 64 additions & 61 deletions src/components/Common/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbList,
BreadcrumbSeparator,
} from "@/components/ui/breadcrumb";
import { Button } from "@/components/ui/button";
import {
Expand Down Expand Up @@ -82,88 +81,92 @@ export default function Breadcrumbs({
const renderCrumb = (crumb: any, index: number) => {
const isLastItem = index === crumbs!.length - 1;
return (
<li
<BreadcrumbItem
key={crumb.name}
className={classNames("text-sm font-normal", crumb.style)}
>
<div className="flex items-center">
<BreadcrumbSeparator className="text-gray-400" />
{isLastItem && <span className="text-gray-600">{crumb.name}</span>}
{!isLastItem ? (
<Button
asChild
variant="link"
className="p-1 font-normal text-gray-800 hover:text-gray-700"
>
<Link href={crumb.uri}>{crumb.name}</Link>
</Button>
) : (
<span className="text-gray-600">{crumb.name}</span>
)}
</div>
</li>
</BreadcrumbItem>
);
};

return (
<Breadcrumb>
<nav className={classNames("w-full", className)} aria-label="Breadcrumb">
<BreadcrumbList>
<ol className="flex flex-wrap items-center">
{!hideBack && (
<li className="mr-3 flex items-center">
<Button
variant="link"
type="button"
className="rounded bg-gray-200/50 px-1 text-sm font-normal text-gray-800 transition hover:bg-gray-200/75 hover:no-underline"
size="xs"
onClick={() => {
if (onBackClick && onBackClick() === false) return;
goBack(backUrl);
}}
>
<CareIcon icon="l-arrow-left" className="h-5 text-gray-700" />
<span className="pr-2">Back</span>
</Button>
</li>
)}
{!hideBack && (
<BreadcrumbItem>
<Button
asChild
variant="link"
className="p-1 font-normal text-gray-800 hover:text-gray-700"
type="button"
className="rounded bg-gray-200/50 px-1 text-sm font-normal text-gray-800 transition hover:bg-gray-200/75 hover:no-underline"
size="xs"
onClick={() => {
if (onBackClick && onBackClick() === false) return;
goBack(backUrl);
}}
>
<Link href="/">Home</Link>
<CareIcon icon="l-arrow-left" className="h-5 text-gray-700" />
<span className="pr-2">Back</span>
</Button>
</BreadcrumbItem>
{crumbs && crumbs.length > 1 && (
<>
{!showFullPath && (
<li>
<div className="flex items-center ml-[-2px]">
<BreadcrumbSeparator className="text-gray-400" />
<DropdownMenu>
<DropdownMenuTrigger asChild>
)}
<BreadcrumbItem>
<Button
asChild
variant="link"
className="p-1 font-normal text-gray-800 hover:text-gray-700"
>
<Link href="/">Home</Link>
</Button>
</BreadcrumbItem>
{crumbs && crumbs.length > 1 && (
<>
{!showFullPath && (
<BreadcrumbItem>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="link"
className="h-auto p-0 font-light text-gray-500 hover:text-gray-700"
onClick={() => setShowFullPath(true)}
>
•••
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
{crumbs.slice(0, -1).map((crumb, index) => (
<DropdownMenuItem key={index}>
<Button
asChild
variant="link"
className="h-auto p-0 font-light text-gray-500 hover:text-gray-700"
onClick={() => setShowFullPath(true)}
className="p-1 font-normal text-gray-800 underline underline-offset-2 hover:text-gray-700"
>
•••
<Link href={crumb.uri}>{crumb.name}</Link>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
{crumbs.slice(0, -1).map((crumb, index) => (
<DropdownMenuItem key={index}>
<Button
asChild
variant="link"
className="p-1 font-normal text-gray-800 underline underline-offset-2 hover:text-gray-700"
>
<Link href={crumb.uri}>{crumb.name}</Link>
</Button>
</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
</div>
</li>
)}
{showFullPath && crumbs.slice(0, -1).map(renderCrumb)}
</>
)}
{crumbs?.length &&
renderCrumb(crumbs[crumbs.length - 1], crumbs.length - 1)}
</ol>
</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
</BreadcrumbItem>
)}
{showFullPath && crumbs.slice(0, -1).map(renderCrumb)}
</>
)}
{crumbs?.length &&
renderCrumb(crumbs[crumbs.length - 1], crumbs.length - 1)}
</BreadcrumbList>
</nav>
</Breadcrumb>
Expand Down

0 comments on commit 3e98ab7

Please sign in to comment.