Skip to content

Commit

Permalink
[changed] Only add the navigation role to navbar when not using a <…
Browse files Browse the repository at this point in the history
…nav>

fixes react-bootstrap#1489
  • Loading branch information
jquense committed Nov 14, 2015
1 parent af93b24 commit 345f4b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const Navbar = React.createClass({
return {
bsClass: 'navbar',
bsStyle: 'default',
role: 'navigation',
componentClass: 'nav',
fixedTop: false,
fixedBottom: false,
Expand Down Expand Up @@ -109,6 +108,13 @@ const Navbar = React.createClass({
(brand || toggleButton || toggleNavKey != null) &&
!this.hasNavBrandChild();

// will result in some false positives but that seems better
// than false negatives. strict `undefined` check allows explicit
// "nulling" of the role if the user really doesn't want one
if (props.role === undefined && ComponentClass !== 'nav') {
props.role = 'navigation';
}

return (
<ComponentClass {...props} className={classNames(className, classes)}>
<Grid fluid={fluid}>
Expand Down
11 changes: 10 additions & 1 deletion test/NavbarSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ describe('Navbar', () => {
let nav = ReactDOM.findDOMNode(instance);
assert.equal(nav.nodeName, 'NAV');
assert.ok(nav.className.match(/\bnavbar\b/));
assert.ok(nav.getAttribute('role'), 'navigation');
assert.ok(!nav.getAttribute('role'));
});

it('Should add "navigation" role when not using a `<nav>`', () => {
let instance = ReactTestUtils.renderIntoDocument(
<Navbar componentClass='div' />
);
let nav = ReactDOM.findDOMNode(instance);
assert.equal(nav.nodeName, 'DIV');
assert.ok(nav.getAttribute('role') === 'navigation');
});

it('Should add fixedTop variation class', () => {
Expand Down

0 comments on commit 345f4b4

Please sign in to comment.