license import { MDCComponent } from '@material/base/component' ; import { applyPassive } from '@material/dom/events' ; import { MDCRippleAdapter } from '@material/ripple/adapter' ; import { MDCRipple } from '@material/ripple/component' ; import { MDCRippleFoundation } from '@material/ripple/foundation' ; import { MDCRippleCapableSurface } from '@material/ripple/types' ; import { MDCRadioAdapter } from './adapter' ; import { MDCRadioFoundation } from './foundation' ; export class MDCRadio extends MDCComponent < MDCRadioFoundation > implements MDCRippleCapableSurface { static override attachTo ( root ) { return new MDCRadio ( root ) ; } get checked ( ) : boolean { return this . nativeControl . checked ; } set checked ( checked ) { this . nativeControl . checked = checked ; } get disabled ( ) { return this . nativeControl . disabled ; } set disabled ( disabled ) { this . foundation . setDisabled ( disabled ) ; } get value ( ) { return this . nativeControl . value ; } set value ( value ) { this . nativeControl . value = value ; } get ripple ( ) : MDCRipple { return this . rippleSurface ; } private readonly rippleSurface : MDCRipple = this . createRipple ( ) ; override destroy ( ) { this . rippleSurface . destroy ( ) ; super . destroy ( ) ; } override getDefaultFoundation ( ) { const adapter = { addClass : ( className ) => this . root . classList . add ( className ) , removeClass : ( className ) => this . root . classList . remove ( className ) , setNativeControlDisabled : ( disabled ) => this . nativeControl . disabled = disabled , } ; return new MDCRadioFoundation ( adapter ) ; } private createRipple ( ) { const adapter = { ... MDCRipple . createAdapter ( this ) , registerInteractionHandler : ( evtType , handler ) => { this . nativeControl . addEventListener ( evtType , handler , applyPassive ( ) ) ; } , deregisterInteractionHandler : ( evtType , handler ) => { this . nativeControl . removeEventListener ( evtType , handler , applyPassive ( ) ) ; } , isSurfaceActive : ( ) => false , isUnbounded : ( ) => true , } ; return new MDCRipple ( this . root , new MDCRippleFoundation ( adapter ) ) ; } private get nativeControl ( ) : HTMLInputElement { const { NATIVE_CONTROL_SELECTOR } = MDCRadioFoundation . strings ; const el = this . root . querySelector < HTMLInputElement > ( NATIVE_CONTROL_SELECTOR ) ; if ( ! el ) { throw new Error ( `Radio component requires a ${ NATIVE_CONTROL_SELECTOR } element` ) ; } return el ; } }