Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support change the aria role of menu or menuitem. #115

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const Menu = createReactClass({
selectable: PropTypes.bool,
multiple: PropTypes.bool,
children: PropTypes.any,
role: PropTypes.string,
},

mixins: [MenuMixin],
Expand Down
6 changes: 3 additions & 3 deletions src/MenuItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ const MenuItem = createReactClass({
[this.getDisabledClassName()]: props.disabled,
});
const attrs = {
...props.attribute,
title: props.title,
className,
role: 'menuitem',
'aria-selected': selected,
'aria-disabled': props.disabled,
...props.attribute,
title: props.title,
className,
};
let mouseEvent = {};
if (!props.disabled) {
Expand Down
6 changes: 4 additions & 2 deletions src/MenuMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const MenuMixin = {
defaultOpenKeys: PropTypes.arrayOf(PropTypes.string),
openKeys: PropTypes.arrayOf(PropTypes.string),
children: PropTypes.any,
role: PropTypes.string,
},

getDefaultProps() {
Expand Down Expand Up @@ -225,11 +226,12 @@ const MenuMixin = {
props.className,
`${props.prefixCls}-${props.mode}`,
);

const domProps = {
className,
role: 'menu',
'aria-activedescendant': '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fatelei Why do you remove this line?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aria-activedescendant="" is an invalid value

role: props.role || 'menu',
};

if (props.id) {
domProps.id = props.id;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Menu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ describe('Menu', () => {
});
});

describe('render role listbox', () => {
function createMenu() {
return (
<Menu
className="myMenu"
openAnimation="fade"
role="listbox"
>
<MenuItem key="1" attribute={{ role: 'option' }}>1</MenuItem>
<MenuItem key="2" attribute={{ role: 'option' }}>2</MenuItem>
<MenuItem key="3" attribute={{ role: 'option' }}>3</MenuItem>
</Menu>
);
}

it(`renders menu correctly`, () => {
const wrapper = render(createMenu());
expect(renderToJson(wrapper)).toMatchSnapshot();
});
});


it('set activeKey', () => {
const wrapper = mount(
Expand Down
33 changes: 30 additions & 3 deletions tests/__snapshots__/Menu.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`Menu render renders horizontal menu correctly 1`] = `
<ul
aria-activedescendant=""
class="rc-menu myMenu rc-menu-root rc-menu-vertical"
role="menu"
tabindex="0"
Expand Down Expand Up @@ -95,7 +94,6 @@ exports[`Menu render renders horizontal menu correctly 1`] = `

exports[`Menu render renders inline menu correctly 1`] = `
<ul
aria-activedescendant=""
class="rc-menu myMenu rc-menu-root rc-menu-vertical"
role="menu"
tabindex="0"
Expand Down Expand Up @@ -188,7 +186,6 @@ exports[`Menu render renders inline menu correctly 1`] = `

exports[`Menu render renders vertical menu correctly 1`] = `
<ul
aria-activedescendant=""
class="rc-menu myMenu rc-menu-root rc-menu-vertical"
role="menu"
tabindex="0"
Expand Down Expand Up @@ -278,3 +275,33 @@ exports[`Menu render renders vertical menu correctly 1`] = `
</li>
</ul>
`;

exports[`Menu render role listbox renders menu correctly 1`] = `
<ul
class="rc-menu myMenu rc-menu-root rc-menu-vertical"
role="listbox"
tabindex="0"
>
<li
aria-selected="false"
class="rc-menu-item"
role="option"
>
1
</li>
<li
aria-selected="false"
class="rc-menu-item"
role="option"
>
2
</li>
<li
aria-selected="false"
class="rc-menu-item"
role="option"
>
3
</li>
</ul>
`;