@@ -2,13 +2,14 @@ import * as React from 'react';
22import classnames from 'classnames' ;
33import TabScroller from '@material/react-tab-scroller' ;
44import Tab , { TabProps } from '@material/react-tab' ; // eslint-disable-line no-unused-vars
5- // @ts -ignore No mdc .d.ts files
6- import { MDCTabBarFoundation } from '@material/tab-bar/dist/mdc.tabBar ' ;
5+ import { MDCTabBarFoundation } from '@material/tab-bar/foundation' ;
6+ import { MDCTabBarAdapter } from '@material/tab-bar/adapter ' ;
77
88export interface TabBarProps extends React . HTMLAttributes < HTMLDivElement > {
99 indexInView ?: number ;
1010 activeIndex : number ;
1111 handleActiveIndexUpdate ?: ( index : number ) => void ;
12+ onActivated ?: ( index : number ) => void ;
1213 className ?: string ;
1314 isRtl ?: boolean ;
1415 children : React . ReactElement < TabProps > | React . ReactElement < TabProps > [ ] ;
@@ -24,7 +25,7 @@ class TabBar extends React.Component<
2425 tabBarRef : React . RefObject < HTMLDivElement > = React . createRef ( ) ;
2526 tabScrollerRef : React . RefObject < TabScroller > = React . createRef ( ) ;
2627 tabList : Tab [ ] = [ ] ;
27- foundation ? : MDCTabBarFoundation ;
28+ foundation ! : MDCTabBarFoundation ;
2829
2930 constructor ( props : TabBarProps ) {
3031 super ( props ) ;
@@ -60,7 +61,7 @@ class TabBar extends React.Component<
6061 } ;
6162 this . tabList [ activeIndex ] . activate ( defaultDOMRect /* previousIndicatorClientRect */ ) ;
6263 }
63- this . foundation . scrollIntoView ( indexInView ) ;
64+ this . foundation . scrollIntoView ( indexInView ! ) ;
6465 }
6566
6667 componentDidUpdate ( prevProps : TabBarProps ) {
@@ -70,7 +71,7 @@ class TabBar extends React.Component<
7071 ) ;
7172 }
7273 if ( this . props . indexInView !== prevProps . indexInView ) {
73- this . foundation . scrollIntoView ( this . props . indexInView ) ;
74+ this . foundation . scrollIntoView ( this . props . indexInView ! ) ;
7475 }
7576 }
7677
@@ -82,7 +83,7 @@ class TabBar extends React.Component<
8283 return classnames ( 'mdc-tab-bar' , this . props . className ) ;
8384 }
8485
85- get adapter ( ) {
86+ get adapter ( ) : MDCTabBarAdapter {
8687 return {
8788 scrollTo : ( scrollX : number ) => {
8889 this . tabScrollerRef . current && this . tabScrollerRef . current . scrollTo ( scrollX ) ;
@@ -91,15 +92,15 @@ class TabBar extends React.Component<
9192 this . tabScrollerRef . current && this . tabScrollerRef . current . incrementScroll ( scrollXIncrement ) ;
9293 } ,
9394 getScrollPosition : ( ) => {
94- if ( ! this . tabScrollerRef . current ) return ;
95+ if ( ! this . tabScrollerRef . current ) return 0 ;
9596 return this . tabScrollerRef . current . getScrollPosition ( ) ;
9697 } ,
9798 getScrollContentWidth : ( ) => {
98- if ( ! this . tabScrollerRef . current ) return ;
99+ if ( ! this . tabScrollerRef . current ) return 0 ;
99100 return this . tabScrollerRef . current . getScrollContentWidth ( ) ;
100101 } ,
101102 getOffsetWidth : ( ) => {
102- if ( this . tabBarRef . current === null ) return ;
103+ if ( this . tabBarRef . current === null ) return 0 ;
103104 return this . tabBarRef . current . offsetWidth ;
104105 } ,
105106 isRTL : ( ) => ! ! this . props . isRtl ,
@@ -127,8 +128,9 @@ class TabBar extends React.Component<
127128 }
128129 return - 1 ;
129130 } ,
130- getIndexOfTab : ( tabToFind : Tab ) => this . tabList . indexOf ( tabToFind ) ,
131+ getIndexOfTabById : ( id : string ) => this . tabList . map ( ( tab ) => tab . props . id ) . indexOf ( id ) ,
131132 getTabListLength : ( ) => this . tabList . length ,
133+ notifyTabActivated : ( index : number ) => this . props . onActivated && this . props . onActivated ( index ) ,
132134 } ;
133135 }
134136
@@ -140,7 +142,7 @@ class TabBar extends React.Component<
140142 // Persist the synthetic event to access its `key`.
141143 e . persist ( ) ;
142144 this . setState ( { previousActiveIndex : this . props . activeIndex } , ( ) =>
143- this . foundation . handleKeyDown ( e )
145+ this . foundation . handleKeyDown ( e . nativeEvent )
144146 ) ;
145147 if ( this . props . onKeyDown ) {
146148 this . props . onKeyDown ( e ) ;
0 commit comments