fix(core): update trigger aria-expanded on close (#1644)

This commit is contained in:
Sam Potts
2026-06-02 17:07:20 +10:00
committed by GitHub
parent e9a619e03a
commit 2f5e23e100
6 changed files with 70 additions and 46 deletions
+1 -1
View File
@@ -83,7 +83,7 @@ export class MenuCore {
getTriggerAttrs(state: MenuState, contentId?: string) {
return {
'aria-haspopup': 'menu' as const,
'aria-expanded': state.open ? 'true' : 'false',
'aria-expanded': state.open && state.status !== 'ending' ? 'true' : 'false',
'aria-controls': contentId,
};
}
@@ -114,6 +114,16 @@ describe('MenuCore', () => {
expect(attrs['aria-expanded']).toBe('true');
});
it('returns aria-expanded false when closing', () => {
const core = new MenuCore();
core.setInput(createInput({ active: true, status: 'ending' }));
const state = core.getState();
const attrs = core.getTriggerAttrs(state);
expect(state.open).toBe(true);
expect(attrs['aria-expanded']).toBe('false');
});
it('sets aria-controls when contentId is provided', () => {
const core = new MenuCore();
core.setInput(createInput());
@@ -94,7 +94,7 @@ export class PopoverCore {
getTriggerAttrs(state: PopoverState, popupId?: string) {
return {
'aria-expanded': state.open ? 'true' : 'false',
'aria-expanded': state.open && state.status !== 'ending' ? 'true' : 'false',
'aria-haspopup': 'dialog',
'aria-controls': popupId,
};
@@ -69,6 +69,16 @@ describe('PopoverCore', () => {
expect(attrs['aria-expanded']).toBe('true');
});
it('returns aria-expanded false when closing', () => {
const core = new PopoverCore();
core.setInput({ active: true, status: 'ending' });
const state = core.getState();
const attrs = core.getTriggerAttrs(state);
expect(state.open).toBe(true);
expect(attrs['aria-expanded']).toBe('false');
});
it('includes aria-controls when popupId is provided', () => {
const core = new PopoverCore();
core.setInput(OPEN);