Skip to content

Commit

Permalink
[fixed] Incorrect 'aria-selected' on NavItem
Browse files Browse the repository at this point in the history
  • Loading branch information
taion committed Oct 16, 2015
1 parent 44182b7 commit 9e4c041
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/NavItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ const NavItem = React.createClass({

if (!role && href === '#') {
linkProps.role = 'button';
} else if (role === 'tab') {
linkProps['aria-selected'] = active;
}

return (
<li {...props} role="presentation" className={classNames(props.className, classes)}>
<SafeAnchor {...linkProps} aria-selected={active} aria-controls={ariaControls}>
<SafeAnchor {...linkProps} aria-controls={ariaControls}>
{ children }
</SafeAnchor>
</li>
Expand Down
16 changes: 13 additions & 3 deletions test/NavItemSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,24 @@ describe('NavItem', () => {
assert.ok(linkElement.hasAttribute('aria-controls'));
});

it('Should add aria-selected to the link', () => {
it('Should add aria-selected to the link when role is "tab"', () => {
let instance = ReactTestUtils.renderIntoDocument(
<NavItem active>Item content</NavItem>
<NavItem role="tab" active>Item content</NavItem>
);

let linkElement = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a');

assert.equal(linkElement.getAttribute('aria-selected'), 'true');
expect(linkElement.getAttribute('aria-selected')).to.equal('true');
});

it('Should not add aria-selected to the link when role is not "tab"', () => {
let instance = ReactTestUtils.renderIntoDocument(
<NavItem role="button" active>Item content</NavItem>
);

let linkElement = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a');

expect(linkElement.getAttribute('aria-selected')).to.not.exist;
});

it('Should pass role down', () => {
Expand Down

0 comments on commit 9e4c041

Please sign in to comment.