An open source design system that's fully customizable and agent ready
TypeScript
fix(core): forward pass-through props and apply className/style in MobileNav (#3872)
Cindy Zhang72ad5c228b6e
diff --git a/.changeset/mobilenav-forward-rest.md b/.changeset/mobilenav-forward-rest.mdnew file mode 100644index 0000000000..60cfceb615--- /dev/null+++ b/.changeset/mobilenav-forward-rest.md@@ -0,0 +1,8 @@+---+'@astryxdesign/core': patch+---++[fix] MobileNav forwards pass-through attributes and applies consumer className/style++MobileNav declared `BaseProps` but silently discarded `className`/`style` (destructured to unused vars) and dropped every other pass-through attribute (`id`, `aria-*`, `data-*` beyond `data-testid`, event handlers). It now merges `className`/`style` and spreads the remaining props onto the `<dialog>`, and composes a consumer `onClick` with the backdrop-dismiss handler via `composeEventHandlers`.+@cixzhangdiff --git a/packages/core/src/MobileNav/MobileNav.test.tsx b/packages/core/src/MobileNav/MobileNav.test.tsxindex b104a3e97f..8942d20385 100644--- a/packages/core/src/MobileNav/MobileNav.test.tsx+++ b/packages/core/src/MobileNav/MobileNav.test.tsx@@ -144,6 +144,62 @@ describe('MobileNav', () => {expect(screen.getByTestId('custom-nav')).toBeInTheDocument();});+ it('forwards arbitrary pass-through attributes to the dialog', () => {+ render(+ <MobileNav+ isOpen={true}+ onOpenChange={() => {}}+ data-testid="nav"+ id="main-nav"+ data-custom="x"+ aria-describedby="nav-desc">+ <span>Content</span>+ </MobileNav>,+ );++ const dialog = screen.getByTestId('nav');+ expect(dialog).toHaveAttribute('id', 'main-nav');+ expect(dialog).toHaveAttribute('data-custom', 'x');+ expect(dialog).toHaveAttribute('aria-describedby', 'nav-desc');+ });++ it('applies a consumer className and style to the dialog', () => {+ render(+ <MobileNav+ isOpen={true}+ onOpenChange={() => {}}+ data-testid="nav"+ className="consumer-class"+ style={{zIndex: 42}}>+ <span>Content</span>+ </MobileNav>,+ );++ const dialog = screen.getByTestId('nav');+ expect(dialog.className).toContain('consumer-class');+ expect(dialog.style.zIndex).toBe('42');+ });++ it('composes a consumer onClick with the backdrop-dismiss handler', () => {+ const onClick = vi.fn();+ const onOpenChange = vi.fn();+ render(+ <MobileNav+ isOpen={true}+ onOpenChange={onOpenChange}+ data-testid="nav"+ onClick={onClick}>+ <span>Content</span>+ </MobileNav>,+ );++ // Clicking the dialog element itself (the backdrop) dismisses AND calls the+ // consumer handler.+ fireEvent.click(screen.getByTestId('nav'));+ expect(onClick).toHaveBeenCalledTimes(1);+ expect(onOpenChange).toHaveBeenCalledWith(false);+ });+it('uses native dialog element', () => {render(<MobileNavdiff --git a/packages/core/src/MobileNav/MobileNav.tsx b/packages/core/src/MobileNav/MobileNav.tsxindex 2256186b9f..5b804cc2d6 100644--- a/packages/core/src/MobileNav/MobileNav.tsx+++ b/packages/core/src/MobileNav/MobileNav.tsx@@ -46,7 +46,7 @@ import {Button} from '../Button';import {Icon} from '../Icon';import {Heading} from '../Heading/Heading';import {useAppShellMobile} from '../AppShell/AppShellMobileContext';-import {mergeProps, mergeRefs} from '../utils';+import {mergeProps, mergeRefs, composeEventHandlers} from '../utils';import type {BaseProps} from '../BaseProps';import {themeProps} from '../utils/themeProps';@@ -284,9 +284,11 @@ export function MobileNav({label,'data-testid': testId,xstyle,- className: _className,- style: _style,+ className,+ style,+ onClick: onClickProp,ref,+ ...rest}: MobileNavProps) {// Read from AppShell context as fallbackconst appShellMobile = useAppShellMobile();@@ -407,10 +409,6 @@ export function MobileNav({return (<dialogref={mergeRefs(ref, dialogRef)}- data-testid={testId}- aria-label={label ?? (typeof header === 'string' ? header : 'Navigation')}- onClick={handleDialogClick}- onCancel={handleCancel}{...mergeProps(themeProps('mobile-nav', {side: resolvedSide}),stylex.props(@@ -420,7 +418,14 @@ export function MobileNav({isOpen && styles.backdropOpen,xstyle,),- )}>+ className,+ style,+ )}+ {...rest}+ data-testid={testId}+ aria-label={label ?? (typeof header === 'string' ? header : 'Navigation')}+ onClick={composeEventHandlers(onClickProp, handleDialogClick)}+ onCancel={handleCancel}>{/* Drawer panel — tabIndex so showModal() focuses the drawer, not the close button */}<divtabIndex={-1}