Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
},
deregisterInteractionHandler: (type: string, handler: EventListener) => {
/* TODO */
},
activateInputRipple: () => {
/* TODO */
},
deactivateInputRipple: () => {
/* TODO */
}
};
private _foundation: {
init: Function,
destroy: Function
} = new MDCFormFieldFoundation(this._mdcAdapter);
constructor(private _renderer: Renderer2, private _root: ElementRef) { }
ngAfterViewInit() {
this._foundation.init();
}
ngOnDestroy() {
this._foundation.destroy();
}
}
getDefaultFoundation() {
// For RMWC, the entire foundation is a noop. Interactions and ripples are controlled
// on the components themselves
return new MDCFormFieldFoundation({
registerInteractionHandler: (
evtType: K,
handler: SpecificEventListener
): void => {},
deregisterInteractionHandler: (
evtType: K,
handler: SpecificEventListener
): void => {},
activateInputRipple: () => {},
deactivateInputRipple: () => {}
});
}
// Radio buttons technically go "active" whenever there is *any* keyboard interaction. This is not the
// UI we desire.
isSurfaceActive: () => false,
registerInteractionHandler: (evt, handler) => {
this.$refs.controlEl.addEventListener(evt, handler, applyPassive());
},
deregisterInteractionHandler: (evt, handler) => {
this.$refs.controlEl.removeEventListener(evt, handler, applyPassive());
},
computeBoundingRect: () => {
return this.$refs.root.getBoundingClientRect();
},
});
this.formField = new MDCFormFieldFoundation({
registerInteractionHandler: (type, handler) => {
this.$refs.labelEl &&
this.$refs.labelEl.addEventListener(type, handler);
},
deregisterInteractionHandler: (type, handler) => {
this.$refs.labelEl &&
this.$refs.labelEl.removeEventListener(type, handler);
},
activateInputRipple: () => {
this.ripple && this.ripple.activate();
},
deactivateInputRipple: () => {
this.ripple && this.ripple.deactivate();
},
});
// Radio buttons technically go "active" whenever there is *any* keyboard interaction. This is not the
// UI we desire.
isSurfaceActive: () => false,
registerInteractionHandler: (evt, handler) => {
this.$refs.controlEl.addEventListener(evt, handler, applyPassive());
},
deregisterInteractionHandler: (evt, handler) => {
this.$refs.controlEl.removeEventListener(evt, handler, applyPassive());
},
computeBoundingRect: () => {
return this.$refs.root.getBoundingClientRect();
},
});
this.formField = new MDCFormFieldFoundation({
registerInteractionHandler: (type, handler) => {
this.$refs.labelEl &&
this.$refs.labelEl.addEventListener(type, handler);
},
deregisterInteractionHandler: (type, handler) => {
this.$refs.labelEl &&
this.$refs.labelEl.removeEventListener(type, handler);
},
activateInputRipple: () => {
this.ripple && this.ripple.activate();
},
deactivateInputRipple: () => {
this.ripple && this.ripple.deactivate();
},
});
getDefaultFoundation() {
this.label_ = this.root_.querySelector(
MDCFormFieldFoundation.strings.LABEL_SELECTOR
)
// prettier-ignore
return new MDCFormFieldFoundation({
registerInteractionHandler: (type, handler) => this.label_.addEventListener(type, handler),
deregisterInteractionHandler: (type, handler) => this.label_.removeEventListener(type, handler),
activateInputRipple: () => {
if (this.input_ && this.input_.ripple) {
this.input_.ripple.activate()
}
},
deactivateInputRipple: () => {
if (this.input_ && this.input_.ripple) {
this.input_.ripple.deactivate()
}
},
})
}
mounted () {
this.mdcFormField = MDCFormField.attachTo(this.$el)
// TODO: Better solution to avoid direct children access?!
if (this.$children.length === 1) {
if (this.$children[0]._data.mdcRadio) {
this.mdcFormField.input = this.$children[0]._data.mdcRadio
} else if (this.$children[0]._data.mdcCheckbox) {
this.mdcFormField.input = this.$children[0]._data.mdcCheckbox
}
}
},
beforeDestroy () {
getDefaultFoundation() {
this.label_ = this.root_.querySelector(
MDCFormFieldFoundation.strings.LABEL_SELECTOR
)
// prettier-ignore
return new MDCFormFieldFoundation({
registerInteractionHandler: (type, handler) => this.label_.addEventListener(type, handler),
deregisterInteractionHandler: (type, handler) => this.label_.removeEventListener(type, handler),
activateInputRipple: () => {
if (this.input_ && this.input_.ripple) {
this.input_.ripple.activate()
}
},
deactivateInputRipple: () => {
if (this.input_ && this.input_.ripple) {
this.input_.ripple.deactivate()
}
},
})
registerInteractionHandler: (type: string, handler: EventListener) => {
this.registry.listen(this.renderer, type, handler, this.root);
},
deregisterInteractionHandler: (type: string, handler: EventListener) => {
this.registry.unlisten(type, handler);
},
activateInputRipple: () => {
if (this.rippleChild)
this.rippleChild.activateRipple();
},
deactivateInputRipple: () => {
if (this.rippleChild)
this.rippleChild.deactivateRipple();
}
};
private foundation: { init: Function, destroy: Function } = new MDCFormFieldFoundation(this.mdcAdapter);
constructor(private renderer: Renderer2, private root: ElementRef, private registry: MdcEventRegistry) {
}
ngAfterContentInit() {
if (this.mdcInput != null && this.mdcLabel != null) {
if (this.mdcInput.id == null && this.mdcLabel.for == null)
this.mdcInput.id = this.mdcLabel.for = `mdc-form-input-${nextId++}`;
else if (this.mdcInput.id == null)
this.mdcInput.id = this.mdcLabel.for;
else if (this.mdcLabel.for == null)
this.mdcLabel.for = this.mdcInput.id;
}
this.foundation.init();
}
this.ripple = new RippleBase(this, {
isUnbounded: () => true,
isSurfaceActive: () => RippleBase.isSurfaceActive(this.$refs.control),
registerInteractionHandler: (evt, handler) => {
this.$refs.control.addEventListener(evt, handler, applyPassive());
},
deregisterInteractionHandler: (evt, handler) => {
this.$refs.control.removeEventListener(evt, handler, applyPassive());
},
computeBoundingRect: () => {
return this.$refs.root.getBoundingClientRect();
},
});
this.formField = new MDCFormFieldFoundation({
registerInteractionHandler: (type, handler) => {
this.$refs.label.addEventListener(type, handler);
},
deregisterInteractionHandler: (type, handler) => {
this.$refs.label.removeEventListener(type, handler);
},
activateInputRipple: () => {
this.ripple && this.ripple.activate();
},
deactivateInputRipple: () => {
this.ripple && this.ripple.deactivate();
},
});
this.foundation.init();
this.ripple.init();
this.ripple = new RippleBase(this, {
isUnbounded: () => true,
isSurfaceActive: () => RippleBase.isSurfaceActive(this.$refs.control),
registerInteractionHandler: (evt, handler) => {
this.$refs.control.addEventListener(evt, handler, applyPassive());
},
deregisterInteractionHandler: (evt, handler) => {
this.$refs.control.removeEventListener(evt, handler, applyPassive());
},
computeBoundingRect: () => {
return this.$refs.root.getBoundingClientRect();
},
});
this.formField = new MDCFormFieldFoundation({
registerInteractionHandler: (type, handler) => {
this.$refs.label.addEventListener(type, handler);
},
deregisterInteractionHandler: (type, handler) => {
this.$refs.label.removeEventListener(type, handler);
},
activateInputRipple: () => {
this.ripple && this.ripple.activate();
},
deactivateInputRipple: () => {
this.ripple && this.ripple.deactivate();
},
});
this.foundation.init();
this.ripple.init();