Material Web Team 4e3054bab3 feat(controller): add label activation support to FormController
Extends `FormController` to provide label activation via form associated custom elements via a shim where not supported (currently just Safari).

Performing label activation is the responsibility of form associated elements.

Helpers are provided to facilitate this, including `isActivationClick` and `dispatchActivationClick`. Note, any element that should perform an action via a click, could use these helpers to help distinguish external "activation" clicks.

PiperOrigin-RevId: 495689270
2022-12-15 13:56:49 -08:00

23 lines
571 B
TypeScript

/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* FormAssociatedElement interface
*/
export interface FormAssociatedElement extends HTMLElement {}
declare var FormAssociatedElement: {
new (): FormAssociatedElement; prototype: FormAssociatedElement;
readonly formAssociated?: boolean;
};
/**
* Returns true if the element is a form associated custom element (FACE).
*/
export function isFormAssociated(element: FormAssociatedElement) {
return (element.constructor as typeof FormAssociatedElement).formAssociated;
}