An open source design system that's fully customizable and agent ready
TypeScript
fix(core): forward unhandled pass-through attributes on native-root components (#3871)
Cindy Zhang76a53e497e9e
diff --git a/.changeset/native-rest-forwarding.md b/.changeset/native-rest-forwarding.mdnew file mode 100644index 0000000000..1b68058612--- /dev/null+++ b/.changeset/native-rest-forwarding.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Forward unhandled pass-through attributes (`data-testid`, `aria-*`, `id`, etc.) to the primary rendered element of Switch, Pagination, RadioListItem, SideNavSection, TableHeader/TableBody/TableFooter, and TopNavMegaMenuFeaturedCard. These components previously dropped attributes not explicitly consumed, so test hooks and accessibility attributes silently disappeared.++@cixzhangdiff --git a/packages/core/src/Pagination/Pagination.test.tsx b/packages/core/src/Pagination/Pagination.test.tsxindex 3b263782aa..cc41b673f4 100644--- a/packages/core/src/Pagination/Pagination.test.tsx+++ b/packages/core/src/Pagination/Pagination.test.tsx@@ -903,4 +903,23 @@ describe('Pagination', () => {).not.toBeInTheDocument();});});++ describe('rest forwarding', () => {+ it('forwards data-testid, id, and aria-* to the root nav', () => {+ const {container} = render(+ <Pagination+ page={1}+ onChange={() => {}}+ totalPages={3}+ data-testid="pager"+ id="pager-1"+ aria-describedby="hint"+ />,+ );+ const nav = container.querySelector('nav')!;+ expect(nav).toHaveAttribute('data-testid', 'pager');+ expect(nav).toHaveAttribute('id', 'pager-1');+ expect(nav).toHaveAttribute('aria-describedby', 'hint');+ });+ });});diff --git a/packages/core/src/Pagination/Pagination.tsx b/packages/core/src/Pagination/Pagination.tsxindex 57505565f1..c82fbaf674 100644--- a/packages/core/src/Pagination/Pagination.tsx+++ b/packages/core/src/Pagination/Pagination.tsx@@ -350,6 +350,7 @@ export function Pagination({className,style,ref,+ ...rest}: PaginationProps) {const [, startTransition] = useTransition();@@ -610,14 +611,15 @@ export function Pagination({return (<navref={ref}- aria-label={label}- data-testid={testId}{...mergeProps(themeProps('pagination', {variant, size}),stylex.props(styles.root, xstyle),className,style,- )}>+ )}+ {...rest}+ aria-label={label}+ data-testid={testId}>{pageSizeOptions != null && pageSizeOptions.length > 0 && (<div {...stylex.props(styles.pageSizeSelector)}><div {...stylex.props(styles.pageSizeSelectorControl)}>diff --git a/packages/core/src/RadioList/RadioList.test.tsx b/packages/core/src/RadioList/RadioList.test.tsxindex 7b3bdb2e75..d6af05d6f9 100644--- a/packages/core/src/RadioList/RadioList.test.tsx+++ b/packages/core/src/RadioList/RadioList.test.tsx@@ -622,4 +622,23 @@ describe('RadioList', () => {expect(input.getAttribute('name')).toBeTruthy();});});++ describe('RadioListItem rest forwarding', () => {+ it('forwards data-testid, id, and aria-* to the item root element', () => {+ render(+ <RadioList label="Preference" value="" onChange={() => {}}>+ <RadioListItem+ label="Option A"+ value="a"+ data-testid="item-a"+ id="item-a-id"+ aria-label="First option"+ />+ </RadioList>,+ );+ const item = screen.getByTestId('item-a');+ expect(item).toHaveAttribute('id', 'item-a-id');+ expect(item).toHaveAttribute('aria-label', 'First option');+ });+ });});diff --git a/packages/core/src/RadioList/RadioListItem.tsx b/packages/core/src/RadioList/RadioListItem.tsxindex de972ee355..5a0c9ed45d 100644--- a/packages/core/src/RadioList/RadioListItem.tsx+++ b/packages/core/src/RadioList/RadioListItem.tsx@@ -220,7 +220,10 @@ export function RadioListItem({isDisabled: isItemDisabled = false,startContent,endContent,- 'data-testid': dataTestId,+ xstyle,+ className,+ style,+ ...rest}: RadioListItemProps) {const context = use(RadioListContext);if (!context) {@@ -313,11 +316,13 @@ export function RadioListItem({return (<divref={ref}- data-testid={dataTestId}{...mergeProps(themeProps('radio-list-item'),- stylex.props(styles.container, !isDisabled && radioScope),- )}>+ stylex.props(styles.container, !isDisabled && radioScope, xstyle),+ className,+ style,+ )}+ {...rest}><ItemstartContent={mediaContent}label={diff --git a/packages/core/src/SideNav/SideNav.test.tsx b/packages/core/src/SideNav/SideNav.test.tsxindex 6c75c34105..749807f231 100644--- a/packages/core/src/SideNav/SideNav.test.tsx+++ b/packages/core/src/SideNav/SideNav.test.tsx@@ -754,6 +754,17 @@ describe('SideNavSection', () => {const group = screen.getByRole('group');expect(group.style.marginTop).toBe('16px');});++ it('forwards arbitrary pass-through attributes (id, aria-*) to root element', () => {+ render(+ <SideNavSection title="Main" id="section-1" aria-describedby="hint">+ <SideNavItem label="Dashboard" />+ </SideNavSection>,+ );+ const group = screen.getByRole('group');+ expect(group).toHaveAttribute('id', 'section-1');+ expect(group).toHaveAttribute('aria-describedby', 'hint');+ });});// =============================================================================diff --git a/packages/core/src/SideNav/SideNavSection.tsx b/packages/core/src/SideNav/SideNavSection.tsxindex b82c90628f..a4deadd3eb 100644--- a/packages/core/src/SideNav/SideNavSection.tsx+++ b/packages/core/src/SideNav/SideNavSection.tsx@@ -145,6 +145,7 @@ export function SideNavSection({className,style,'data-testid': testId,+ ...rest}: SideNavSectionProps) {const {isCollapsed} = useSideNavCollapse();const id = useId();@@ -183,15 +184,16 @@ export function SideNavSection({return (<divref={ref}- role="group"- aria-labelledby={titleId}- data-testid={testId}{...mergeProps(themeProps('side-nav-section'),stylex.props(styles.root, xstyle),className,style,- )}>+ )}+ {...rest}+ role="group"+ aria-labelledby={titleId}+ data-testid={testId}><div{...mergeProps(stylex.props(styles.header), {style: shouldHideHeader ? visuallyHiddenStyle : undefined,diff --git a/packages/core/src/Switch/Switch.test.tsx b/packages/core/src/Switch/Switch.test.tsxindex 61ea5246fc..cc0b17e8fd 100644--- a/packages/core/src/Switch/Switch.test.tsx+++ b/packages/core/src/Switch/Switch.test.tsx@@ -588,4 +588,23 @@ describe('Switch', () => {expect([...data.keys()]).toEqual([]);});});++ describe('rest forwarding', () => {+ it('forwards data-testid, id, and aria-* to the root element', () => {+ const {container} = render(+ <Switch+ label="Notifications"+ value={false}+ onChange={() => {}}+ data-testid="my-switch"+ id="switch-1"+ aria-label="Toggle notifications"+ />,+ );+ const root = container.querySelector('[data-testid="my-switch"]');+ expect(root).not.toBeNull();+ expect(root).toHaveAttribute('id', 'switch-1');+ expect(root).toHaveAttribute('aria-label', 'Toggle notifications');+ });+ });});diff --git a/packages/core/src/Switch/Switch.tsx b/packages/core/src/Switch/Switch.tsxindex c5aac725c2..3f5c65b325 100644--- a/packages/core/src/Switch/Switch.tsx+++ b/packages/core/src/Switch/Switch.tsx@@ -363,6 +363,7 @@ export function Switch({className,style,ref,+ ...rest}: SwitchProps) {const id = useId();const descriptionID = useId();@@ -503,7 +504,8 @@ export function Switch({stylex.props(width != null && dynamicWidthStyles.width(width), xstyle),className,style,- )}>+ )}+ {...rest}><divref={el => {// Interaction (hover/focus) listeners for the disabled-messagediff --git a/packages/core/src/Table/Table.test.tsx b/packages/core/src/Table/Table.test.tsxindex a0576db578..5605d1bfca 100644--- a/packages/core/src/Table/Table.test.tsx+++ b/packages/core/src/Table/Table.test.tsx@@ -15,6 +15,9 @@ import {BaseTable} from './BaseTable';import {Table} from './Table';import {TableRow} from './TableRow';import {TableCell} from './TableCell';+import {TableHeader} from './TableHeader';+import {TableBody} from './TableBody';+import {TableFooter} from './TableFooter';import {proportional,pixel,@@ -1283,4 +1286,37 @@ describe('emptyState', () => {expect(screen.getByText('Name')).toBeInTheDocument();expect(screen.getByText('Age')).toBeInTheDocument();});++ describe('table section rest forwarding', () => {+ it('forwards data-testid and id to the tbody, thead, and tfoot', () => {+ const {container} = render(+ <table>+ <TableHeader data-testid="thead" id="head-1">+ <tr>+ <th>H</th>+ </tr>+ </TableHeader>+ <TableBody data-testid="tbody" id="body-1">+ <tr>+ <td>B</td>+ </tr>+ </TableBody>+ <TableFooter data-testid="tfoot" id="foot-1">+ <tr>+ <td>F</td>+ </tr>+ </TableFooter>+ </table>,+ );+ const thead = container.querySelector('thead')!;+ const tbody = container.querySelector('tbody')!;+ const tfoot = container.querySelector('tfoot')!;+ expect(thead).toHaveAttribute('data-testid', 'thead');+ expect(thead).toHaveAttribute('id', 'head-1');+ expect(tbody).toHaveAttribute('data-testid', 'tbody');+ expect(tbody).toHaveAttribute('id', 'body-1');+ expect(tfoot).toHaveAttribute('data-testid', 'tfoot');+ expect(tfoot).toHaveAttribute('id', 'foot-1');+ });+ });});diff --git a/packages/core/src/Table/TableBody.tsx b/packages/core/src/Table/TableBody.tsxindex 7432e4f9b1..b4505f84d0 100644--- a/packages/core/src/Table/TableBody.tsx+++ b/packages/core/src/Table/TableBody.tsx@@ -13,11 +13,24 @@ export interface TableBodyProps extends BaseProps<HTMLTableSectionElement> {children: ReactNode;}-export function TableBody({ref, children, xstyle}: TableBodyProps) {+export function TableBody({+ ref,+ children,+ xstyle,+ className,+ style,+ ...rest+}: TableBodyProps) {return (<tbodyref={ref}- {...mergeProps(themeProps('table-body'), stylex.props(xstyle))}>+ {...mergeProps(+ themeProps('table-body'),+ stylex.props(xstyle),+ className,+ style,+ )}+ {...rest}>{children}</tbody>);diff --git a/packages/core/src/Table/TableFooter.tsx b/packages/core/src/Table/TableFooter.tsxindex a542c76f9d..e64b31b42e 100644--- a/packages/core/src/Table/TableFooter.tsx+++ b/packages/core/src/Table/TableFooter.tsx@@ -13,11 +13,24 @@ export interface TableFooterProps extends BaseProps<HTMLTableSectionElement> {children: ReactNode;}-export function TableFooter({ref, children, xstyle}: TableFooterProps) {+export function TableFooter({+ ref,+ children,+ xstyle,+ className,+ style,+ ...rest+}: TableFooterProps) {return (<tfootref={ref}- {...mergeProps(themeProps('table-footer'), stylex.props(xstyle))}>+ {...mergeProps(+ themeProps('table-footer'),+ stylex.props(xstyle),+ className,+ style,+ )}+ {...rest}>{children}</tfoot>);diff --git a/packages/core/src/Table/TableHeader.tsx b/packages/core/src/Table/TableHeader.tsxindex e03d7286f3..c147d056f2 100644--- a/packages/core/src/Table/TableHeader.tsx+++ b/packages/core/src/Table/TableHeader.tsx@@ -13,11 +13,24 @@ export interface TableHeaderProps extends BaseProps<HTMLTableSectionElement> {children: ReactNode;}-export function TableHeader({ref, children, xstyle}: TableHeaderProps) {+export function TableHeader({+ ref,+ children,+ xstyle,+ className,+ style,+ ...rest+}: TableHeaderProps) {return (<theadref={ref}- {...mergeProps(themeProps('table-header'), stylex.props(xstyle))}>+ {...mergeProps(+ themeProps('table-header'),+ stylex.props(xstyle),+ className,+ style,+ )}+ {...rest}>{children}</thead>);diff --git a/packages/core/src/TopNav/TopNav.test.tsx b/packages/core/src/TopNav/TopNav.test.tsxindex e513c684a8..3406a8c8df 100644--- a/packages/core/src/TopNav/TopNav.test.tsx+++ b/packages/core/src/TopNav/TopNav.test.tsx@@ -16,6 +16,7 @@ import {TopNav} from './TopNav';import {TopNavHeading} from './TopNavHeading';import {NavIcon} from '../NavIcon';import {TopNavItem} from './TopNavItem';+import {TopNavMegaMenuFeaturedCard} from './TopNavMegaMenuFeaturedCard';import {LinkProvider} from '../Link/LinkProvider';function CustomLink({@@ -398,4 +399,21 @@ describe('TopNavItem', () => {expect(link).toHaveAttribute('data-custom-link');expect(link).not.toHaveAttribute('data-another-link');});++ describe('TopNavMegaMenuFeaturedCard rest forwarding', () => {+ it('forwards data-testid, id, and aria-* to the root element', () => {+ render(+ <TopNavMegaMenuFeaturedCard+ title="What's new"+ description="Details"+ data-testid="featured-card"+ id="card-1"+ aria-label="Featured"+ />,+ );+ const card = screen.getByTestId('featured-card');+ expect(card).toHaveAttribute('id', 'card-1');+ expect(card).toHaveAttribute('aria-label', 'Featured');+ });+ });});diff --git a/packages/core/src/TopNav/TopNavMegaMenuFeaturedCard.tsx b/packages/core/src/TopNav/TopNavMegaMenuFeaturedCard.tsxindex ebdc802f23..5c3ea0deea 100644--- a/packages/core/src/TopNav/TopNavMegaMenuFeaturedCard.tsx+++ b/packages/core/src/TopNav/TopNavMegaMenuFeaturedCard.tsx@@ -132,6 +132,10 @@ export function TopNavMegaMenuFeaturedCard({linkLabel,linkHref,children,+ xstyle,+ className,+ style,+ ...rest}: TopNavMegaMenuFeaturedCardProps) {const LinkComponent = useLinkComponent();return (@@ -139,8 +143,11 @@ export function TopNavMegaMenuFeaturedCard({ref={ref}{...mergeProps(themeProps('top-nav-mega-menu-featured-card'),- stylex.props(styles.root),- )}>+ stylex.props(styles.root, xstyle),+ className,+ style,+ )}+ {...rest}>{image && (<img src={image} alt={imageAlt ?? ''} {...stylex.props(styles.image)} />)}