An open source design system that's fully customizable and agent ready
TypeScript
fix(SideNavItem): keep a caller's className on the row element (#7772)
Cindy Zhang3c1d32d9a659
diff --git a/.changeset/sidenav-item-row-classname.md b/.changeset/sidenav-item-row-classname.mdnew file mode 100644index 0000000000..de9e583ac8--- /dev/null+++ b/.changeset/sidenav-item-row-classname.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] `SideNavItem` keeps a caller's `className` on its row element (the link or button, and the collapsed rail item) next to its own classes. Before, the row's generated class replaced it, so a class passed to style the row (for example, a cursor while a row is dragged) never reached the DOM, even though `style`, ARIA, data attributes and handlers did.++@cixzhangdiff --git a/packages/core/src/SideNav/SideNav.test.tsx b/packages/core/src/SideNav/SideNav.test.tsxindex 5e11d58ad3..5acfcaecf4 100644--- a/packages/core/src/SideNav/SideNav.test.tsx+++ b/packages/core/src/SideNav/SideNav.test.tsx@@ -928,6 +928,47 @@ describe('SideNavItem', () => {expect(indentOf(security)).toBe('calc(1 * var(--spacing-6))');});+ it("keeps a caller's className on the row element", () => {+ render(+ <SideNavItem label="Settings">+ <SideNavItem+ label="General"+ href="/settings/general"+ className="caller-row"+ />+ <SideNavItem+ label="Security"+ href="/settings/security"+ className="caller-row">+ <SideNavItem label="Keys" href="/settings/security/keys" />+ </SideNavItem>+ </SideNavItem>,+ );+ // Ordinary row: the link is the row, and the caller's class sits beside+ // the row's own classes instead of being replaced by them.+ const general = screen.getByRole('link', {name: 'General'});+ expect(general).toHaveClass('caller-row');+ expect(general).toHaveClass('astryx-side-nav-item');+ // Split row: the class lands on the primary link, as `style` does.+ expect(screen.getByRole('link', {name: 'Security'})).toHaveClass(+ 'caller-row',+ );+ });++ it("keeps a caller's className on a collapsed rail item", () => {+ render(+ <SideNav collapsible={{isCollapsed: true, hasButton: false}}>+ <SideNavItem+ label="Home"+ href="/"+ icon="calendar"+ className="caller-row"+ />+ </SideNav>,+ );+ expect(screen.getByRole('link', {name: 'Home'})).toHaveClass('caller-row');+ });+it("lets a caller's inline-start padding replace the indent", () => {// The caller's `style` composes after the indent: a caller-set// inline-start padding is an inline declaration, so it wins over thediff --git a/packages/core/src/SideNav/SideNavItem.tsx b/packages/core/src/SideNav/SideNavItem.tsxindex e0cd86d695..0beb29afd2 100644--- a/packages/core/src/SideNav/SideNavItem.tsx+++ b/packages/core/src/SideNav/SideNavItem.tsx@@ -634,6 +634,8 @@ export function SideNavItem({isSelected && navItemStyles.selected,isDisabled && navItemStyles.disabled,),+ // Spread after `rest`, so keep the caller's class beside these.+ rest.className,),...pressable,};@@ -752,8 +754,9 @@ export function SideNavItem({// The indent is a runtime value, so it reaches the element as an inline// style. These props are spread after `rest`, so fold the caller's `style`- // back in (caller wins) rather than letting the indent replace it.- const callerStyle = {style: rest.style};+ // back in (caller wins) rather than letting the indent replace it, and the+ // caller's `className` beside the row's own classes.+ const callerStyle = {className: rest.className, style: rest.style};// Three shapes of the same row appearance:// - `rowProps` — split-action path (toggle, no actions): presentational