Skip to content

Commit 455dd72

Browse files
committed
Merge pull request #8 from chefsplate/tagName
custom tag names
2 parents 5e07535 + e169b13 commit 455dd72

File tree

6 files changed

+32
-11
lines changed

6 files changed

+32
-11
lines changed

src/components/Col.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class Col extends Component {
3939
}
4040
}
4141

42-
return React.createElement('div', Object.assign({}, this.props, {
42+
return React.createElement(this.props.tagName || 'div', Object.assign({}, this.props, {
4343
className: classes.join(' ')
4444
}), this.props.children);
4545
}
@@ -56,5 +56,6 @@ Col.propTypes = {
5656
lgOffset: PropTypes.number,
5757
reverse: PropTypes.bool,
5858
className: PropTypes.string,
59+
tagName: PropTypes.string,
5960
children: PropTypes.node
6061
};

src/components/Grid.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ export default class Grid extends Component {
66
render() {
77
const containerClass = style[this.props.fluid ? 'container-fluid' : 'container'];
88
const className = classNames(this.props.className, containerClass);
9-
return (
10-
<div {...this.props} className={className}>
11-
{this.props.children}
12-
</div>
13-
);
9+
10+
return React.createElement(this.props.tagName || 'div', Object.assign({}, this.props, {
11+
className
12+
}), this.props.children);
1413
}
1514
}
1615

1716
Grid.propTypes = {
1817
fluid: PropTypes.bool,
1918
className: PropTypes.string,
19+
tagName: PropTypes.string,
2020
children: PropTypes.node
2121
};

src/components/Row.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ export default class Row extends Component {
2323

2424
const className = classNames(this.props.className, modificators);
2525

26-
return (
27-
<div {...this.props} className={className}>
28-
{this.props.children}
29-
</div>
30-
);
26+
return React.createElement(this.props.tagName || 'div', Object.assign({}, this.props, {
27+
className
28+
}), this.props.children);
3129
}
3230
}
3331

@@ -44,5 +42,6 @@ Row.propTypes = {
4442
first: ModificatorType,
4543
last: ModificatorType,
4644
className: PropTypes.string,
45+
tagName: PropTypes.string,
4746
children: PropTypes.node
4847
};

test/components/Col.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,11 @@ describe('Col', () => {
3535
expect(className).toContain(style['col-md']);
3636
expect(className).toContain(style['col-lg']);
3737
});
38+
39+
it('Should support custom tag name', () => {
40+
const col = TestUtils.renderIntoDocument(<Col xs sm md lg tagName="li" />);
41+
const { tagName } = ReactDOM.findDOMNode(col);
42+
43+
expect(tagName).toBe('LI');
44+
});
3845
});

test/components/Grid.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@ describe('Grid', () => {
2323
const grid = TestUtils.renderIntoDocument(<Grid fluid />);
2424
expect(ReactDOM.findDOMNode(grid).className).toEqual(style['container-fluid']);
2525
});
26+
27+
it('Should support custom tag name', () => {
28+
const col = TestUtils.renderIntoDocument(<Grid tagName="section" />);
29+
const { tagName } = ReactDOM.findDOMNode(col);
30+
31+
expect(tagName).toBe('SECTION');
32+
});
2633
});

test/components/Row.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,11 @@ describe('Row', () => {
5252
expect(className).toContain(style['first-xs']);
5353
expect(className).toContain(style['last-sm']);
5454
});
55+
56+
it('Should support custom tag name', () => {
57+
const col = TestUtils.renderIntoDocument(<Row tagName="ul" />);
58+
const { tagName } = ReactDOM.findDOMNode(col);
59+
60+
expect(tagName).toBe('UL');
61+
});
5562
});

0 commit comments

Comments
 (0)