Skip to content

Commit b60e295

Browse files
authored
feat(a11y): remove incorrect expanded attribute on OptionsMenu (#1792)
1 parent dfa0905 commit b60e295

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

packages/react/src/components/OptionsMenu/OptionsMenu.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,10 @@ test('should toggle menu on trigger clicks', async () => {
117117

118118
await user.click(button);
119119
expect(button).toHaveAttribute('aria-expanded', 'true');
120-
expect(screen.getByRole('menu')).toHaveAttribute('aria-expanded', 'true');
121-
120+
expect(screen.getByRole('menu')).toHaveClass('OptionsMenu--expanded');
122121
await user.click(button);
123-
124122
expect(button).toHaveAttribute('aria-expanded', 'false');
125-
expect(screen.getByRole('menu')).toHaveAttribute('aria-expanded', 'false');
123+
expect(screen.getByRole('menu')).not.toHaveClass('OptionsMenu--expanded');
126124
});
127125

128126
test('should click trigger with down key on trigger', () => {
@@ -188,10 +186,12 @@ test('should close menu when click outside event occurs', async () => {
188186
</>
189187
);
190188

191-
await user.click(screen.getByRole('button', { name: 'trigger' }));
192-
expect(screen.getByRole('menu')).toHaveAttribute('aria-expanded', 'true');
189+
const triggerButton = screen.getByRole('button', { name: 'trigger' });
190+
await user.click(triggerButton);
191+
expect(triggerButton).toHaveAttribute('aria-expanded', 'true');
193192
await user.click(screen.getByRole('button', { name: 'Click me!' }));
194-
expect(screen.getByRole('menu')).toHaveAttribute('aria-expanded', 'false');
193+
expect(triggerButton).toHaveAttribute('aria-expanded', 'false');
194+
expect(screen.getByRole('menu')).not.toHaveClass('OptionsMenu--expanded');
195195
});
196196

197197
test('should return no axe violations when hidden', async () => {

packages/react/src/components/OptionsMenu/OptionsMenuList.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ const OptionsMenuList = ({
142142
>
143143
<ul
144144
{...other}
145-
className={classnames('OptionsMenu__list', className)}
146-
/* aria-expanded is not correct usage here, but the pattern library
147-
currently styles the open state of the menu based on this attribute */
148-
aria-expanded={show}
145+
className={classnames('OptionsMenu__list', className, {
146+
'OptionsMenu--expanded': show
147+
})}
149148
role="menu"
150149
onClick={handleClick}
151150
ref={(el) => {

packages/styles/options-menu.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.15);
5959
}
6060

61-
.OptionsMenu__list[aria-expanded='true'] {
61+
.OptionsMenu__list:is(.OptionsMenu--expanded) {
6262
display: block;
6363
}
6464

0 commit comments

Comments
 (0)