Skip to content

Commit 4551ede

Browse files
committed
Add support for specifying any role on MenuItem.
Ran into a case where there is a readonly list displayed by a dropdown and the `<li />` role should be "reset" to `listitem`.
1 parent 2134c43 commit 4551ede

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/MenuItem.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class MenuItem extends React.Component {
150150
title: props.title,
151151
className,
152152
// set to menuitem by default
153-
role: 'menuitem',
153+
role: props.role || 'menuitem',
154154
'aria-disabled': props.disabled,
155155
};
156156

tests/MenuItem.spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,13 @@ describe('MenuItem', () => {
129129
expect(wrapper.render()).toMatchSnapshot();
130130
});
131131

132-
it('should set specific role', () => {
132+
it('should set role to listitem', () => {
133+
const wrapper = shallow(<NakedMenuItem role="listitem">test</NakedMenuItem>);
134+
135+
expect(wrapper.render()).toMatchSnapshot();
136+
});
137+
138+
it('should set role to option', () => {
133139
const wrapper = shallow(<NakedMenuItem role="option">test</NakedMenuItem>);
134140

135141
expect(wrapper.render()).toMatchSnapshot();

tests/__snapshots__/MenuItem.spec.js.snap

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

3+
exports[`MenuItem overwrite default role should set role to listitem 1`] = `
4+
<li
5+
class="undefined-item"
6+
role="listitem"
7+
>
8+
test
9+
</li>
10+
`;
11+
312
exports[`MenuItem overwrite default role should set role to none if none 1`] = `
413
<li
514
class="undefined-item"
@@ -18,7 +27,7 @@ exports[`MenuItem overwrite default role should set role to none if null 1`] = `
1827
</li>
1928
`;
2029

21-
exports[`MenuItem overwrite default role should set specific role 1`] = `
30+
exports[`MenuItem overwrite default role should set role to option 1`] = `
2231
<li
2332
class="undefined-item"
2433
role="option"

0 commit comments

Comments
 (0)