diff --git a/.changeset/overlay-dropdown-menu-group-host-props.md b/.changeset/overlay-dropdown-menu-group-host-props.md
new file mode 100644
index 0000000000000..b88802b50691c
--- /dev/null
+++ b/.changeset/overlay-dropdown-menu-group-host-props.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] `Overlay`, `DropdownMenuGroup` and `MobileNavToggle` now forward host attributes and DOM handlers (`id`, `data-*`, `aria-*`, event handlers) to the element each one owns, as other DOM-owning components do. Before, `Overlay` and `DropdownMenuGroup` accepted only `xstyle`, `className`, `style` and `ref` and dropped everything else, so a test id or analytics attribute on either never reached the page; `MobileNavToggle` also forwarded `data-testid`, but no other `data-*`, `id`, `aria-*` or handler. Built-in behavior stays component-owned: `Overlay`'s touch toggle and `MobileNavToggle`'s drawer toggle run on every press, before a caller handler; `DropdownMenuGroup` keeps its `role="group"` and, while it has a `title`, keeps that title as its name; `MobileNavToggle` keeps its `aria-expanded` and `aria-controls`.
+
+@kentonquatman
diff --git a/packages/core/src/DropdownMenu/DropdownMenu.test.tsx b/packages/core/src/DropdownMenu/DropdownMenu.test.tsx
index b154b7cfb6107..2b7ab6da0a3dc 100644
--- a/packages/core/src/DropdownMenu/DropdownMenu.test.tsx
+++ b/packages/core/src/DropdownMenu/DropdownMenu.test.tsx
@@ -1779,6 +1779,49 @@ describe('DropdownMenuGroup (compound mode)', () => {
screen.getByRole('group', {name: 'T', hidden: true}),
);
});
+
+ it('forwards host attributes to the group while keeping its role and heading name', () => {
+ render(
+
+
+ {}} />
+
+ ,
+ );
+ const group = screen.getByTestId('history');
+ expect(group).toHaveAttribute('data-analytics-id', 'menu-history');
+ expect(group).toHaveAttribute('id', 'history-group');
+ expect(group).toHaveAttribute('aria-describedby', 'history-hint');
+ expect(group).toHaveAttribute('role', 'group');
+ // The visible title keeps naming the group.
+ expect(
+ screen.getByRole('group', {name: 'Version history', hidden: true}),
+ ).toBe(group);
+ });
+
+ it('an untitled group takes a caller-supplied accessible name', () => {
+ render(
+
+ Recent
+
+ {}} />
+
+ ,
+ );
+ const group = screen.getByTestId('recent');
+ expect(group).toHaveAttribute('aria-labelledby', 'recent-label');
+ expect(screen.getByRole('group', {name: 'Recent', hidden: true})).toBe(
+ group,
+ );
+ });
});
describe('DropdownMenu dividers', () => {
diff --git a/packages/core/src/DropdownMenu/DropdownMenuGroup.doc.mjs b/packages/core/src/DropdownMenu/DropdownMenuGroup.doc.mjs
index 6fa69a405b018..7b43cc1675ba0 100644
--- a/packages/core/src/DropdownMenu/DropdownMenuGroup.doc.mjs
+++ b/packages/core/src/DropdownMenu/DropdownMenuGroup.doc.mjs
@@ -13,7 +13,7 @@ export const docs = {
defaults: {title: 'Version history'},
},
description:
- 'A group of rows in a compound menu. A visible title names role="group" through aria-labelledby; an omitted title leaves the group unnamed. The heading is not a menuitem, so arrow keys and typeahead skip it. Keep title content non-interactive and place controls in DropdownMenu header or footer. The data-driven equivalent is the `{type: "section", title, items}` entry in `items`; both forms share the heading treatment and theme target.',
+ 'A group of rows in a compound menu. A visible title names role="group" through aria-labelledby; an omitted title leaves the group unnamed. The heading is not a menuitem, so arrow keys and typeahead skip it. Keep title content non-interactive and place controls in DropdownMenu header or footer. The data-driven equivalent is the `{type: "section", title, items}` entry in `items`; both forms share the heading treatment and theme target. Host attributes and DOM handlers (id, data-*, aria-*) reach the group element; its role, and its name while it has a title, stay component-owned.',
usage: {
description:
'Use DropdownMenuGroup to give related compound-menu rows one visible and programmatic name. Use an untitled group only when a separate name would not help people understand the rows.',
@@ -107,7 +107,7 @@ export const docsZh = {
displayName: 'Dropdown Menu Group',
isHiddenFromOverview: true,
description:
- '复合菜单中的一组菜单行。可见标题通过 aria-labelledby 为 role="group" 命名;省略标题时该组没有名称。标题不是 menuitem,因此方向键和预输入会跳过它。标题内容应保持非交互;控件应放在 DropdownMenu 的 header 或 footer 中。',
+ '复合菜单中的一组菜单行。可见标题通过 aria-labelledby 为 role="group" 命名;省略标题时该组没有名称。标题不是 menuitem,因此方向键和预输入会跳过它。标题内容应保持非交互;控件应放在 DropdownMenu 的 header 或 footer 中。宿主属性和 DOM 事件处理函数(id、data-*、aria-*)会传到分组元素上;其 role 以及有标题时的名称由组件控制。',
usage: {
description:
'使用 DropdownMenuGroup 为相关的复合菜单行提供同一个可见名称和无障碍名称。只有当名称能帮助理解这些菜单行时才使用分组。',
diff --git a/packages/core/src/DropdownMenu/DropdownMenuGroup.tsx b/packages/core/src/DropdownMenu/DropdownMenuGroup.tsx
index 46cf9d04e882b..f5c59392de4f7 100644
--- a/packages/core/src/DropdownMenu/DropdownMenuGroup.tsx
+++ b/packages/core/src/DropdownMenu/DropdownMenuGroup.tsx
@@ -4,7 +4,8 @@
/**
* @file DropdownMenuGroup.tsx
- * @input Uses spacing/typography/color tokens, themeProps (heading target)
+ * @input Uses spacing/typography/color tokens, themeProps (heading target);
+ * forwards host props to the group element
* @output Exports DropdownMenuGroup component and DropdownMenuGroupProps
* @position Sub-component; used inside DropdownMenu
*
@@ -47,9 +48,9 @@ const styles = stylex.create({
},
});
-export interface DropdownMenuGroupProps extends Pick<
- BaseProps,
- 'xstyle' | 'className' | 'style'
+export interface DropdownMenuGroupProps extends Omit<
+ BaseProps,
+ 'role'
> {
/**
* Heading shown above the group's rows and used as the group's accessible
@@ -70,7 +71,9 @@ export interface DropdownMenuGroupProps extends Pick<
* `menuitem`, so arrow-key navigation and typeahead skip it. Keep heading
* content non-interactive; place controls in DropdownMenu's `header` or
* `footer`. The compound peer of
- * `{type: 'section', title, items}` in the `items` data API.
+ * `{type: 'section', title, items}` in the `items` data API. Host attributes
+ * (`id`, `data-*`, `aria-*`) and DOM handlers reach the group element; its
+ * role, and its name while it has a title, stay component-owned.
*
* @example
* ```
@@ -91,15 +94,18 @@ export function DropdownMenuGroup({
className,
style,
ref,
+ 'aria-labelledby': ariaLabelledBy,
+ ...rest
}: DropdownMenuGroupProps) {
const headingId = useId();
const hasTitle = title != null && title !== '' && title !== false;
return (
{hasTitle && (
, so we mock them
beforeAll(() => {
@@ -114,3 +115,65 @@ describe('MobileNavToggle ARIA wiring', () => {
expect(target?.tagName).toBe('DIALOG');
});
});
+
+describe('MobileNavToggle host attributes', () => {
+ // architecture:public-component-api INV5 and INV7: host attributes and
+ // handlers reach the button; FR11's toggle and ARIA wiring stay owned.
+ function ShellWithToggle(props: MobileNavToggleProps) {
+ return (
+
+
+
+
+
+ }
+ mobileNav={{breakpoint: 'md'}}>
+
+
+ );
+ }
+
+ it('forwards data, ARIA and id attributes to the button', () => {
+ render(
+ ,
+ );
+ const toggle = screen.getByTestId('page-menu');
+ expect(toggle.tagName).toBe('BUTTON');
+ expect(toggle).toHaveAttribute('data-analytics-id', 'open-nav');
+ expect(toggle).toHaveAttribute('id', 'page-menu-toggle');
+ expect(toggle).toHaveAttribute('aria-describedby', 'nav-hint');
+ });
+
+ it('keeps its own aria-expanded and aria-controls over a caller value', () => {
+ render(
+ ,
+ );
+ const toggle = screen.getByTestId('page-menu');
+ expect(toggle).toHaveAttribute('aria-expanded', 'false');
+ const controls = toggle.getAttribute('aria-controls');
+ expect(controls).not.toBe('elsewhere');
+ expect(document.getElementById(controls!)?.tagName).toBe('DIALOG');
+ });
+
+ it('runs a caller onClick after the toggle, which a preventDefault does not cancel', () => {
+ const onClick = vi.fn((event: {preventDefault: () => void}) => {
+ event.preventDefault();
+ });
+ render();
+ const toggle = screen.getByTestId('page-menu');
+ fireEvent.click(toggle);
+ expect(onClick).toHaveBeenCalledTimes(1);
+ expect(toggle).toHaveAttribute('aria-expanded', 'true');
+ });
+});
diff --git a/packages/core/src/MobileNav/MobileNavToggle.tsx b/packages/core/src/MobileNav/MobileNavToggle.tsx
index 2a567ca1fcddf..ff40d7cd6b55c 100644
--- a/packages/core/src/MobileNav/MobileNavToggle.tsx
+++ b/packages/core/src/MobileNav/MobileNavToggle.tsx
@@ -4,13 +4,17 @@
/**
* @file MobileNavToggle.tsx
- * @input Uses React, Button, Icon, AppShell mobile context
+ * @input Uses React, Button, Icon, AppShell mobile context; forwards host props
+ * to the Button
* @output Exports MobileNavToggle component
* @position Standalone toggle button; can be placed anywhere in the AppShell tree.
*
* Hamburger button that opens/closes the mobile nav drawer.
* Reads from AppShell mobile context — renders nothing above the mobile breakpoint.
* Can be placed anywhere in the component tree (TopNav, content area, custom toolbar, etc.).
+ * Host attributes and DOM handlers reach the button; its `aria-expanded` and
+ * `aria-controls` stay component-owned, and a caller `onClick` runs after the
+ * toggle.
*/
import React, {type ReactNode} from 'react';
@@ -19,10 +23,11 @@ import {Icon} from '../Icon';
import {useAppShellMobile} from '../AppShell/AppShellMobileContext';
import type {BaseProps} from '../BaseProps';
import {useTranslator} from '../i18n';
+import {composeEventHandlers} from '../utils';
-export interface MobileNavToggleProps extends Pick<
- BaseProps,
- 'xstyle' | 'className' | 'style'
+export interface MobileNavToggleProps extends Omit<
+ BaseProps,
+ 'aria-expanded' | 'aria-controls'
> {
ref?: React.Ref;
/**
@@ -66,6 +71,8 @@ export function MobileNavToggle({
xstyle,
className,
style,
+ onClick,
+ ...rest
}: MobileNavToggleProps) {
const t = useTranslator();
const label = labelFromProps ?? t('@astryx.mobileNav.toggle.open');
@@ -84,11 +91,12 @@ export function MobileNavToggle({
return (
}
- onClick={toggleMobileNav}
+ onClick={composeEventHandlers(toggleMobileNav, onClick)}
aria-expanded={isMobileNavOpen}
aria-controls={mobileNavId || undefined}
data-testid={testId ?? 'mobile-nav-toggle'}
diff --git a/packages/core/src/Overlay/Overlay.doc.mjs b/packages/core/src/Overlay/Overlay.doc.mjs
index f33e30929488e..1e37528a0a47e 100644
--- a/packages/core/src/Overlay/Overlay.doc.mjs
+++ b/packages/core/src/Overlay/Overlay.doc.mjs
@@ -12,7 +12,7 @@ export const docs = {
usage: {
description:
- 'Overlay layers action or supporting content over media, cards, video, or other bounded surfaces with an optional scrim and reveal behavior.',
+ 'Overlay layers action or supporting content over media, cards, video, or other bounded surfaces with an optional scrim and reveal behavior. Host attributes and DOM handlers (id, data-*, aria-*) reach the root element.',
bestPractices: [
{
guidance: true,
@@ -193,7 +193,7 @@ export const docsDense = {
description: 'layered content over media/card surfaces with scrim + hover/focus/controlled reveal',
usage: {
description:
- 'Overlay layers compact actions or supporting content over media, cards, or bounded surfaces with optional dark/light scrim and hover/focus/controlled reveal.',
+ 'Overlay layers compact actions or supporting content over media, cards, or bounded surfaces with optional dark/light scrim and hover/focus/controlled reveal. Host attributes and DOM handlers reach the root element.',
bestPractices: [
{guidance: true, description: 'Use for short contextual actions/labels tied to the underlying surface.'},
{guidance: true, description: 'Keep content compact and legible over the scrim.'},
diff --git a/packages/core/src/Overlay/Overlay.test.tsx b/packages/core/src/Overlay/Overlay.test.tsx
index ff5c51ecd17b4..a976bf9c732f7 100644
--- a/packages/core/src/Overlay/Overlay.test.tsx
+++ b/packages/core/src/Overlay/Overlay.test.tsx
@@ -10,8 +10,8 @@
* update tests to match new behavior
*/
-import {describe, it, expect, beforeEach, afterEach} from 'vitest';
-import {render, screen, renderHook} from '@testing-library/react';
+import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
+import {render, screen, renderHook, fireEvent} from '@testing-library/react';
import {createRef} from 'react';
import {Overlay} from './Overlay';
import {useOverlay} from './useOverlay';
@@ -31,7 +31,7 @@ function getScrim(container: HTMLElement): HTMLElement {
*/
function mockHoverNone(matches: boolean): () => void {
const original = window.matchMedia;
- window.matchMedia = ((query: string) => ({
+ window.matchMedia = (query: string) => ({
matches: query.includes('hover: none') ? matches : false,
media: query,
onchange: null,
@@ -40,7 +40,7 @@ function mockHoverNone(matches: boolean): () => void {
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => false,
- }));
+ });
return () => {
window.matchMedia = original;
};
@@ -245,6 +245,74 @@ describe('Overlay', () => {
expect(root.style.opacity).toBe('0.5');
});
});
+
+ describe('host attributes', () => {
+ // architecture:public-component-api INV5: host attributes reach the root
+ // element that owns the ref, the theme target and the styling props.
+ it('forwards data, ARIA and id attributes to the root div', () => {
+ const ref = createRef();
+ render(
+ c}
+ id="hero-overlay"
+ data-testid="hero"
+ data-analytics-id="hero-card"
+ aria-describedby="hero-caption">
+