@@ -18,7 +18,7 @@ const EnhancedTab = ({
18
18
disabled_className,
19
19
mobile_breakpoint,
20
20
amountOfTabs,
21
- colors
21
+ colors,
22
22
} ) => {
23
23
let tabStyle = style ;
24
24
if ( disabled ) {
@@ -111,38 +111,50 @@ export default class Tabs extends Component {
111
111
constructor ( props ) {
112
112
super ( props ) ;
113
113
114
+ this . selectHandler = this . selectHandler . bind ( this ) ;
115
+ this . parseChildrenToArray = this . parseChildrenToArray . bind ( this ) ;
116
+
117
+ this . parseChildrenToArray ( ) ;
118
+
114
119
if ( ! this . props . value ) {
115
120
// if no value specified on Tabs component, set it to the first child's (which should be a Tab component) value
116
- const value = this . props . children [ 0 ] . props . children . props . value ;
121
+ const value =
122
+ this . props . children [ 0 ] . props . children . props . value || 'tab-1' ;
117
123
this . state = {
118
- selected : value || 'tab-1'
124
+ selected : value ,
119
125
} ;
120
- if ( this . props . setProps ) {
126
+ if ( this . props . setProps ) {
121
127
// updating the prop in Dash is necessary so that callbacks work
122
128
this . props . setProps ( {
123
- value : value
129
+ value : value ,
124
130
} ) ;
125
131
}
126
132
} else {
127
133
this . state = {
128
- selected : this . props . value
134
+ selected : this . props . value ,
129
135
} ;
130
136
}
131
- this . selectHandler = this . selectHandler . bind ( this ) ;
137
+ }
138
+ parseChildrenToArray ( ) {
139
+ if ( ! R . is ( Array , this . props . children ) ) {
140
+ // if dcc.Tabs.children contains just one single element, it gets passed as an object
141
+ // instead of an array - so we put in in a array ourselves!
142
+ this . props . children = [ this . props . children ] ;
143
+ }
132
144
}
133
145
selectHandler ( value ) {
134
146
this . setState ( {
135
- selected : value
147
+ selected : value ,
136
148
} ) ;
137
149
if ( this . props . setProps ) {
138
150
this . props . setProps ( { value : value } ) ;
139
151
}
140
152
}
141
153
componentWillReceiveProps ( newProps ) {
142
154
const value = newProps . value ;
143
- if ( ! value ) {
155
+ if ( typeof value !== 'undefined' ) {
144
156
this . setState ( {
145
- selected : value
157
+ selected : value ,
146
158
} ) ;
147
159
}
148
160
}
@@ -151,13 +163,9 @@ export default class Tabs extends Component {
151
163
let selectedTab ;
152
164
let selectedTabContent ;
153
165
154
- if ( this . props . children ) {
155
- if ( ! R . is ( Array , this . props . children ) ) {
156
- // if dcc.Tabs.children contains just one single element, it gets passed as an object
157
- // instead of an array - so we put in in a array ourselves!
158
- this . props . children = [ this . props . children ] ;
159
- }
166
+ this . parseChildrenToArray ( ) ;
160
167
168
+ if ( this . props . children ) {
161
169
const amountOfTabs = this . props . children . length ;
162
170
163
171
EnhancedTabs = this . props . children . map ( ( child , index ) => {
@@ -202,8 +210,6 @@ export default class Tabs extends Component {
202
210
selectedTab = this . props . children . filter ( child => {
203
211
return child . props . children . props . value === this . state . selected ;
204
212
} ) ;
205
- window . console . log ( 'selected' , this . state . selected ) ;
206
- window . console . log ( 'selectedTab[0]' , selectedTab [ 0 ] ) ;
207
213
if ( 'props' in selectedTab [ 0 ] ) {
208
214
selectedTabContent = selectedTab [ 0 ] . props . children ;
209
215
}
@@ -265,13 +271,11 @@ export default class Tabs extends Component {
265
271
border-bottom: none;
266
272
}
267
273
:global(.tab-container--vert .tab:last-of-type) {
268
- border-bottom: 1px solid
269
- ${ this . props . colors . border } !important;
274
+ border-bottom: 1px solid ${ this . props . colors . border } !important;
270
275
}
271
276
:global(.tab-container--vert .tab--selected) {
272
277
border: 1px solid ${ this . props . colors . border } ;
273
- border-left: 2px solid
274
- ${ this . props . colors . primary } ;
278
+ border-left: 2px solid ${ this . props . colors . primary } ;
275
279
border-right: none;
276
280
}
277
281
@@ -291,8 +295,8 @@ Tabs.defaultProps = {
291
295
colors : {
292
296
border : '#d6d6d6' ,
293
297
primary : '#1975FA' ,
294
- background : '#f9f9f9'
295
- }
298
+ background : '#f9f9f9' ,
299
+ } ,
296
300
} ;
297
301
298
302
Tabs . propTypes = {
@@ -364,6 +368,6 @@ Tabs.propTypes = {
364
368
colors : PropTypes . shape ( {
365
369
border : PropTypes . string ,
366
370
primary : PropTypes . string ,
367
- background : PropTypes . string
368
- } )
371
+ background : PropTypes . string ,
372
+ } ) ,
369
373
} ;
0 commit comments