Skip to content

Commit 75b8cea

Browse files
authored
Fix dbc.Tab.active_label_style (dbc-team#946)
1 parent 42e4deb commit 75b8cea

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/components/tabs/Tabs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ const Tabs = props => {
7979
{active}
8080
)}
8181
style={{
82-
...(active && childProps.active_label_style),
8382
...(!childProps.disabled && {cursor: 'pointer'}),
84-
...childProps.label_style
83+
...childProps.label_style,
84+
...(active && childProps.active_label_style)
8585
}}
8686
disabled={childProps.disabled}
8787
onClick={() => {

src/components/tabs/__tests__/Tabs.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,48 @@ describe('Tabs', () => {
8080
expect(nav.children[0].firstChild).not.toHaveClass('active');
8181
expect(nav.children[1].firstChild).toHaveClass('active');
8282
});
83+
84+
test('checks if inline styles from "tab_style", "active_tab_style", "label_style" and "active_label_style" are consistent', () => {
85+
const tabStyle = {backgroundColor: '#fff', borderRadius: '20px'};
86+
const activeTabStyle = {backgroundColor: '#000'};
87+
const labelStyle = {color: '#000', textDecoration: 'underline'};
88+
const activeLabelStyle = {color: '#fff'};
89+
90+
const {container} = render(
91+
<Tabs active_tab="tab-2">
92+
<Tab
93+
tab_id="tab-1"
94+
label="tab-label-1"
95+
tab_style={tabStyle}
96+
active_tab_style={activeTabStyle}
97+
label_style={labelStyle}
98+
active_label_style={activeLabelStyle}
99+
>
100+
tab-content-1
101+
</Tab>
102+
<Tab
103+
tab_id="tab-2"
104+
label="tab-label-2"
105+
tab_style={tabStyle}
106+
active_tab_style={activeTabStyle}
107+
label_style={labelStyle}
108+
active_label_style={activeLabelStyle}
109+
>
110+
tab-content-2
111+
</Tab>
112+
</Tabs>
113+
);
114+
const nav = container.querySelector('ul.nav.nav-tabs');
115+
116+
expect(nav.children[0]).toHaveStyle(tabStyle);
117+
expect(nav.children[0].firstChild).toHaveStyle(labelStyle);
118+
expect(nav.children[1]).toHaveStyle({
119+
backgroundColor: '#000',
120+
borderRadius: '20px'
121+
});
122+
expect(nav.children[1].firstChild).toHaveStyle({
123+
color: '#fff',
124+
textDecoration: 'underline'
125+
});
126+
});
83127
});

0 commit comments

Comments
 (0)