Skip to content

Commit 2134c43

Browse files
committed
On MenuItem, set the role to none if the role is null or none.
This will remove the implied `listitem` role of the `<li />`. https://www.w3.org/TR/wai-aria-practices-1.1/examples/menubar/menubar-1/menubar-1.html
1 parent 0c80d9b commit 2134c43

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/MenuItem.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,13 @@ export class MenuItem extends React.Component {
161161
role: 'option',
162162
'aria-selected': props.isSelected,
163163
};
164-
} else if (props.role === null) {
164+
} else if (props.role === null || props.role === 'none') {
165165
// sometimes we want to specify role inside <li/> element
166166
// <li><a role='menuitem'>Link</a></li> would be a good example
167-
delete attrs.role;
167+
// in this case the role on <li/> should be "none" to
168+
// remove the implied listitem role.
169+
// https://www.w3.org/TR/wai-aria-practices-1.1/examples/menubar/menubar-1/menubar-1.html
170+
attrs.role = 'none';
168171
}
169172
// In case that onClick/onMouseLeave/onMouseEnter is passed down from owner
170173
const mouseEvent = {

tests/MenuItem.spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,18 @@ describe('MenuItem', () => {
117117
});
118118

119119
describe('overwrite default role', () => {
120-
it('should set empty role', () => {
120+
it('should set role to none if null', () => {
121121
const wrapper = shallow(<NakedMenuItem role={null}>test</NakedMenuItem>);
122122

123123
expect(wrapper.render()).toMatchSnapshot();
124124
});
125125

126+
it('should set role to none if none', () => {
127+
const wrapper = shallow(<NakedMenuItem role="none">test</NakedMenuItem>);
128+
129+
expect(wrapper.render()).toMatchSnapshot();
130+
});
131+
126132
it('should set specific role', () => {
127133
const wrapper = shallow(<NakedMenuItem role="option">test</NakedMenuItem>);
128134

tests/__snapshots__/MenuItem.spec.js.snap

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`MenuItem overwrite default role should set empty role 1`] = `
3+
exports[`MenuItem overwrite default role should set role to none if none 1`] = `
44
<li
55
class="undefined-item"
6+
role="none"
7+
>
8+
test
9+
</li>
10+
`;
11+
12+
exports[`MenuItem overwrite default role should set role to none if null 1`] = `
13+
<li
14+
class="undefined-item"
15+
role="none"
616
>
717
test
818
</li>

0 commit comments

Comments
 (0)