license import { MDCFoundation } from '@material/base/foundation' ; import { MDCTextFieldHelperTextAdapter } from './adapter' ; import { cssClasses , strings } from './constants' ; export class MDCTextFieldHelperTextFoundation extends MDCFoundation < MDCTextFieldHelperTextAdapter > { static override get cssClasses ( ) { return cssClasses ; } static override get strings ( ) { return strings ; } /**
     * See  MDCTextFieldHelperTextAdapter for typing information on parameters and return types.
      static override get defaultAdapter ( ) : MDCTextFieldHelperTextAdapter { return { addClass : ( ) => undefined , removeClass : ( ) => undefined , hasClass : ( ) => false , getAttr : ( ) => null , setAttr : ( ) => undefined , removeAttr : ( ) => undefined , setContent : ( ) => undefined , } ; } constructor ( adapter ? ) { super ( { ... MDCTextFieldHelperTextFoundation . defaultAdapter , ... adapter } ) ; } getId ( ) { return this . adapter . getAttr ( 'id' ) ; } isVisible ( ) { return this . adapter . getAttr ( strings . ARIA_HIDDEN ) !== 'true' ; } /**
     * Sets the content of the helper text field.
     */ setContent ( content ) { this . adapter . setContent ( content ) ; } isPersistent ( ) { return this . adapter . hasClass ( cssClasses . HELPER_TEXT_PERSISTENT ) ; } param isPersistent setPersistent ( isPersistent ) { if ( isPersistent ) { this . adapter . addClass ( cssClasses . HELPER_TEXT_PERSISTENT ) ; } else { this . adapter . removeClass ( cssClasses . HELPER_TEXT_PERSISTENT ) ; } } return isValidation ( ) { return this . adapter . hasClass ( cssClasses . HELPER_TEXT_VALIDATION_MSG ) ; } param isValidation setValidation ( isValidation ) { if ( isValidation ) { this . adapter . addClass ( cssClasses . HELPER_TEXT_VALIDATION_MSG ) ; } else { this . adapter . removeClass ( cssClasses . HELPER_TEXT_VALIDATION_MSG ) ; } } /**
     * Makes the helper text visible to the screen reader.
     */ showToScreenReader ( ) { this . adapter . removeAttr ( strings . ARIA_HIDDEN ) ; } /**
     * Sets the validity of the helper text based on the input validity.
     */ setValidity ( inputIsValid ) { const helperTextIsPersistent = this . adapter . hasClass ( cssClasses . HELPER_TEXT_PERSISTENT ) ; const helperTextIsValidationMsg = this . adapter . hasClass ( cssClasses . HELPER_TEXT_VALIDATION_MSG ) ; const validationMsgNeedsDisplay = helperTextIsValidationMsg && ! inputIsValid ; if ( validationMsgNeedsDisplay ) { this . showToScreenReader ( ) ; if ( this . adapter . getAttr ( strings . ROLE ) === 'alert' ) { this . refreshAlertRole ( ) ; } else { this . adapter . setAttr ( strings . ROLE , 'alert' ) ; } } else { this . adapter . removeAttr ( strings . ROLE ) ; } if ( ! helperTextIsPersistent && ! validationMsgNeedsDisplay ) { this . hide ( ) ; } } /**
     * Hides the help text from screen readers.
     */ private hide ( ) { this . adapter . setAttr ( strings . ARIA_HIDDEN , 'true' ) ; } private refreshAlertRole ( ) { this . adapter . removeAttr ( strings . ROLE ) ; requestAnimationFrame ( ( ) => { this . adapter . setAttr ( strings . ROLE , 'alert' ) ; } ) ; } } export default MDCTextFieldHelperTextFoundation ;