How to use the @material/radio.MDCRadioFoundation function in @material/radio

To help you get started, we’ve selected a few @material/radio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github src-zone / material / bundle / src / components / radio / mdc.radio.directive.ts View on Github external
@Directive({
    selector: '[mdcRadio]'
})
export class MdcRadioDirective extends AbstractMdcRipple implements AfterContentInit, OnDestroy {
    @HostBinding('class.mdc-radio') _cls = true;
    @ContentChild(MdcRadioInputDirective) _input: MdcRadioInputDirective;
    private mdcAdapter: MdcRadioAdapter = {
        addClass: (className: string) => {
            this.renderer.addClass(this.root.nativeElement, className);
        },
        removeClass: (className: string) => {
            this.renderer.removeClass(this.root.nativeElement, className);
        },
        getNativeControl: () => this._input ? this._input._elm.nativeElement : null
    };
    private foundation: { init: Function, destroy: Function } = new MDCRadioFoundation(this.mdcAdapter);

    constructor(private renderer: Renderer2, private root: ElementRef, private registry: MdcEventRegistry) {
        super(root, renderer, registry);
    }

    ngAfterContentInit() {
        this.addBackground();
        this.initRipple();
        this.foundation.init();
    }

    ngOnDestroy() {
        this.destroyRipple();
        this.foundation.destroy();
    }
github jamesmfriedman / rmwc / src / radio / index.tsx View on Github external
getDefaultFoundation() {
    return new MDCRadioFoundation({
      addClass: (className: string) => this.root.addClass(className),
      removeClass: (className: string) => this.root.removeClass(className)
    });
  }
github trimox / angular-mdc-web / packages / radio / radio.ts View on Github external
getDefaultFoundation() {
    const adapter: MDCRadioAdapter = {
      addClass: (className: string) => this._getHostElement().classList.add(className),
      removeClass: (className: string) => this._getHostElement().classList.remove(className),
      setNativeControlDisabled: (disabled: boolean) => this.disabled = disabled
    };
    return new MDCRadioFoundation(adapter);
  }
github angular / components / src / material-experimental / mdc-radio / radio.ts View on Github external
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MatRadioButton implements AfterViewInit, OnDestroy {

  private _uniqueId: string = `mat-radio-${++nextUniqueId}`;

  private _radioAdapter: MDCRadioAdapter = {
    addClass: (className: string) => this._setClass(className, true),
    removeClass: (className: string) => this._setClass(className, false),
    setNativeControlDisabled: (disabled: boolean) => {
      this._disabled = disabled;
      this._changeDetectorRef.markForCheck();
    },
  };

  _radioFoundation = new MDCRadioFoundation(this._radioAdapter);
  _classes: {[key: string]: boolean} = {};

  /** The unique ID for the radio button. */
  @Input() id: string = this._uniqueId;

  /** Whether the radio button is disabled. */
  @Input()
  get disabled(): boolean {
    return this._disabled;
  }
  set disabled(disabled: boolean) {
    this._radioFoundation.setDisabled(coerceBooleanProperty(disabled));
  }
  private _disabled = false;

  constructor(private _changeDetectorRef: ChangeDetectorRef) {}