@@ -24,8 +24,8 @@ import * as React from 'react';
2424import classnames from 'classnames' ;
2525
2626import TabIndicator from '@material/react-tab-indicator' ;
27- // @ts -ignore No mdc .d.ts files
28- import { MDCTabFoundation } from '@material/tab/dist/mdc.tab ' ;
27+ import { MDCTabFoundation } from '@material/tab/foundation' ;
28+ import { MDCTabAdapter } from '@material/tab/adapter ' ;
2929
3030import TabRipple , { TabRippleProps } from './TabRipple' ;
3131
@@ -38,10 +38,11 @@ export interface TabProps extends React.HTMLProps<HTMLButtonElement> {
3838 isMinWidthIndicator ?: boolean ;
3939 stacked ?: boolean ;
4040 previousIndicatorClientRect ?: ClientRect ;
41+ onInteraction ?: ( ) => void ;
4142}
4243
4344interface MDCTabElementAttributes {
44- 'aria-selected' : boolean ;
45+ 'aria-selected' ?: 'false' | 'true' ;
4546 tabIndex ?: number ;
4647}
4748
@@ -52,7 +53,7 @@ interface TabState extends MDCTabElementAttributes {
5253}
5354
5455export default class Tab extends React . Component < TabProps , TabState > {
55- foundation ? : MDCTabFoundation ;
56+ foundation ! : MDCTabFoundation ;
5657 tabRef : React . RefObject < HTMLButtonElement > = React . createRef ( ) ;
5758 tabContentRef : React . RefObject < HTMLSpanElement > = React . createRef ( ) ;
5859 tabIndicatorRef : React . RefObject < TabIndicator > = React . createRef ( ) ;
@@ -67,11 +68,12 @@ export default class Tab extends React.Component<TabProps, TabState> {
6768 minWidth : false ,
6869 isMinWidthIndicator : false ,
6970 stacked : false ,
71+ onInteraction : ( ) => null ,
7072 } ;
7173
7274 state : TabState = {
7375 'classList' : new Set ( ) ,
74- 'aria-selected' : false ,
76+ 'aria-selected' : ' false' ,
7577 'activateIndicator' : false ,
7678 'previousIndicatorClientRect' : this . props . previousIndicatorClientRect ,
7779 'tabIndex' : - 1 ,
@@ -81,7 +83,7 @@ export default class Tab extends React.Component<TabProps, TabState> {
8183 const { active, focusOnActivate} = this . props ;
8284 this . foundation = new MDCTabFoundation ( this . adapter ) ;
8385 this . foundation . init ( ) ;
84- this . foundation . setFocusOnActivate ( focusOnActivate ) ;
86+ this . foundation . setFocusOnActivate ( focusOnActivate ! ) ;
8587 if ( active ) {
8688 this . foundation . activate ( ) ;
8789 }
@@ -94,7 +96,7 @@ export default class Tab extends React.Component<TabProps, TabState> {
9496 componentDidUpdate ( prevProps : TabProps ) {
9597 const { active, focusOnActivate, previousIndicatorClientRect} = this . props ;
9698 if ( focusOnActivate !== prevProps . focusOnActivate ) {
97- this . foundation . setFocusOnActivate ( focusOnActivate ) ;
99+ this . foundation . setFocusOnActivate ( focusOnActivate ! ) ;
98100 }
99101 if ( active !== prevProps . active ) {
100102 if ( active ) {
@@ -115,7 +117,7 @@ export default class Tab extends React.Component<TabProps, TabState> {
115117 } ) ;
116118 }
117119
118- get adapter ( ) {
120+ get adapter ( ) : MDCTabAdapter {
119121 return {
120122 addClass : ( className : string ) => {
121123 const classList = new Set ( this . state . classList ) ;
@@ -136,12 +138,15 @@ export default class Tab extends React.Component<TabProps, TabState> {
136138 getOffsetWidth : ( ) =>
137139 Number ( this . tabRef . current && this . tabRef . current . offsetWidth ) ,
138140 getContentOffsetLeft : ( ) =>
139- this . tabContentRef . current &&
140- this . tabContentRef . current . offsetLeft ,
141+ this . tabContentRef . current ?
142+ this . tabContentRef . current . offsetLeft :
143+ 0 ,
141144 getContentOffsetWidth : ( ) =>
142- this . tabContentRef . current &&
143- this . tabContentRef . current . offsetWidth ,
145+ this . tabContentRef . current ?
146+ this . tabContentRef . current . offsetWidth :
147+ 0 ,
144148 focus : ( ) => this . tabRef . current && this . tabRef . current . focus ( ) ,
149+ notifyInteracted : this . props . onInteraction ! ,
145150 activateIndicator : ( previousIndicatorClientRect : ClientRect ) =>
146151 this . setState ( {
147152 activateIndicator : true ,
@@ -151,7 +156,7 @@ export default class Tab extends React.Component<TabProps, TabState> {
151156 } ;
152157 }
153158
154- activate ( computeIndicatorClientRect ?: ClientRect | { } ) {
159+ activate ( computeIndicatorClientRect ?: ClientRect ) {
155160 this . foundation . activate ( computeIndicatorClientRect ) ;
156161 }
157162
@@ -190,6 +195,7 @@ export default class Tab extends React.Component<TabProps, TabState> {
190195 isFadingIndicator,
191196 indicatorContent,
192197 minWidth,
198+ onInteraction,
193199 stacked,
194200 /* eslint-enable */
195201 children,
0 commit comments