Skip to content

Commit ffbcf39

Browse files
committedJul 3, 2015
[fixed] html id and class attributes handling for Nav
className - for the wrapper `nav` element ulClassName - for the inner `ul` element id - for the wrapper `nav` element ulId - for the inner `ul` element
1 parent 8abc998 commit ffbcf39

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed
 

‎src/Nav.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ const Nav = React.createClass({
1818
justified: React.PropTypes.bool,
1919
onSelect: React.PropTypes.func,
2020
collapsible: React.PropTypes.bool,
21+
/**
22+
* CSS classes for the wrapper `nav` element
23+
*/
24+
className: React.PropTypes.string,
25+
/**
26+
* HTML id for the wrapper `nav` element
27+
*/
28+
id: React.PropTypes.string,
29+
/**
30+
* CSS classes for the inner `ul` element
31+
*/
32+
ulClassName: React.PropTypes.string,
33+
/**
34+
* HTML id for the inner `ul` element
35+
*/
36+
ulId: React.PropTypes.string,
2137
expanded: React.PropTypes.bool,
2238
navbar: React.PropTypes.bool,
2339
eventKey: React.PropTypes.any,
@@ -69,7 +85,8 @@ const Nav = React.createClass({
6985
return (
7086
<ul {...this.props}
7187
role={this.props.bsStyle === 'tabs' ? 'tablist' : null}
72-
className={classNames(this.props.className, classes)}
88+
className={classNames(this.props.ulClassName, classes)}
89+
id={this.props.ulId}
7390
ref="ul"
7491
>
7592
{ValidComponentChildren.map(this.props.children, this.renderNavItem)}

‎test/NavSpec.js

+62
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,68 @@ describe('Nav', function () {
115115
assert.ok(items[0].props.navItem);
116116
});
117117

118+
it('Should apply className only to the wrapper nav element', function () {
119+
const instance = ReactTestUtils.renderIntoDocument(
120+
<Nav bsStyle="tabs" activeKey={1} className="nav-specific">
121+
<NavItem key={1}>Tab 1 content</NavItem>
122+
<NavItem key={2}>Tab 2 content</NavItem>
123+
</Nav>
124+
);
125+
126+
let ulNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'ul'));
127+
assert.notInclude(ulNode.className, 'nav-specific');
128+
129+
let navNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'nav'));
130+
assert.include(navNode.className, 'nav-specific');
131+
});
132+
133+
it('Should apply ulClassName to the inner ul element', function () {
134+
const instance = ReactTestUtils.renderIntoDocument(
135+
<Nav bsStyle="tabs" activeKey={1} className="nav-specific" ulClassName="ul-specific">
136+
<NavItem key={1}>Tab 1 content</NavItem>
137+
<NavItem key={2}>Tab 2 content</NavItem>
138+
</Nav>
139+
);
140+
141+
let ulNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'ul'));
142+
assert.include(ulNode.className, 'ul-specific');
143+
assert.notInclude(ulNode.className, 'nav-specific');
144+
145+
let navNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'nav'));
146+
assert.notInclude(navNode.className, 'ul-specific');
147+
assert.include(navNode.className, 'nav-specific');
148+
});
149+
150+
it('Should apply id to the wrapper nav element', function () {
151+
const instance = ReactTestUtils.renderIntoDocument(
152+
<Nav bsStyle="tabs" activeKey={1} id="nav-id">
153+
<NavItem key={1}>Tab 1 content</NavItem>
154+
<NavItem key={2}>Tab 2 content</NavItem>
155+
</Nav>
156+
);
157+
158+
let navNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'nav'));
159+
assert.equal(navNode.id, 'nav-id');
160+
161+
let ulNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'ul'));
162+
assert.notEqual(ulNode.id, 'nav-id');
163+
});
164+
165+
it('Should apply ulId to the inner ul element', function () {
166+
const instance = ReactTestUtils.renderIntoDocument(
167+
<Nav bsStyle="tabs" activeKey={1} id="nav-id" ulId="ul-id">
168+
<NavItem key={1}>Tab 1 content</NavItem>
169+
<NavItem key={2}>Tab 2 content</NavItem>
170+
</Nav>
171+
);
172+
173+
let ulNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'ul'));
174+
assert.equal(ulNode.id, 'ul-id');
175+
176+
let navNode = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'nav'));
177+
assert.equal(navNode.id, 'nav-id');
178+
});
179+
118180

119181
describe('Web Accessibility', function(){
120182

0 commit comments

Comments
 (0)
Please sign in to comment.