Skip to content

Commit de7c5e6

Browse files
committed
Optimize TabPanel style merging
1 parent 5f9aab7 commit de7c5e6

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/components/TabPanel.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ module.exports = React.createClass({
55
displayName: 'TabPanel',
66

77
propTypes: {
8-
className: PropTypes.string,
9-
selected: PropTypes.bool,
10-
id: PropTypes.string,
11-
tabId: PropTypes.string,
128
children: PropTypes.oneOfType([
139
PropTypes.array,
1410
PropTypes.object,
1511
PropTypes.string,
1612
]),
13+
className: PropTypes.string,
14+
id: PropTypes.string,
15+
selected: PropTypes.bool,
16+
style: PropTypes.object,
17+
tabId: PropTypes.string,
1718
},
1819

1920
contextTypes: {
@@ -29,11 +30,7 @@ module.exports = React.createClass({
2930
},
3031

3132
render() {
32-
const { className, children, selected, id, tabId, ...attributes } = this.props;
33-
34-
// Merge style
35-
let style = { ...attributes.style, display: selected ? null : 'none' };
36-
delete attributes.style;
33+
const { className, children, selected, id, tabId, style, ...attributes } = this.props;
3734

3835
return (
3936
<div
@@ -48,7 +45,7 @@ module.exports = React.createClass({
4845
role="tabpanel"
4946
id={id}
5047
aria-labelledby={tabId}
51-
style={style}
48+
style={{ ...style, display: selected ? null : 'none' }}
5249
>
5350
{(this.context.forceRenderTabPanel || selected) ? children : null}
5451
</div>

src/components/__tests__/TabPanel-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ describe('Tab', () => {
4949
expect(wrapper.prop('role')).toBe('tabpanel');
5050
});
5151

52+
it('should have default style attribute', () => {
53+
const wrapper = shallow(<TabPanel />);
54+
55+
expect(wrapper.prop('style')).toEqual({ display: 'none' });
56+
});
5257

5358
it('should merge style attribute', () => {
5459
const wrapper = shallow(<TabPanel style={{ borderWidth: '1px' }} />);

0 commit comments

Comments
 (0)