This repository was archived by the owner on Jul 29, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +29
-9
lines changed Expand file tree Collapse file tree 4 files changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -63,11 +63,14 @@ export default class TabBar extends Component {
63
63
getPreviousActiveTabIndex : ( ) => this . state . previousActiveIndex ,
64
64
getFocusedTabIndex : ( ) => {
65
65
const activeElement = document . activeElement ;
66
- this . tabList_ . forEach ( ( tabList , index ) => {
67
- if ( tabList . tabElement_ . current === activeElement ) {
68
- return index ;
66
+ // cannot use findIndex, not supported in IE11
67
+ // cannot use forEach, return statement inside the forEach loop will not return
68
+ for ( let i = 0 ; i < this . tabList_ . length ; i ++ ) {
69
+ if ( this . tabList_ [ i ] . tabElement_ . current === activeElement ) {
70
+ return i ;
69
71
}
70
- } ) ;
72
+ }
73
+ return - 1 ;
71
74
} ,
72
75
getIndexOfTab : ( tabToFind ) => this . tabList_ . indexOf ( tabToFind ) ,
73
76
getTabListLength : ( ) => this . tabList_ . length ,
Original file line number Diff line number Diff line change @@ -27,10 +27,6 @@ import withRipple from '@material/react-ripple';
27
27
28
28
export class TabRipple extends React . Component {
29
29
30
- init = ( el ) => {
31
- this . props . initRipple ( el ) ;
32
- }
33
-
34
30
get classes ( ) {
35
31
return classnames ( 'mdc-tab__ripple' , this . props . className ) ;
36
32
}
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ export default class Tab extends Component {
34
34
tabElement_ = React . createRef ( ) ;
35
35
tabContentElement_ = React . createRef ( ) ;
36
36
tabIndicator_ = React . createRef ( ) ;
37
+ tabRipple_ = React . createRef ( ) ;
37
38
38
39
state = {
39
40
'classList' : new Set ( ) ,
@@ -153,6 +154,8 @@ export default class Tab extends Component {
153
154
role = 'tab'
154
155
aria-selected = { ariaSelected }
155
156
tabIndex = { tabIndex }
157
+ onFocus = { ( e ) => this . tabRipple_ . current . handleFocus ( e ) }
158
+ onBlur = { ( e ) => this . tabRipple_ . current . handleBlur ( e ) }
156
159
ref = { this . tabElement_ }
157
160
{ ...otherProps }
158
161
>
@@ -164,7 +167,7 @@ export default class Tab extends Component {
164
167
{ isMinWidthIndicator ? this . renderIndicator ( ) : null }
165
168
</ span >
166
169
{ isMinWidthIndicator ? null : this . renderIndicator ( ) }
167
- < TabRipple />
170
+ < TabRipple ref = { this . tabRipple_ } />
168
171
</ button >
169
172
) ;
170
173
}
Original file line number Diff line number Diff line change @@ -305,3 +305,21 @@ test('#componentWillUnmount destroys foundation', () => {
305
305
wrapper . unmount ( ) ;
306
306
td . verify ( foundation . destroy ( ) , { times : 1 } ) ;
307
307
} ) ;
308
+
309
+ test ( 'on focus event calls handleFocus on TabRipple' , ( ) => {
310
+ const wrapper = mount ( < Tab /> ) ;
311
+ const ripple = wrapper . instance ( ) . tabRipple_ . current ;
312
+ ripple . handleFocus = td . func ( ) ;
313
+
314
+ wrapper . simulate ( 'focus' ) ;
315
+ td . verify ( ripple . handleFocus ( td . matchers . isA ( Object ) ) , { times : 1 } ) ;
316
+ } ) ;
317
+
318
+ test ( 'on blur event calls handleBlur on TabRipple' , ( ) => {
319
+ const wrapper = mount ( < Tab /> ) ;
320
+ const ripple = wrapper . instance ( ) . tabRipple_ . current ;
321
+ ripple . handleBlur = td . func ( ) ;
322
+
323
+ wrapper . simulate ( 'blur' ) ;
324
+ td . verify ( ripple . handleBlur ( td . matchers . isA ( Object ) ) , { times : 1 } ) ;
325
+ } ) ;
You can’t perform that action at this time.
0 commit comments