license import { MDCFoundation } from '@material/base/foundation' ; import { MDCSelectHelperTextAdapter } from './adapter' ; import { cssClasses , strings } from './constants' ; export class MDCSelectHelperTextFoundation extends MDCFoundation < MDCSelectHelperTextAdapter > { static override get cssClasses ( ) { return cssClasses ; } static override get strings ( ) { return strings ; } /**
     * See  MDCSelectHelperTextAdapter for typing information on parameters and return types.
      static override get defaultAdapter ( ) : MDCSelectHelperTextAdapter { return { addClass : ( ) => undefined , removeClass : ( ) => undefined , hasClass : ( ) => false , setAttr : ( ) => undefined , getAttr : ( ) => null , removeAttr : ( ) => undefined , setContent : ( ) => undefined , } ; } constructor ( adapter ? ) { super ( { ... MDCSelectHelperTextFoundation . defaultAdapter , ... adapter } ) ; } return getId ( ) { return this . adapter . getAttr ( 'id' ) ; } return isVisible ( ) { return this . adapter . getAttr ( strings . ARIA_HIDDEN ) !== 'true' ; } /**
     * Sets the content of the helper text field.
     */ setContent ( content ) { this . adapter . setContent ( content ) ; } param isValidation setValidation ( isValidation ) { if ( isValidation ) { this . adapter . addClass ( cssClasses . HELPER_TEXT_VALIDATION_MSG ) ; } else { this . adapter . removeClass ( cssClasses . HELPER_TEXT_VALIDATION_MSG ) ; } } /**
     * Sets the persistency of the validation helper text.
     * This keeps the validation message visible even if the select is valid,
     * though it will be displayed in the normal (grey) color.
     */ setValidationMsgPersistent ( isPersistent ) { if ( isPersistent ) { this . adapter . addClass ( cssClasses . HELPER_TEXT_VALIDATION_MSG_PERSISTENT ) ; } else { this . adapter . removeClass ( cssClasses . HELPER_TEXT_VALIDATION_MSG_PERSISTENT ) ; } } /**
     * When acting as a validation message, shows/hides the helper text and
     * triggers alerts as necessary based on the select's validity.
     */ setValidity ( selectIsValid ) { const isValidationMsg = this . adapter . hasClass ( cssClasses . HELPER_TEXT_VALIDATION_MSG ) ; if ( ! isValidationMsg ) { return ; } const isPersistentValidationMsg = this . adapter . hasClass ( cssClasses . HELPER_TEXT_VALIDATION_MSG_PERSISTENT ) ; const msgShouldDisplay = ! selectIsValid || isPersistentValidationMsg ; if ( msgShouldDisplay ) { this . showToScreenReader ( ) ; if ( ! selectIsValid ) { this . adapter . setAttr ( strings . ROLE , 'alert' ) ; } else { this . adapter . removeAttr ( strings . ROLE ) ; } return ; } this . adapter . removeAttr ( strings . ROLE ) ; this . hide ( ) ; } /**
     * Makes the helper text visible to screen readers.
     */ private showToScreenReader ( ) { this . adapter . removeAttr ( strings . ARIA_HIDDEN ) ; } /**
     * Hides the help text from screen readers.
     */ private hide ( ) { this . adapter . setAttr ( strings . ARIA_HIDDEN , 'true' ) ; } } export default MDCSelectHelperTextFoundation ;