mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
fix(core): update trigger aria-expanded on close (#1644)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user