Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(DropdownMenuDivider): forward host attributes to the separator (#7645)

Cindy Zhang9da2d0b3936a
diff --git a/.changeset/dropdown-menu-divider-host-props.md b/.changeset/dropdown-menu-divider-host-props.md
new file mode 100644
index 0000000000..ad44d8f8fc
--- /dev/null
+++ b/.changeset/dropdown-menu-divider-host-props.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] `DropdownMenuDivider` now forwards host attributes and DOM handlers (`id`, `data-*`, `aria-*`, event handlers) to its separator, as other DOM-owning components do. Before, it accepted only `xstyle`, `className`, `style` and `ref` and dropped everything else, so a separator could not carry a test id or an accessible label. Its `role="separator"` and orientation stay component-owned.
+
+@cixzhang
diff --git a/packages/core/src/DropdownMenu/DropdownMenu.test.tsx b/packages/core/src/DropdownMenu/DropdownMenu.test.tsx
index 0d7e81ec93..67cb5d419b 100644
--- a/packages/core/src/DropdownMenu/DropdownMenu.test.tsx
+++ b/packages/core/src/DropdownMenu/DropdownMenu.test.tsx
@@ -2508,6 +2508,27 @@ describe('DropdownMenu data/compound parity', () => {
expect(fromCompound).toHaveClass('astryx-dropdown-menu-divider');
});
+ it('forwards host attributes to a compound divider while keeping its role', () => {
+ render(
+ <DropdownMenu button={{label: 'Actions'}}>
+ <DropdownMenuItem label="Edit" />
+ <DropdownMenuDivider
+ id="menu-sep"
+ data-testid="menu-separator"
+ aria-label="Danger zone"
+ // @ts-expect-error role is component-owned
+ role="presentation"
+ />
+ <DropdownMenuItem label="Delete" />
+ </DropdownMenu>,
+ );
+ const separator = screen.getByTestId('menu-separator');
+ expect(separator).toHaveAttribute('id', 'menu-sep');
+ expect(separator).toHaveAttribute('aria-label', 'Danger zone');
+ expect(separator).toHaveAttribute('role', 'separator');
+ expect(separator).toHaveClass('astryx-dropdown-menu-divider');
+ });
+
it('skips a compound divider in the arrow-key order', async () => {
const user = userEvent.setup();
render(
diff --git a/packages/core/src/DropdownMenu/DropdownMenuDivider.doc.mjs b/packages/core/src/DropdownMenu/DropdownMenuDivider.doc.mjs
index e9c082916a..313f91d3c5 100644
--- a/packages/core/src/DropdownMenu/DropdownMenuDivider.doc.mjs
+++ b/packages/core/src/DropdownMenu/DropdownMenuDivider.doc.mjs
@@ -8,7 +8,7 @@ export const docs = {
displayName: 'Dropdown Menu Divider',
isHiddenFromOverview: true,
description:
- 'A horizontal rule separating groups of rows in a compound menu. Renders role="separator", so it is never a stop in the arrow-key order. The data-driven equivalent is the `{type: "divider"}` entry in `items`; both modes render this component, so they look and theme identically.',
+ 'A horizontal rule separating groups of rows in a compound menu. Renders role="separator", so it is never a stop in the arrow-key order. The data-driven equivalent is the `{type: "divider"}` entry in `items`; both modes render this component, so they look and theme identically. Host attributes and DOM handlers (id, data-*, aria-*) reach the separator; its role and orientation stay component-owned.',
props: [
{
name: 'xstyle',
@@ -27,7 +27,7 @@ export const docsDense = {
isHiddenFromOverview: true,
displayName: 'Dropdown Menu Divider',
description:
- 'separator row for compound menus; compound peer of the data API\'s {type: "divider"}',
+ 'separator row for compound menus; compound peer of the data API\'s {type: "divider"}; host attributes reach the separator, role/orientation stay owned',
propDescriptions: {
xstyle: 'StyleX styles applied after the menu spacing',
},
diff --git a/packages/core/src/DropdownMenu/DropdownMenuDivider.tsx b/packages/core/src/DropdownMenu/DropdownMenuDivider.tsx
index bc77a497e3..b8dbdeedc3 100644
--- a/packages/core/src/DropdownMenu/DropdownMenuDivider.tsx
+++ b/packages/core/src/DropdownMenu/DropdownMenuDivider.tsx
@@ -4,7 +4,7 @@
/**
* @file DropdownMenuDivider.tsx
- * @input Uses Divider, spacing tokens, themeProps
+ * @input Uses Divider, spacing tokens, themeProps; forwards host props to Divider
* @output Exports DropdownMenuDivider component and DropdownMenuDividerProps
* @position Sub-component; used inside DropdownMenu
*
@@ -37,9 +37,9 @@ const styles = stylex.create({
const THEME_CLASS_NAME = themeProps('dropdown-menu-divider').className;
-export interface DropdownMenuDividerProps extends Pick<
- BaseProps,
- 'xstyle' | 'className' | 'style'
+export interface DropdownMenuDividerProps extends Omit<
+ BaseProps<HTMLDivElement>,
+ 'role' | 'aria-orientation'
> {
/** Ref forwarded to the separator element. */
ref?: React.Ref<HTMLDivElement>;
@@ -49,7 +49,9 @@ export interface DropdownMenuDividerProps extends Pick<
* A horizontal rule separating groups of menu rows.
*
* Renders `role="separator"`, so it is never a stop in the menu's arrow-key
- * order. Equivalent to `{type: 'divider'}` in the `items` data API.
+ * order. Equivalent to `{type: 'divider'}` in the `items` data API. Host
+ * attributes (`id`, `data-*`, `aria-*`) and DOM handlers reach the separator;
+ * its role and orientation stay component-owned.
*
* @example
* ```
@@ -65,9 +67,11 @@ export function DropdownMenuDivider({
className,
style,
ref,
+ ...rest
}: DropdownMenuDividerProps) {
return (
<Divider
+ {...rest}
ref={ref}
xstyle={[styles.divider, xstyle]}
className={