How to use the @material/mwc-base/form-element.js.addHasRemoveClass function in @material/mwc-base

To help you get started, we’ve selected a few @material/mwc-base 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 material-components / material-components-web-components / packages / slider / src / mwc-slider-base.ts View on Github external
protected createAdapter(): MDCSliderAdapter {
    return {
      ...addHasRemoveClass(this.mdcRoot),
      getAttribute: (name: string) => this.mdcRoot.getAttribute(name),
      setAttribute: (name: string, value: string) =>
          this.mdcRoot.setAttribute(name, value),
      removeAttribute: (name: string) => this.mdcRoot.removeAttribute(name),
      computeBoundingRect: () => this.mdcRoot.getBoundingClientRect(),
      getTabIndex: () => this.mdcRoot.tabIndex,
      registerInteractionHandler:
          (type: K, handler: SpecificEventListener) => {
            const init = type === 'touchstart' ? applyPassive() : undefined;
            this.mdcRoot.addEventListener(type, handler, init);
          },
      deregisterInteractionHandler:
          (type: K, handler: SpecificEventListener) =>
              this.mdcRoot.removeEventListener(type, handler),
      registerThumbContainerInteractionHandler:
          (type: K, handler: SpecificEventListener) => {
github material-components / material-components-web-components / packages / textfield / src / mwc-textfield-base.ts View on Github external
.filter((attributeName) => attributeName) as string[];
            };
        const observer = new MutationObserver((mutationsList) => {
          const attributes = getAttributesList(mutationsList);
          if (attributes.indexOf('maxlength') !== -1 && this.maxLength !== -1) {
            this.charCounterElement.charCounterFoundation.setCounterValue(
                this.value.length, this.maxLength);
          }
        });
        const config = {attributes: true};
        observer.observe(this.formElement, config);
        return observer;
      },
      deregisterValidationAttributeChangeHandler:
          (observer: MutationObserver) => observer.disconnect(),
      ...addHasRemoveClass(this.mdcRoot),
    };
  }
github material-components / material-components-web-components / packages / select / src / mwc-select-base.ts View on Github external
createAdapter(): MDCSelectAdapter {
    this.createListFoundation();
    this.createMenuSurfaceFoundation();
    this.createMenuFoundation();

    return {
      ...addHasRemoveClass(this.mdcRoot),
      activateBottomLine: () => {
        if (this.lineRippleElement) {
          this.lineRippleElement.lineRippleFoundation.activate();
        }
      },
      deactivateBottomLine: () => {
        if (this.lineRippleElement) {
          this.lineRippleElement.lineRippleFoundation.deactivate();
        }
      },
      getSelectedMenuItem: () => {
        const listElement = this.listElement;

        if (!listElement) {
          return null;
        }
github material-components / material-components-web-components / packages / textfield / src / mwc-textfield-base-element.ts View on Github external
protected createAdapter(): MDCTextFieldAdapter {
    return {
      ...addHasRemoveClass(this.mdcRoot),
      ...this.getRootAdapterMethods(),
      ...this.getInputAdapterMethods(),
      ...this.getLabelAdapterMethods(),
      ...this.getLineRippleAdapterMethods(),
      ...this.getOutlineAdapterMethods(),
    };
  }
github material-components / material-components-web-components / packages / select / src / mwc-select-base.ts View on Github external
createMenuSurfaceFoundation() {
    if (!this.menuElement) {
      return;
    }

    if (this.mdcMenuSurfaceFoundation) {
      this.mdcMenuSurfaceFoundation.destroy();
    }

    const mdcMenuSurfaceAdapter: MDCMenuSurfaceAdapter = {
      ...addHasRemoveClass(this.menuElement),
      hasAnchor: () => {
        if (!this.menuElement) {
          return false;
        }

        return !!mwcMenu.anchorElement(this.menuElement);
      },
      notifyClose: () => {
        if (!this.menuElement) {
          return;
        }

        const init: CustomEventInit = {};
        const ev = new CustomEvent('closed', init);
        this.menuElement.dispatchEvent(ev);
      },
github material-components / material-components-web-components / packages / switch / src / mwc-switch-base.ts View on Github external
protected createAdapter(): MDCSwitchAdapter {
    return {
      ...addHasRemoveClass(this.mdcRoot),
      setNativeControlChecked: (checked: boolean) => {
        this.formElement.checked = checked;
      },
      setNativeControlDisabled: (disabled: boolean) => {
        this.formElement.disabled = disabled;
      },
    };
  }
github material-components / material-components-web-components / packages / checkbox / src / mwc-checkbox-base.ts View on Github external
protected createAdapter(): MDCCheckboxAdapter {
    return {
      ...addHasRemoveClass(this.mdcRoot),
      forceLayout: () => {
        this.mdcRoot.offsetWidth;
      },
      isAttachedToDOM: () => this.isConnected,
      isIndeterminate: () => this.indeterminate,
      isChecked: () => this.checked,
      hasNativeControl: () => Boolean(this.formElement),
      setNativeControlDisabled: (disabled: boolean) => {
        this.formElement.disabled = disabled;
      },
      setNativeControlAttr: (attr: string, value: string) => {
        this.formElement.setAttribute(attr, value);
      },
      removeNativeControlAttr: (attr: string) => {
        this.formElement.removeAttribute(attr);
      },