feat(content-docs): allow setting class name for category link#6249
feat(content-docs): allow setting class name for category link#6249
Conversation
|
✔️ [V2] 🔨 Explore the source changes: 8703ac1 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/61d2c27e48c7e90007e58c48 😎 Browse the preview: https://deploy-preview-6249--docusaurus-2.netlify.app |
|
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-6249--docusaurus-2.netlify.app/ |
|
Size Change: +2.23 kB (0%) Total Size: 672 kB
ℹ️ View Unchanged
|
| type: 'doc', | ||
| id: categoryLinkedDocId, // We "remap" a potentially "local id" to a "qualified id" | ||
| className: | ||
| categoryMetadata?.link?.className ?? |
There was a problem hiding this comment.
we already have categoryMetadata?.className and it solves user reported use-case, why introduce a new categoryMetadata?.link?.className here?
You could do this instead:
category.className = categoryMetadata?.className ?? getDoc(link.id).frontMatter.sidebar_class_name| export type SidebarItemCategoryLinkDoc = { | ||
| type: 'doc'; | ||
| id: string; | ||
| className?: string; |
There was a problem hiding this comment.
Is this new attribute really necessary? What's the advantage of having it instead of reusing the existing category className? Will this be applied to something else that is not the category?
| ThemeClassNames.docs.docSidebarItemCategoryLink, | ||
| ThemeClassNames.docs.docSidebarItemCategoryLinkLevel(level), | ||
| 'menu__list-item-collapsible', | ||
| linkClassName, |
There was a problem hiding this comment.
The user wanted the className to be applied to the <li> item, so may not exactly solve the user problem
| <div | ||
| className={clsx( | ||
| ThemeClassNames.docs.docSidebarItemCategoryLink, | ||
| ThemeClassNames.docs.docSidebarItemCategoryLinkLevel(level), |
There was a problem hiding this comment.
do we really need those extra classes stable? What's the purpose?
I know we want stable selectors but IMHO on parent it's good enough, it's quite easy to target the first child div once we can target the parent reliably
| frontMatter: {sidebar_label: sidebarLabel}, | ||
| frontMatter: { | ||
| sidebar_label: sidebarLabel, | ||
| sidebar_class_name: sidebarClassName, |
There was a problem hiding this comment.
sidebar_class_name intuitively implies to me that it will apply as well to doc items in the sidebar, and not just category
Maybe we should make it more explicit?
sidebar_category_class_name ? Or apply to doc and categories both?
|
So we have a category class name already, but this one targets the entire category dropdown rather than the link itself. (I designed it like that initially because at that time there wasn't the extra |
Agree that we could add another semantic selector here, but that seems like a different subject. Does a new When using This frontmatter should allow customizing a whole category li item, including subitems. If it's only applied to the child div, it's less powerful and it's definitively not what the original issue asked for. We should be able to write something like: .theme-doc-sidebar-item-category-group.green > .theme-doc-sidebar-item-category > a {
color: green;
}But also .theme-doc-sidebar-item-category-group.green {
border-left: solid green;
}Also I think the current desing/API is mixing 2 things: the category linking feature, and the sidebar category label link. Those share some "link" terminology but are not strictly related. And it's even weird that you have a |
|
Wait, eh? I didn't realize they wanted it on the In that case, maybe that issue is actually related to #6254? Can we guarantee DOM stability in the future? In that case we may just recommend I implemented the link class name as targeting |
Yes it's related, see my previous comment :) We should apply
I don't really like to guarantee DOM structure stability, so there's probably still value in creating a sub-selector for the category "row" (excluding child), but not sure how to find good names 🤷♂️ However I don't think this selector is likely to be refactored so it should be pretty stable anyway. In general, I think our public API surface is the theme components interface and stable CSS classNames. All other CSS and HTML structures should be considered as implementation details, subject to change. |
You mean
Same reason for applying the className on |
No, I mean
Yes, absolutely no objection to applying class name to So the resolution is:
|
|
yes 👍 But should the new stable selector apply to the div or the a? What could be a good name for it? |
|
Going to close this as it's not in the right direction |

Motivation
Close #6232.
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Added a dogfood example