Skip to content

Commit 9e4c041

Browse files
committed
[fixed] Incorrect 'aria-selected' on NavItem
1 parent 44182b7 commit 9e4c041

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/NavItem.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ const NavItem = React.createClass({
5555

5656
if (!role && href === '#') {
5757
linkProps.role = 'button';
58+
} else if (role === 'tab') {
59+
linkProps['aria-selected'] = active;
5860
}
5961

6062
return (
6163
<li {...props} role="presentation" className={classNames(props.className, classes)}>
62-
<SafeAnchor {...linkProps} aria-selected={active} aria-controls={ariaControls}>
64+
<SafeAnchor {...linkProps} aria-controls={ariaControls}>
6365
{ children }
6466
</SafeAnchor>
6567
</li>

test/NavItemSpec.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,24 @@ describe('NavItem', () => {
135135
assert.ok(linkElement.hasAttribute('aria-controls'));
136136
});
137137

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

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

145-
assert.equal(linkElement.getAttribute('aria-selected'), 'true');
145+
expect(linkElement.getAttribute('aria-selected')).to.equal('true');
146+
});
147+
148+
it('Should not add aria-selected to the link when role is not "tab"', () => {
149+
let instance = ReactTestUtils.renderIntoDocument(
150+
<NavItem role="button" active>Item content</NavItem>
151+
);
152+
153+
let linkElement = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a');
154+
155+
expect(linkElement.getAttribute('aria-selected')).to.not.exist;
146156
});
147157

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

0 commit comments

Comments
 (0)