File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ const Navbar = React.createClass({
3939 return {
4040 bsClass : 'navbar' ,
4141 bsStyle : 'default' ,
42- role : 'navigation' ,
4342 componentClass : 'nav' ,
4443 fixedTop : false ,
4544 fixedBottom : false ,
@@ -109,6 +108,13 @@ const Navbar = React.createClass({
109108 ( brand || toggleButton || toggleNavKey != null ) &&
110109 ! this . hasNavBrandChild ( ) ;
111110
111+ // will result in some false positives but that seems better
112+ // than false negatives. strict `undefined` check allows explicit
113+ // "nulling" of the role if the user really doesn't want one
114+ if ( props . role === undefined && ComponentClass !== 'nav' ) {
115+ props . role = 'navigation' ;
116+ }
117+
112118 return (
113119 < ComponentClass { ...props } className = { classNames ( className , classes ) } >
114120 < Grid fluid = { fluid } >
Original file line number Diff line number Diff line change @@ -17,7 +17,16 @@ describe('Navbar', () => {
1717 let nav = ReactDOM . findDOMNode ( instance ) ;
1818 assert . equal ( nav . nodeName , 'NAV' ) ;
1919 assert . ok ( nav . className . match ( / \b n a v b a r \b / ) ) ;
20- assert . ok ( nav . getAttribute ( 'role' ) , 'navigation' ) ;
20+ assert . ok ( ! nav . getAttribute ( 'role' ) ) ;
21+ } ) ;
22+
23+ it ( 'Should add "navigation" role when not using a `<nav>`' , ( ) => {
24+ let instance = ReactTestUtils . renderIntoDocument (
25+ < Navbar componentClass = 'div' />
26+ ) ;
27+ let nav = ReactDOM . findDOMNode ( instance ) ;
28+ assert . equal ( nav . nodeName , 'DIV' ) ;
29+ assert . ok ( nav . getAttribute ( 'role' ) === 'navigation' ) ;
2130 } ) ;
2231
2332 it ( 'Should add fixedTop variation class' , ( ) => {
You can’t perform that action at this time.
0 commit comments