license import { MDCFoundation } from '@material/base/foundation' ; import { MDCTabAdapter } from './adapter' ; import { cssClasses , strings } from './constants' ; import { MDCTabDimensions } from './types' ; export class MDCTabFoundation extends MDCFoundation < MDCTabAdapter > { static override get cssClasses ( ) { return cssClasses ; } static override get strings ( ) { return strings ; } static override get defaultAdapter ( ) : MDCTabAdapter { return { addClass : ( ) => undefined , removeClass : ( ) => undefined , hasClass : ( ) => false , setAttr : ( ) => undefined , activateIndicator : ( ) => undefined , deactivateIndicator : ( ) => undefined , notifyInteracted : ( ) => undefined , getOffsetLeft : ( ) => 0 , getOffsetWidth : ( ) => 0 , getContentOffsetLeft : ( ) => 0 , getContentOffsetWidth : ( ) => 0 , focus : ( ) => undefined , } ; } private focusOnActivate = true ; constructor ( adapter ? ) { super ( { ... MDCTabFoundation . defaultAdapter , ... adapter } ) ; } handleClick ( ) { this . adapter . notifyInteracted ( ) ; } isActive ( ) { return this . adapter . hasClass ( cssClasses . ACTIVE ) ; } /**
     * Sets whether the tab should focus itself when activated
     */ setFocusOnActivate ( focusOnActivate ) { this . focusOnActivate = focusOnActivate ; } /**
     * Activates the Tab
     */ activate ( previousIndicatorClientRect ? ) { this . adapter . addClass ( cssClasses . ACTIVE ) ; this . adapter . setAttr ( strings . ARIA_SELECTED , 'true' ) ; this . adapter . setAttr ( strings . TABINDEX , '0' ) ; this . adapter . activateIndicator ( previousIndicatorClientRect ) ; if ( this . focusOnActivate ) { this . adapter . focus ( ) ; } } /**
     * Deactivates the Tab
     */ deactivate ( ) { if ( ! this . isActive ( ) ) { return ; } this . adapter . removeClass ( cssClasses . ACTIVE ) ; this . adapter . setAttr ( strings . ARIA_SELECTED , 'false' ) ; this . adapter . setAttr ( strings . TABINDEX , '-1' ) ; this . adapter . deactivateIndicator ( ) ; } /**
     * Returns the dimensions of the Tab
     */ computeDimensions ( ) { const rootWidth = this . adapter . getOffsetWidth ( ) ; const rootLeft = this . adapter . getOffsetLeft ( ) ; const contentWidth = this . adapter . getContentOffsetWidth ( ) ; const contentLeft = this . adapter . getContentOffsetLeft ( ) ; return { contentLeft : rootLeft + contentLeft , contentRight : rootLeft + contentLeft + contentWidth , rootLeft , rootRight : rootLeft + rootWidth , } ; } } export default MDCTabFoundation ;