Skip to content

Commit

Permalink
Merge pull request react-bootstrap#441 from limscoder/master
Browse files Browse the repository at this point in the history
Added role="button" to NavItem for aria compliance.
  • Loading branch information
mtscout6 committed Mar 5, 2015
2 parents 96cc2fb + 7cc4747 commit f7808bd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/NavItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var NavItem = React.createClass({
},

render: function () {
var {
var {
disabled,
active,
href,
Expand All @@ -34,16 +34,22 @@ var NavItem = React.createClass({
classes = {
'active': active,
'disabled': disabled
},
linkProps = {
href,
title,
target,
onClick: this.handleClick,
ref: 'anchor'
};

if (href === '#') {
linkProps.role = 'button';
}

return (
<li {...props} className={joinClasses(props.className, classSet(classes))}>
<a
href={href}
title={title}
target={target}
onClick={this.handleClick}
ref="anchor">
<a {...linkProps}>
{ children }
</a>
</li>
Expand All @@ -61,4 +67,4 @@ var NavItem = React.createClass({
}
});

module.exports = NavItem;
module.exports = NavItem;
18 changes: 18 additions & 0 deletions test/NavItemSpec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,22 @@ describe('NavItem', function () {
);
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'span'));
});

it('Should set role="button" when href=="#"', function () {
var instance = ReactTestUtils.renderIntoDocument(
<NavItem href="#" target="_blank">Item content</NavItem>
);

var linkElement = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a').getDOMNode();
assert(linkElement.outerHTML.match('role="button"'), true);
});

it('Should not set role when href!="#"', function () {
var instance = ReactTestUtils.renderIntoDocument(
<NavItem href="/path/to/stuff" target="_blank">Item content</NavItem>
);

var linkElement = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a').getDOMNode();
assert.equal(linkElement.outerHTML.match('role="button"'), null);
});
});

0 comments on commit f7808bd

Please sign in to comment.