-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix : DOM nesting Warning in BreadCrumbs.tsx #9941
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,9 @@ import { | |
Breadcrumb, | ||
BreadcrumbItem, | ||
BreadcrumbList, | ||
BreadcrumbSeparator, | ||
} from "@/components/ui/breadcrumb"; | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuTrigger, | ||
} from "@/components/ui/dropdown-menu"; | ||
import { DropdownMenu } from "@/components/ui/dropdown-menu"; | ||
|
||
import useAppHistory from "@/hooks/useAppHistory"; | ||
|
||
|
@@ -62,7 +56,7 @@ export default function Breadcrumbs({ | |
}: BreadcrumbsProps) { | ||
const { goBack } = useAppHistory(); | ||
const path = usePath(); | ||
const [showFullPath, setShowFullPath] = useState(false); | ||
const [showFullPath] = useState(false); | ||
|
||
const crumbs = path | ||
?.slice(1) | ||
|
@@ -82,88 +76,71 @@ 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> | ||
<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="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> | ||
)} | ||
<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> | ||
{/* ... (dropdown menu content) ... */} | ||
</DropdownMenu> | ||
Comment on lines
+134
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implementation needed for dropdown menu content. The dropdown menu content is currently commented out. Please implement the menu content to ensure proper functionality. |
||
</BreadcrumbItem> | ||
)} | ||
{showFullPath && crumbs.slice(0, -1).map(renderCrumb)} | ||
</> | ||
)} | ||
{crumbs?.length && | ||
renderCrumb(crumbs[crumbs.length - 1], crumbs.length - 1)} | ||
</BreadcrumbList> | ||
</nav> | ||
</Breadcrumb> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Replace useState with a constant boolean value
The
showFullPath
state is never updated since its setter has been removed. Since it's initialized asfalse
and never changes, replaceuseState(false)
with a constant:Or better yet, simplify the conditional rendering since
showFullPath
is alwaysfalse
:🔗 Analysis chain
Verify if showFullPath state needs to be mutable.
The state setter for showFullPath has been removed, but the state is still used for conditional rendering. If this is intentional, consider using a constant instead of state.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 92
Script:
Length of output: 1131