@material/web 1.0.2-nightly.6be83b4.0 → 1.0.2-nightly.b5686ea.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/labs/behaviors/constraint-validation.d.ts +2 -2
  2. package/labs/behaviors/constraint-validation.js +1 -1
  3. package/labs/behaviors/constraint-validation.js.map +1 -1
  4. package/labs/behaviors/on-report-validity.d.ts +70 -0
  5. package/labs/behaviors/on-report-validity.js +150 -0
  6. package/labs/behaviors/on-report-validity.js.map +1 -0
  7. package/labs/behaviors/validators/checkbox-validator.d.ts +2 -3
  8. package/labs/behaviors/validators/checkbox-validator.js +0 -3
  9. package/labs/behaviors/validators/checkbox-validator.js.map +1 -1
  10. package/labs/behaviors/validators/radio-validator.d.ts +38 -0
  11. package/labs/behaviors/validators/radio-validator.js +65 -0
  12. package/labs/behaviors/validators/radio-validator.js.map +1 -0
  13. package/labs/behaviors/validators/select-validator.d.ts +31 -0
  14. package/labs/behaviors/validators/select-validator.js +30 -0
  15. package/labs/behaviors/validators/select-validator.js.map +1 -0
  16. package/labs/behaviors/validators/validator.d.ts +1 -1
  17. package/labs/behaviors/validators/validator.js +10 -0
  18. package/labs/behaviors/validators/validator.js.map +1 -1
  19. package/list/internal/listitem/_list-item.scss +1 -0
  20. package/list/internal/listitem/list-item-styles.css.js +1 -1
  21. package/list/internal/listitem/list-item-styles.css.js.map +1 -1
  22. package/package.json +1 -1
  23. package/radio/internal/radio.d.ts +11 -1
  24. package/radio/internal/radio.js +28 -2
  25. package/radio/internal/radio.js.map +1 -1
  26. package/radio/internal/single-selection-controller.d.ts +5 -5
  27. package/radio/internal/single-selection-controller.js +16 -14
  28. package/radio/internal/single-selection-controller.js.map +1 -1
  29. package/select/internal/select.d.ts +8 -72
  30. package/select/internal/select.js +16 -135
  31. package/select/internal/select.js.map +1 -1
@@ -13,7 +13,7 @@ import { Validator } from './validators/validator.js';
13
13
  *
14
14
  * https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation
15
15
  */
16
- export interface ConstraintValidation {
16
+ export interface ConstraintValidation extends FormAssociated {
17
17
  /**
18
18
  * Returns a ValidityState object that represents the validity states of the
19
19
  * element.
@@ -99,7 +99,7 @@ export declare const createValidator: unique symbol;
99
99
  */
100
100
  export declare const getValidityAnchor: unique symbol;
101
101
  /**
102
- * Mixins in constraint validation APIs for an element.
102
+ * Mixes in constraint validation APIs for an element.
103
103
  *
104
104
  * See https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation
105
105
  * for more details.
@@ -20,7 +20,7 @@ const privateValidator = Symbol('privateValidator');
20
20
  const privateSyncValidity = Symbol('privateSyncValidity');
21
21
  const privateCustomValidationMessage = Symbol('privateCustomValidationMessage');
22
22
  /**
23
- * Mixins in constraint validation APIs for an element.
23
+ * Mixes in constraint validation APIs for an element.
24
24
  *
25
25
  * See https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation
26
26
  * for more details.
@@ -1 +1 @@
1
- {"version":3,"file":"constraint-validation.js","sourceRoot":"","sources":["constraint-validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,QAAQ,EAAkC,MAAM,KAAK,CAAC;AAE9D,OAAO,EAAC,SAAS,EAAuB,MAAM,wBAAwB,CAAC;AA6FvE;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAEzD;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAE7D,uDAAuD;AACvD,MAAM,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AACpD,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAC1D,MAAM,8BAA8B,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH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CAAC,EAAE;gBAC3B,IAAI,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;aAClD;YAED,MAAM,EAAC,QAAQ,EAAE,iBAAiB,EAAE,0BAA0B,EAAC,GAC7D,IAAI,CAAC,gBAAgB,CAAC,CAAC,WAAW,EAAE,CAAC;YAEvC,MAAM,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;YAC3D,MAAM,iBAAiB,GACrB,IAAI,CAAC,8BAA8B,CAAC,IAAI,0BAA0B,CAAC;YAErE,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,CACzB,EAAC,GAAG,QAAQ,EAAE,WAAW,EAAC,EAC1B,iBAAiB,EACjB,IAAI,CAAC,iBAAiB,CAAC,EAAE,IAAI,SAAS,CACvC,CAAC;QACJ,CAAC;QAED,CAAC,eAAe,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,CAAC,iBAAiB,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;KACF;IAED,OAAO,2BAA2B,CAAC;AACrC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {isServer, LitElement, PropertyDeclaration} from 'lit';\n\nimport {internals, WithElementInternals} from './element-internals.js';\nimport {FormAssociated} from './form-associated.js';\nimport {MixinBase, MixinReturn} from './mixin.js';\nimport {Validator} from './validators/validator.js';\n\n/**\n * A form associated element that provides constraint validation APIs.\n *\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation\n */\nexport interface ConstraintValidation {\n /**\n * Returns a ValidityState object that represents the validity states of the\n * element.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ValidityState\n */\n readonly validity: ValidityState;\n\n /**\n * Returns a validation error message or an empty string if the element is\n * valid.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/validationMessage\n */\n readonly validationMessage: string;\n\n /**\n * Returns whether an element will successfully validate based on forms\n * validation rules and constraints.\n *\n * Disabled and readonly elements will not validate.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/willValidate\n */\n readonly willValidate: boolean;\n\n /**\n * Checks the element's constraint validation and returns true if the element\n * is valid or false if not.\n *\n * If invalid, this method will dispatch an `invalid` event.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/checkValidity\n *\n * @return true if the element is valid, or false if not.\n */\n checkValidity(): boolean;\n\n /**\n * Checks the element's constraint validation and returns true if the element\n * is valid or false if not.\n *\n * If invalid, this method will dispatch a cancelable `invalid` event. If not\n * canceled, a the current `validationMessage` will be reported to the user.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/reportValidity\n *\n * @return true if the element is valid, or false if not.\n */\n reportValidity(): boolean;\n\n /**\n * Sets the element's constraint validation error message. When set to a\n * non-empty string, `validity.customError` will be true and\n * `validationMessage` will display the provided error.\n *\n * Use this method to customize error messages reported.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity\n *\n * @param error The error message to display, or an empty string.\n */\n setCustomValidity(error: string): void;\n\n /**\n * Creates and returns a `Validator` that is used to compute and cache\n * validity for the element.\n *\n * A validator that caches validity is important since constraint validation\n * must be computed synchronously and frequently in response to constraint\n * validation property changes.\n */\n [createValidator](): Validator<unknown>;\n\n /**\n * Returns shadow DOM child that is used as the anchor for the platform\n * `reportValidity()` popup. This is often the root element or the inner\n * focus-delegated element.\n */\n [getValidityAnchor](): HTMLElement | null;\n}\n\n/**\n * A symbol property used to create a constraint validation `Validator`.\n * Required for all `mixinConstraintValidation()` elements.\n */\nexport const createValidator = Symbol('createValidator');\n\n/**\n * A symbol property used to return an anchor for constraint validation popups.\n * Required for all `mixinConstraintValidation()` elements.\n */\nexport const getValidityAnchor = Symbol('getValidityAnchor');\n\n// Private symbol members, used to avoid name clashing.\nconst privateValidator = Symbol('privateValidator');\nconst privateSyncValidity = Symbol('privateSyncValidity');\nconst privateCustomValidationMessage = Symbol('privateCustomValidationMessage');\n\n/**\n * Mixins in constraint validation APIs for an element.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation\n * for more details.\n *\n * Implementations must provide a validator to cache and compute its validity,\n * along with a shadow root element to anchor validation popups to.\n *\n * @example\n * ```ts\n * const baseClass = mixinConstraintValidation(\n * mixinFormAssociated(mixinElementInternals(LitElement))\n * );\n *\n * class MyCheckbox extends baseClass {\n * \\@property({type: Boolean}) checked = false;\n * \\@property({type: Boolean}) required = false;\n *\n * [createValidator]() {\n * return new CheckboxValidator(() => this);\n * }\n *\n * [getValidityAnchor]() {\n * return this.renderRoot.querySelector('.root');\n * }\n * }\n * ```\n *\n * @param base The class to mix functionality into.\n * @return The provided class with `ConstraintValidation` mixed in.\n */\nexport function mixinConstraintValidation<\n T extends MixinBase<LitElement & FormAssociated & WithElementInternals>,\n>(base: T): MixinReturn<T, ConstraintValidation> {\n abstract class ConstraintValidationElement\n extends base\n implements ConstraintValidation\n {\n get validity() {\n this[privateSyncValidity]();\n return this[internals].validity;\n }\n\n get validationMessage() {\n this[privateSyncValidity]();\n return this[internals].validationMessage;\n }\n\n get willValidate() {\n this[privateSyncValidity]();\n return this[internals].willValidate;\n }\n\n /**\n * A validator instance created from `[createValidator]()`.\n */\n [privateValidator]?: Validator<unknown>;\n\n /**\n * Needed for Safari, see https://bugs.webkit.org/show_bug.cgi?id=261432\n * Replace with this[internals].validity.customError when resolved.\n */\n [privateCustomValidationMessage] = '';\n\n checkValidity() {\n this[privateSyncValidity]();\n return this[internals].checkValidity();\n }\n\n reportValidity() {\n this[privateSyncValidity]();\n return this[internals].reportValidity();\n }\n\n setCustomValidity(error: string) {\n this[privateCustomValidationMessage] = error;\n this[privateSyncValidity]();\n }\n\n override requestUpdate(\n name?: PropertyKey,\n oldValue?: unknown,\n options?: PropertyDeclaration,\n ) {\n super.requestUpdate(name, oldValue, options);\n this[privateSyncValidity]();\n }\n\n [privateSyncValidity]() {\n if (isServer) {\n return;\n }\n\n if (!this[privateValidator]) {\n this[privateValidator] = this[createValidator]();\n }\n\n const {validity, validationMessage: nonCustomValidationMessage} =\n this[privateValidator].getValidity();\n\n const customError = !!this[privateCustomValidationMessage];\n const validationMessage =\n this[privateCustomValidationMessage] || nonCustomValidationMessage;\n\n this[internals].setValidity(\n {...validity, customError},\n validationMessage,\n this[getValidityAnchor]() ?? undefined,\n );\n }\n\n [createValidator](): Validator<unknown> {\n throw new Error('Implement [createValidator]');\n }\n\n [getValidityAnchor](): HTMLElement | null {\n throw new Error('Implement [getValidityAnchor]');\n }\n }\n\n return ConstraintValidationElement;\n}\n"]}
1
+ {"version":3,"file":"constraint-validation.js","sourceRoot":"","sources":["constraint-validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,QAAQ,EAAkC,MAAM,KAAK,CAAC;AAE9D,OAAO,EAAC,SAAS,EAAuB,MAAM,wBAAwB,CAAC;AA6FvE;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAEzD;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAE7D,uDAAuD;AACvD,MAAM,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AACpD,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAC1D,MAAM,8BAA8B,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,yBAAyB,CAEvC,IAAO;;IACP,MAAe,2BACb,SAAQ,IAAI;QADd;;YAwBE;;;eAGG;YACH,QAAgC,GAAG,EAAE,CAAC;QAwDxC,CAAC;QAhFC,IAAI,QAAQ;YACV,IAA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IAAI,CAAC,gBAAgB,CAAC,CAAC,WAAW,EAAE,CAAC;YAEvC,MAAM,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;YAC3D,MAAM,iBAAiB,GACrB,IAAI,CAAC,8BAA8B,CAAC,IAAI,0BAA0B,CAAC;YAErE,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,CACzB,EAAC,GAAG,QAAQ,EAAE,WAAW,EAAC,EAC1B,iBAAiB,EACjB,IAAI,CAAC,iBAAiB,CAAC,EAAE,IAAI,SAAS,CACvC,CAAC;QACJ,CAAC;QAED,CAAC,eAAe,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,CAAC,iBAAiB,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;KACF;IAED,OAAO,2BAA2B,CAAC;AACrC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {isServer, LitElement, PropertyDeclaration} from 'lit';\n\nimport {internals, WithElementInternals} from './element-internals.js';\nimport {FormAssociated} from './form-associated.js';\nimport {MixinBase, MixinReturn} from './mixin.js';\nimport {Validator} from './validators/validator.js';\n\n/**\n * A form associated element that provides constraint validation APIs.\n *\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation\n */\nexport interface ConstraintValidation extends FormAssociated {\n /**\n * Returns a ValidityState object that represents the validity states of the\n * element.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ValidityState\n */\n readonly validity: ValidityState;\n\n /**\n * Returns a validation error message or an empty string if the element is\n * valid.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/validationMessage\n */\n readonly validationMessage: string;\n\n /**\n * Returns whether an element will successfully validate based on forms\n * validation rules and constraints.\n *\n * Disabled and readonly elements will not validate.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/willValidate\n */\n readonly willValidate: boolean;\n\n /**\n * Checks the element's constraint validation and returns true if the element\n * is valid or false if not.\n *\n * If invalid, this method will dispatch an `invalid` event.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/checkValidity\n *\n * @return true if the element is valid, or false if not.\n */\n checkValidity(): boolean;\n\n /**\n * Checks the element's constraint validation and returns true if the element\n * is valid or false if not.\n *\n * If invalid, this method will dispatch a cancelable `invalid` event. If not\n * canceled, a the current `validationMessage` will be reported to the user.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/reportValidity\n *\n * @return true if the element is valid, or false if not.\n */\n reportValidity(): boolean;\n\n /**\n * Sets the element's constraint validation error message. When set to a\n * non-empty string, `validity.customError` will be true and\n * `validationMessage` will display the provided error.\n *\n * Use this method to customize error messages reported.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity\n *\n * @param error The error message to display, or an empty string.\n */\n setCustomValidity(error: string): void;\n\n /**\n * Creates and returns a `Validator` that is used to compute and cache\n * validity for the element.\n *\n * A validator that caches validity is important since constraint validation\n * must be computed synchronously and frequently in response to constraint\n * validation property changes.\n */\n [createValidator](): Validator<unknown>;\n\n /**\n * Returns shadow DOM child that is used as the anchor for the platform\n * `reportValidity()` popup. This is often the root element or the inner\n * focus-delegated element.\n */\n [getValidityAnchor](): HTMLElement | null;\n}\n\n/**\n * A symbol property used to create a constraint validation `Validator`.\n * Required for all `mixinConstraintValidation()` elements.\n */\nexport const createValidator = Symbol('createValidator');\n\n/**\n * A symbol property used to return an anchor for constraint validation popups.\n * Required for all `mixinConstraintValidation()` elements.\n */\nexport const getValidityAnchor = Symbol('getValidityAnchor');\n\n// Private symbol members, used to avoid name clashing.\nconst privateValidator = Symbol('privateValidator');\nconst privateSyncValidity = Symbol('privateSyncValidity');\nconst privateCustomValidationMessage = Symbol('privateCustomValidationMessage');\n\n/**\n * Mixes in constraint validation APIs for an element.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation\n * for more details.\n *\n * Implementations must provide a validator to cache and compute its validity,\n * along with a shadow root element to anchor validation popups to.\n *\n * @example\n * ```ts\n * const baseClass = mixinConstraintValidation(\n * mixinFormAssociated(mixinElementInternals(LitElement))\n * );\n *\n * class MyCheckbox extends baseClass {\n * \\@property({type: Boolean}) checked = false;\n * \\@property({type: Boolean}) required = false;\n *\n * [createValidator]() {\n * return new CheckboxValidator(() => this);\n * }\n *\n * [getValidityAnchor]() {\n * return this.renderRoot.querySelector('.root');\n * }\n * }\n * ```\n *\n * @param base The class to mix functionality into.\n * @return The provided class with `ConstraintValidation` mixed in.\n */\nexport function mixinConstraintValidation<\n T extends MixinBase<LitElement & FormAssociated & WithElementInternals>,\n>(base: T): MixinReturn<T, ConstraintValidation> {\n abstract class ConstraintValidationElement\n extends base\n implements ConstraintValidation\n {\n get validity() {\n this[privateSyncValidity]();\n return this[internals].validity;\n }\n\n get validationMessage() {\n this[privateSyncValidity]();\n return this[internals].validationMessage;\n }\n\n get willValidate() {\n this[privateSyncValidity]();\n return this[internals].willValidate;\n }\n\n /**\n * A validator instance created from `[createValidator]()`.\n */\n [privateValidator]?: Validator<unknown>;\n\n /**\n * Needed for Safari, see https://bugs.webkit.org/show_bug.cgi?id=261432\n * Replace with this[internals].validity.customError when resolved.\n */\n [privateCustomValidationMessage] = '';\n\n checkValidity() {\n this[privateSyncValidity]();\n return this[internals].checkValidity();\n }\n\n reportValidity() {\n this[privateSyncValidity]();\n return this[internals].reportValidity();\n }\n\n setCustomValidity(error: string) {\n this[privateCustomValidationMessage] = error;\n this[privateSyncValidity]();\n }\n\n override requestUpdate(\n name?: PropertyKey,\n oldValue?: unknown,\n options?: PropertyDeclaration,\n ) {\n super.requestUpdate(name, oldValue, options);\n this[privateSyncValidity]();\n }\n\n [privateSyncValidity]() {\n if (isServer) {\n return;\n }\n\n if (!this[privateValidator]) {\n this[privateValidator] = this[createValidator]();\n }\n\n const {validity, validationMessage: nonCustomValidationMessage} =\n this[privateValidator].getValidity();\n\n const customError = !!this[privateCustomValidationMessage];\n const validationMessage =\n this[privateCustomValidationMessage] || nonCustomValidationMessage;\n\n this[internals].setValidity(\n {...validity, customError},\n validationMessage,\n this[getValidityAnchor]() ?? undefined,\n );\n }\n\n [createValidator](): Validator<unknown> {\n throw new Error('Implement [createValidator]');\n }\n\n [getValidityAnchor](): HTMLElement | null {\n throw new Error('Implement [getValidityAnchor]');\n }\n }\n\n return ConstraintValidationElement;\n}\n"]}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { LitElement } from 'lit';
7
+ import { ConstraintValidation } from './constraint-validation.js';
8
+ import { MixinBase, MixinReturn } from './mixin.js';
9
+ /**
10
+ * A constraint validation element that has a callback for when the element
11
+ * should report validity styles and error messages to the user.
12
+ *
13
+ * This is commonly used in text-field-like controls that display error styles
14
+ * and error messages.
15
+ */
16
+ export interface OnReportValidity extends ConstraintValidation {
17
+ /**
18
+ * A callback that is invoked when validity should be reported. Components
19
+ * that can display their own error state can use this and update their
20
+ * styles.
21
+ *
22
+ * If an invalid event is provided, the element is invalid. If `null`, the
23
+ * element is valid.
24
+ *
25
+ * The invalid event's `preventDefault()` may be called to stop the platform
26
+ * popup from displaying.
27
+ *
28
+ * @param invalidEvent The `invalid` event dispatched when an element is
29
+ * invalid, or `null` if the element is valid.
30
+ */
31
+ [onReportValidity](invalidEvent: Event | null): void;
32
+ formAssociatedCallback(form: HTMLFormElement | null): void;
33
+ }
34
+ /**
35
+ * A symbol property used for a callback when validity has been reported.
36
+ */
37
+ export declare const onReportValidity: unique symbol;
38
+ /**
39
+ * Mixes in a callback for constraint validation when validity should be
40
+ * styled and reported to the user.
41
+ *
42
+ * This is commonly used in text-field-like controls that display error styles
43
+ * and error messages.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const baseClass = mixinOnReportValidity(
48
+ * mixinConstraintValidation(
49
+ * mixinFormAssociated(mixinElementInternals(LitElement)),
50
+ * ),
51
+ * );
52
+ *
53
+ * class MyField extends baseClass {
54
+ * \@property({type: Boolean}) error = false;
55
+ * \@property() errorMessage = '';
56
+ *
57
+ * [onReportValidity](invalidEvent: Event | null) {
58
+ * this.error = !!invalidEvent;
59
+ * this.errorMessage = this.validationMessage;
60
+ *
61
+ * // Optionally prevent platform popup from displaying
62
+ * invalidEvent?.preventDefault();
63
+ * }
64
+ * }
65
+ * ```
66
+ *
67
+ * @param base The class to mix functionality into.
68
+ * @return The provided class with `OnReportValidity` mixed in.
69
+ */
70
+ export declare function mixinOnReportValidity<T extends MixinBase<LitElement & ConstraintValidation>>(base: T): MixinReturn<T, OnReportValidity>;
@@ -0,0 +1,150 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * A symbol property used for a callback when validity has been reported.
8
+ */
9
+ export const onReportValidity = Symbol('onReportValidity');
10
+ // Private symbol members, used to avoid name clashing.
11
+ const privateCleanupFormListeners = Symbol('privateCleanupFormListeners');
12
+ /**
13
+ * Mixes in a callback for constraint validation when validity should be
14
+ * styled and reported to the user.
15
+ *
16
+ * This is commonly used in text-field-like controls that display error styles
17
+ * and error messages.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const baseClass = mixinOnReportValidity(
22
+ * mixinConstraintValidation(
23
+ * mixinFormAssociated(mixinElementInternals(LitElement)),
24
+ * ),
25
+ * );
26
+ *
27
+ * class MyField extends baseClass {
28
+ * \@property({type: Boolean}) error = false;
29
+ * \@property() errorMessage = '';
30
+ *
31
+ * [onReportValidity](invalidEvent: Event | null) {
32
+ * this.error = !!invalidEvent;
33
+ * this.errorMessage = this.validationMessage;
34
+ *
35
+ * // Optionally prevent platform popup from displaying
36
+ * invalidEvent?.preventDefault();
37
+ * }
38
+ * }
39
+ * ```
40
+ *
41
+ * @param base The class to mix functionality into.
42
+ * @return The provided class with `OnReportValidity` mixed in.
43
+ */
44
+ export function mixinOnReportValidity(base) {
45
+ var _a;
46
+ class OnReportValidityElement extends base {
47
+ constructor() {
48
+ super(...arguments);
49
+ /**
50
+ * Used to clean up event listeners when a new form is associated.
51
+ */
52
+ this[_a] = new AbortController();
53
+ }
54
+ reportValidity() {
55
+ let invalidEvent = null;
56
+ const cleanupInvalidListener = new AbortController();
57
+ this.addEventListener('invalid', (event) => {
58
+ invalidEvent = event;
59
+ }, { signal: cleanupInvalidListener.signal });
60
+ const valid = super.reportValidity();
61
+ cleanupInvalidListener.abort();
62
+ // event may be null, so check for strict `true`. If null it should still
63
+ // be reported.
64
+ if (invalidEvent?.defaultPrevented !== true) {
65
+ this[onReportValidity](invalidEvent);
66
+ }
67
+ return valid;
68
+ }
69
+ [(_a = privateCleanupFormListeners, onReportValidity)](invalidEvent) {
70
+ throw new Error('Implement [onReportValidity]');
71
+ }
72
+ formAssociatedCallback(form) {
73
+ // can't use super.formAssociatedCallback?.() due to closure
74
+ if (super.formAssociatedCallback) {
75
+ super.formAssociatedCallback(form);
76
+ }
77
+ // Clean up previous submit listener
78
+ this[privateCleanupFormListeners].abort();
79
+ if (!form) {
80
+ return;
81
+ }
82
+ this[privateCleanupFormListeners] = new AbortController();
83
+ // If the element's form submits, then all controls are valid. This lets
84
+ // the element remove its error styles that may have been set when
85
+ // `reportValidity()` was called.
86
+ form.addEventListener('submit', () => {
87
+ this[onReportValidity](null);
88
+ }, {
89
+ signal: this[privateCleanupFormListeners].signal,
90
+ });
91
+ // Inject a callback when `form.reportValidity()` is called and the form
92
+ // is valid. There isn't an event that is dispatched to alert us (unlike
93
+ // the 'invalid' event), and we need to remove error styles when
94
+ // `form.reportValidity()` is called and returns true.
95
+ let reportedInvalidEventFromForm = false;
96
+ let formReportValidityCleanup = new AbortController();
97
+ injectFormReportValidityHooks({
98
+ form,
99
+ cleanup: this[privateCleanupFormListeners].signal,
100
+ beforeReportValidity: () => {
101
+ reportedInvalidEventFromForm = false;
102
+ this.addEventListener('invalid', (invalidEvent) => {
103
+ reportedInvalidEventFromForm = true;
104
+ if (!invalidEvent.defaultPrevented) {
105
+ this[onReportValidity](invalidEvent);
106
+ }
107
+ }, { signal: formReportValidityCleanup.signal });
108
+ },
109
+ afterReportValidity: () => {
110
+ formReportValidityCleanup.abort();
111
+ formReportValidityCleanup = new AbortController();
112
+ if (reportedInvalidEventFromForm) {
113
+ reportedInvalidEventFromForm = false;
114
+ return;
115
+ }
116
+ // Report successful form validation if an invalid event wasn't
117
+ // fired.
118
+ this[onReportValidity](null);
119
+ },
120
+ });
121
+ }
122
+ }
123
+ return OnReportValidityElement;
124
+ }
125
+ const FORM_REPORT_VALIDITY_HOOKS = new WeakMap();
126
+ function injectFormReportValidityHooks({ form, beforeReportValidity, afterReportValidity, cleanup, }) {
127
+ if (!FORM_REPORT_VALIDITY_HOOKS.has(form)) {
128
+ // Patch form.reportValidity() to add an event target that can be used to
129
+ // react when the method is called.
130
+ // We should only patch this method once, since multiple controls and other
131
+ // forces may want to patch this method. We cannot reliably clean it up by
132
+ // resetting the method to "superReportValidity", which may be a patched
133
+ // function.
134
+ // Instead, we never clean up the patch but add and clean up event listener
135
+ // hooks once it's patched.
136
+ const hooks = new EventTarget();
137
+ const superReportValidity = form.reportValidity;
138
+ form.reportValidity = function () {
139
+ hooks.dispatchEvent(new Event('before'));
140
+ const valid = superReportValidity.call(this);
141
+ hooks.dispatchEvent(new Event('after'));
142
+ return valid;
143
+ };
144
+ FORM_REPORT_VALIDITY_HOOKS.set(form, hooks);
145
+ }
146
+ const hooks = FORM_REPORT_VALIDITY_HOOKS.get(form);
147
+ hooks.addEventListener('before', beforeReportValidity, { signal: cleanup });
148
+ hooks.addEventListener('after', afterReportValidity, { signal: cleanup });
149
+ }
150
+ //# sourceMappingURL=on-report-validity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"on-report-validity.js","sourceRoot":"","sources":["on-report-validity.ts"],"names":[],"mappings":"AAAA;;;;GAIG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Element} from 'lit';\n\nimport {ConstraintValidation} from './constraint-validation.js';\nimport {MixinBase, MixinReturn} from './mixin.js';\n\n/**\n * A constraint validation element that has a callback for when the element\n * should report validity styles and error messages to the user.\n *\n * This is commonly used in text-field-like controls that display error styles\n * and error messages.\n */\nexport interface OnReportValidity extends ConstraintValidation {\n /**\n * A callback that is invoked when validity should be reported. Components\n * that can display their own error state can use this and update their\n * styles.\n *\n * If an invalid event is provided, the element is invalid. If `null`, the\n * element is valid.\n *\n * The invalid event's `preventDefault()` may be called to stop the platform\n * popup from displaying.\n *\n * @param invalidEvent The `invalid` event dispatched when an element is\n * invalid, or `null` if the element is valid.\n */\n [onReportValidity](invalidEvent: Event | null): void;\n\n // `mixinOnReportValidity()` implements this optional method. If overriden,\n // call `super.formAssociatedCallback(form)`.\n // (inherit jsdoc from `FormAssociated`)\n formAssociatedCallback(form: HTMLFormElement | null): void;\n}\n\n/**\n * A symbol property used for a callback when validity has been reported.\n */\nexport const onReportValidity = Symbol('onReportValidity');\n\n// Private symbol members, used to avoid name clashing.\nconst privateCleanupFormListeners = Symbol('privateCleanupFormListeners');\n\n/**\n * Mixes in a callback for constraint validation when validity should be\n * styled and reported to the user.\n *\n * This is commonly used in text-field-like controls that display error styles\n * and error messages.\n *\n * @example\n * ```ts\n * const baseClass = mixinOnReportValidity(\n * mixinConstraintValidation(\n * mixinFormAssociated(mixinElementInternals(LitElement)),\n * ),\n * );\n *\n * class MyField extends baseClass {\n * \\@property({type: Boolean}) error = false;\n * \\@property() errorMessage = '';\n *\n * [onReportValidity](invalidEvent: Event | null) {\n * this.error = !!invalidEvent;\n * this.errorMessage = this.validationMessage;\n *\n * // Optionally prevent platform popup from displaying\n * invalidEvent?.preventDefault();\n * }\n * }\n * ```\n *\n * @param base The class to mix functionality into.\n * @return The provided class with `OnReportValidity` mixed in.\n */\nexport function mixinOnReportValidity<\n T extends MixinBase<LitElement & ConstraintValidation>,\n>(base: T): MixinReturn<T, OnReportValidity> {\n abstract class OnReportValidityElement\n extends base\n implements OnReportValidity\n {\n /**\n * Used to clean up event listeners when a new form is associated.\n */\n [privateCleanupFormListeners] = new AbortController();\n\n override reportValidity() {\n let invalidEvent = null as Event | null;\n const cleanupInvalidListener = new AbortController();\n this.addEventListener(\n 'invalid',\n (event) => {\n invalidEvent = event;\n },\n {signal: cleanupInvalidListener.signal},\n );\n\n const valid = super.reportValidity();\n cleanupInvalidListener.abort();\n // event may be null, so check for strict `true`. If null it should still\n // be reported.\n if (invalidEvent?.defaultPrevented !== true) {\n this[onReportValidity](invalidEvent);\n }\n\n return valid;\n }\n\n [onReportValidity](invalidEvent: Event | null) {\n throw new Error('Implement [onReportValidity]');\n }\n\n override formAssociatedCallback(form: HTMLFormElement | null) {\n // can't use super.formAssociatedCallback?.() due to closure\n if (super.formAssociatedCallback) {\n super.formAssociatedCallback(form);\n }\n\n // Clean up previous submit listener\n this[privateCleanupFormListeners].abort();\n if (!form) {\n return;\n }\n\n this[privateCleanupFormListeners] = new AbortController();\n // If the element's form submits, then all controls are valid. This lets\n // the element remove its error styles that may have been set when\n // `reportValidity()` was called.\n form.addEventListener(\n 'submit',\n () => {\n this[onReportValidity](null);\n },\n {\n signal: this[privateCleanupFormListeners].signal,\n },\n );\n\n // Inject a callback when `form.reportValidity()` is called and the form\n // is valid. There isn't an event that is dispatched to alert us (unlike\n // the 'invalid' event), and we need to remove error styles when\n // `form.reportValidity()` is called and returns true.\n let reportedInvalidEventFromForm = false;\n let formReportValidityCleanup = new AbortController();\n injectFormReportValidityHooks({\n form,\n cleanup: this[privateCleanupFormListeners].signal,\n beforeReportValidity: () => {\n reportedInvalidEventFromForm = false;\n this.addEventListener(\n 'invalid',\n (invalidEvent) => {\n reportedInvalidEventFromForm = true;\n if (!invalidEvent.defaultPrevented) {\n this[onReportValidity](invalidEvent);\n }\n },\n {signal: formReportValidityCleanup.signal},\n );\n },\n afterReportValidity: () => {\n formReportValidityCleanup.abort();\n formReportValidityCleanup = new AbortController();\n if (reportedInvalidEventFromForm) {\n reportedInvalidEventFromForm = false;\n return;\n }\n\n // Report successful form validation if an invalid event wasn't\n // fired.\n this[onReportValidity](null);\n },\n });\n }\n }\n\n return OnReportValidityElement;\n}\n\nconst FORM_REPORT_VALIDITY_HOOKS = new WeakMap<HTMLFormElement, EventTarget>();\n\nfunction injectFormReportValidityHooks({\n form,\n beforeReportValidity,\n afterReportValidity,\n cleanup,\n}: {\n form: HTMLFormElement;\n beforeReportValidity: () => void;\n afterReportValidity: () => void;\n cleanup: AbortSignal;\n}) {\n if (!FORM_REPORT_VALIDITY_HOOKS.has(form)) {\n // Patch form.reportValidity() to add an event target that can be used to\n // react when the method is called.\n // We should only patch this method once, since multiple controls and other\n // forces may want to patch this method. We cannot reliably clean it up by\n // resetting the method to \"superReportValidity\", which may be a patched\n // function.\n // Instead, we never clean up the patch but add and clean up event listener\n // hooks once it's patched.\n const hooks = new EventTarget();\n const superReportValidity = form.reportValidity;\n form.reportValidity = function (this: HTMLFormElement) {\n hooks.dispatchEvent(new Event('before'));\n const valid = superReportValidity.call(this);\n hooks.dispatchEvent(new Event('after'));\n return valid;\n };\n\n FORM_REPORT_VALIDITY_HOOKS.set(form, hooks);\n }\n\n const hooks = FORM_REPORT_VALIDITY_HOOKS.get(form)!;\n hooks.addEventListener('before', beforeReportValidity, {signal: cleanup});\n hooks.addEventListener('after', afterReportValidity, {signal: cleanup});\n}\n"]}
@@ -11,11 +11,11 @@ export interface CheckboxState {
11
11
  /**
12
12
  * Whether the checkbox is checked.
13
13
  */
14
- checked: boolean;
14
+ readonly checked: boolean;
15
15
  /**
16
16
  * Whether the checkbox is required.
17
17
  */
18
- required: boolean;
18
+ readonly required: boolean;
19
19
  }
20
20
  /**
21
21
  * A validator that provides constraint validation that emulates
@@ -28,5 +28,4 @@ export declare class CheckboxValidator extends Validator<CheckboxState> {
28
28
  validationMessage: string;
29
29
  };
30
30
  protected equals(prev: CheckboxState, next: CheckboxState): boolean;
31
- protected copy({ checked, required }: CheckboxState): CheckboxState;
32
31
  }
@@ -25,8 +25,5 @@ export class CheckboxValidator extends Validator {
25
25
  equals(prev, next) {
26
26
  return prev.checked === next.checked && prev.required === next.required;
27
27
  }
28
- copy({ checked, required }) {
29
- return { checked, required };
30
- }
31
28
  }
32
29
  //# sourceMappingURL=checkbox-validator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkbox-validator.js","sourceRoot":"","sources":["checkbox-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAiBzC;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,SAAwB;IAG1C,eAAe,CAAC,KAAoB;QACrD,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,mCAAmC;YACnC,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACvD,IAAI,CAAC,eAAe,CAAC,IAAI,GAAG,UAAU,CAAC;SACxC;QAED,IAAI,CAAC,eAAe,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7C,IAAI,CAAC,eAAe,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/C,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC,QAAQ;YACvC,iBAAiB,EAAE,IAAI,CAAC,eAAe,CAAC,iBAAiB;SAC1D,CAAC;IACJ,CAAC;IAEkB,MAAM,CAAC,IAAmB,EAAE,IAAmB;QAChE,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAAC;IAC1E,CAAC;IAEkB,IAAI,CAAC,EAAC,OAAO,EAAE,QAAQ,EAAgB;QACxD,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,CAAC;IAC7B,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {Validator} from './validator.js';\n\n/**\n * Constraint validation properties for a checkbox.\n */\nexport interface CheckboxState {\n /**\n * Whether the checkbox is checked.\n */\n checked: boolean;\n\n /**\n * Whether the checkbox is required.\n */\n required: boolean;\n}\n\n/**\n * A validator that provides constraint validation that emulates\n * `<input type=\"checkbox\">` validation.\n */\nexport class CheckboxValidator extends Validator<CheckboxState> {\n private checkboxControl?: HTMLInputElement;\n\n protected override computeValidity(state: CheckboxState) {\n if (!this.checkboxControl) {\n // Lazily create the platform input\n this.checkboxControl = document.createElement('input');\n this.checkboxControl.type = 'checkbox';\n }\n\n this.checkboxControl.checked = state.checked;\n this.checkboxControl.required = state.required;\n return {\n validity: this.checkboxControl.validity,\n validationMessage: this.checkboxControl.validationMessage,\n };\n }\n\n protected override equals(prev: CheckboxState, next: CheckboxState) {\n return prev.checked === next.checked && prev.required === next.required;\n }\n\n protected override copy({checked, required}: CheckboxState): CheckboxState {\n return {checked, required};\n }\n}\n"]}
1
+ {"version":3,"file":"checkbox-validator.js","sourceRoot":"","sources":["checkbox-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAiBzC;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,SAAwB;IAG1C,eAAe,CAAC,KAAoB;QACrD,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,mCAAmC;YACnC,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACvD,IAAI,CAAC,eAAe,CAAC,IAAI,GAAG,UAAU,CAAC;SACxC;QAED,IAAI,CAAC,eAAe,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7C,IAAI,CAAC,eAAe,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/C,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC,QAAQ;YACvC,iBAAiB,EAAE,IAAI,CAAC,eAAe,CAAC,iBAAiB;SAC1D,CAAC;IACJ,CAAC;IAEkB,MAAM,CAAC,IAAmB,EAAE,IAAmB;QAChE,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAAC;IAC1E,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {Validator} from './validator.js';\n\n/**\n * Constraint validation properties for a checkbox.\n */\nexport interface CheckboxState {\n /**\n * Whether the checkbox is checked.\n */\n readonly checked: boolean;\n\n /**\n * Whether the checkbox is required.\n */\n readonly required: boolean;\n}\n\n/**\n * A validator that provides constraint validation that emulates\n * `<input type=\"checkbox\">` validation.\n */\nexport class CheckboxValidator extends Validator<CheckboxState> {\n private checkboxControl?: HTMLInputElement;\n\n protected override computeValidity(state: CheckboxState) {\n if (!this.checkboxControl) {\n // Lazily create the platform input\n this.checkboxControl = document.createElement('input');\n this.checkboxControl.type = 'checkbox';\n }\n\n this.checkboxControl.checked = state.checked;\n this.checkboxControl.required = state.required;\n return {\n validity: this.checkboxControl.validity,\n validationMessage: this.checkboxControl.validationMessage,\n };\n }\n\n protected override equals(prev: CheckboxState, next: CheckboxState) {\n return prev.checked === next.checked && prev.required === next.required;\n }\n}\n"]}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Validator } from './validator.js';
7
+ /**
8
+ * Constraint validation properties for a radio.
9
+ */
10
+ export interface RadioState {
11
+ /**
12
+ * Whether the radio is checked.
13
+ */
14
+ readonly checked: boolean;
15
+ /**
16
+ * Whether the radio is required.
17
+ */
18
+ readonly required: boolean;
19
+ }
20
+ /**
21
+ * Radio constraint validation properties for a single radio and its siblings.
22
+ */
23
+ export type RadioGroupState = readonly [RadioState, ...RadioState[]];
24
+ /**
25
+ * A validator that provides constraint validation that emulates
26
+ * `<input type="radio">` validation.
27
+ */
28
+ export declare class RadioValidator extends Validator<RadioGroupState> {
29
+ private radioElement?;
30
+ protected computeValidity(states: RadioGroupState): {
31
+ validity: {
32
+ valueMissing: boolean;
33
+ };
34
+ validationMessage: string;
35
+ };
36
+ protected equals(prevGroup: RadioGroupState, nextGroup: RadioGroupState): boolean;
37
+ protected copy(states: RadioGroupState): RadioGroupState;
38
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Validator } from './validator.js';
7
+ /**
8
+ * A validator that provides constraint validation that emulates
9
+ * `<input type="radio">` validation.
10
+ */
11
+ export class RadioValidator extends Validator {
12
+ computeValidity(states) {
13
+ if (!this.radioElement) {
14
+ // Lazily create the radio element
15
+ this.radioElement = document.createElement('input');
16
+ this.radioElement.type = 'radio';
17
+ // A name is required for validation to run
18
+ this.radioElement.name = 'group';
19
+ }
20
+ let isRequired = false;
21
+ let isChecked = false;
22
+ for (const { checked, required } of states) {
23
+ if (required) {
24
+ isRequired = true;
25
+ }
26
+ if (checked) {
27
+ isChecked = true;
28
+ }
29
+ }
30
+ // Firefox v119 doesn't compute grouped radio validation correctly while
31
+ // they are detached from the DOM, which is why we don't render multiple
32
+ // virtual <input>s. Instead, we can check the required/checked states and
33
+ // grab the i18n'd validation message if the value is missing.
34
+ this.radioElement.checked = isChecked;
35
+ this.radioElement.required = isRequired;
36
+ return {
37
+ validity: {
38
+ valueMissing: isRequired && !isChecked,
39
+ },
40
+ validationMessage: this.radioElement.validationMessage,
41
+ };
42
+ }
43
+ equals(prevGroup, nextGroup) {
44
+ if (prevGroup.length !== nextGroup.length) {
45
+ return false;
46
+ }
47
+ for (let i = 0; i < prevGroup.length; i++) {
48
+ const prev = prevGroup[i];
49
+ const next = nextGroup[i];
50
+ if (prev.checked !== next.checked || prev.required !== next.required) {
51
+ return false;
52
+ }
53
+ }
54
+ return true;
55
+ }
56
+ copy(states) {
57
+ // Cast as unknown since typescript does not have enough information to
58
+ // infer that the array always has at least one element.
59
+ return states.map(({ checked, required }) => ({
60
+ checked,
61
+ required,
62
+ }));
63
+ }
64
+ }
65
+ //# sourceMappingURL=radio-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"radio-validator.js","sourceRoot":"","sources":["radio-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAsBzC;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,SAA0B;IAGzC,eAAe,CAAC,MAAuB;QACxD,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACtB,kCAAkC;YAClC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACpD,IAAI,CAAC,YAAY,CAAC,IAAI,GAAG,OAAO,CAAC;YACjC,2CAA2C;YAC3C,IAAI,CAAC,YAAY,CAAC,IAAI,GAAG,OAAO,CAAC;SAClC;QAED,IAAI,UAAU,GAAG,KAAK,CAAC;QACvB,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,KAAK,MAAM,EAAC,OAAO,EAAE,QAAQ,EAAC,IAAI,MAAM,EAAE;YACxC,IAAI,QAAQ,EAAE;gBACZ,UAAU,GAAG,IAAI,CAAC;aACnB;YAED,IAAI,OAAO,EAAE;gBACX,SAAS,GAAG,IAAI,CAAC;aAClB;SACF;QAED,wEAAwE;QACxE,wEAAwE;QACxE,0EAA0E;QAC1E,8DAA8D;QAC9D,IAAI,CAAC,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC;QACtC,IAAI,CAAC,YAAY,CAAC,QAAQ,GAAG,UAAU,CAAC;QACxC,OAAO;YACL,QAAQ,EAAE;gBACR,YAAY,EAAE,UAAU,IAAI,CAAC,SAAS;aACvC;YACD,iBAAiB,EAAE,IAAI,CAAC,YAAY,CAAC,iBAAiB;SACvD,CAAC;IACJ,CAAC;IAEkB,MAAM,CACvB,SAA0B,EAC1B,SAA0B;QAE1B,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE;YACzC,OAAO,KAAK,CAAC;SACd;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACzC,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YAC1B,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YAC1B,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,EAAE;gBACpE,OAAO,KAAK,CAAC;aACd;SACF;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEkB,IAAI,CAAC,MAAuB;QAC7C,uEAAuE;QACvE,wDAAwD;QACxD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,EAAC,OAAO,EAAE,QAAQ,EAAC,EAAE,EAAE,CAAC,CAAC;YAC1C,OAAO;YACP,QAAQ;SACT,CAAC,CAA+B,CAAC;IACpC,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {Validator} from './validator.js';\n\n/**\n * Constraint validation properties for a radio.\n */\nexport interface RadioState {\n /**\n * Whether the radio is checked.\n */\n readonly checked: boolean;\n\n /**\n * Whether the radio is required.\n */\n readonly required: boolean;\n}\n\n/**\n * Radio constraint validation properties for a single radio and its siblings.\n */\nexport type RadioGroupState = readonly [RadioState, ...RadioState[]];\n\n/**\n * A validator that provides constraint validation that emulates\n * `<input type=\"radio\">` validation.\n */\nexport class RadioValidator extends Validator<RadioGroupState> {\n private radioElement?: HTMLInputElement;\n\n protected override computeValidity(states: RadioGroupState) {\n if (!this.radioElement) {\n // Lazily create the radio element\n this.radioElement = document.createElement('input');\n this.radioElement.type = 'radio';\n // A name is required for validation to run\n this.radioElement.name = 'group';\n }\n\n let isRequired = false;\n let isChecked = false;\n for (const {checked, required} of states) {\n if (required) {\n isRequired = true;\n }\n\n if (checked) {\n isChecked = true;\n }\n }\n\n // Firefox v119 doesn't compute grouped radio validation correctly while\n // they are detached from the DOM, which is why we don't render multiple\n // virtual <input>s. Instead, we can check the required/checked states and\n // grab the i18n'd validation message if the value is missing.\n this.radioElement.checked = isChecked;\n this.radioElement.required = isRequired;\n return {\n validity: {\n valueMissing: isRequired && !isChecked,\n },\n validationMessage: this.radioElement.validationMessage,\n };\n }\n\n protected override equals(\n prevGroup: RadioGroupState,\n nextGroup: RadioGroupState,\n ) {\n if (prevGroup.length !== nextGroup.length) {\n return false;\n }\n\n for (let i = 0; i < prevGroup.length; i++) {\n const prev = prevGroup[i];\n const next = nextGroup[i];\n if (prev.checked !== next.checked || prev.required !== next.required) {\n return false;\n }\n }\n\n return true;\n }\n\n protected override copy(states: RadioGroupState): RadioGroupState {\n // Cast as unknown since typescript does not have enough information to\n // infer that the array always has at least one element.\n return states.map(({checked, required}) => ({\n checked,\n required,\n })) as unknown as RadioGroupState;\n }\n}\n"]}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Validator } from './validator.js';
7
+ /**
8
+ * Constraint validation properties for a select dropdown.
9
+ */
10
+ export interface SelectState {
11
+ /**
12
+ * The current selected value.
13
+ */
14
+ readonly value: string;
15
+ /**
16
+ * Whether the select is required.
17
+ */
18
+ readonly required: boolean;
19
+ }
20
+ /**
21
+ * A validator that provides constraint validation that emulates `<select>`
22
+ * validation.
23
+ */
24
+ export declare class SelectValidator extends Validator<SelectState> {
25
+ private selectControl?;
26
+ protected computeValidity(state: SelectState): {
27
+ validity: ValidityState;
28
+ validationMessage: string;
29
+ };
30
+ protected equals(prev: SelectState, next: SelectState): boolean;
31
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { html, render } from 'lit';
7
+ import { Validator } from './validator.js';
8
+ /**
9
+ * A validator that provides constraint validation that emulates `<select>`
10
+ * validation.
11
+ */
12
+ export class SelectValidator extends Validator {
13
+ computeValidity(state) {
14
+ if (!this.selectControl) {
15
+ // Lazily create the platform select
16
+ this.selectControl = document.createElement('select');
17
+ }
18
+ render(html `<option value=${state.value}></option>`, this.selectControl);
19
+ this.selectControl.value = state.value;
20
+ this.selectControl.required = state.required;
21
+ return {
22
+ validity: this.selectControl.validity,
23
+ validationMessage: this.selectControl.validationMessage,
24
+ };
25
+ }
26
+ equals(prev, next) {
27
+ return prev.value === next.value && prev.required === next.required;
28
+ }
29
+ }
30
+ //# sourceMappingURL=select-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-validator.js","sourceRoot":"","sources":["select-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,MAAM,KAAK,CAAC;AAEjC,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAiBzC;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAsB;IAGtC,eAAe,CAAC,KAAkB;QACnD,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,oCAAoC;YACpC,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;SACvD;QAED,MAAM,CAAC,IAAI,CAAA,iBAAiB,KAAK,CAAC,KAAK,YAAY,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAEzE,IAAI,CAAC,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACvC,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC7C,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,aAAa,CAAC,QAAQ;YACrC,iBAAiB,EAAE,IAAI,CAAC,aAAa,CAAC,iBAAiB;SACxD,CAAC;IACJ,CAAC;IAEkB,MAAM,CAAC,IAAiB,EAAE,IAAiB;QAC5D,OAAO,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAAC;IACtE,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {html, render} from 'lit';\n\nimport {Validator} from './validator.js';\n\n/**\n * Constraint validation properties for a select dropdown.\n */\nexport interface SelectState {\n /**\n * The current selected value.\n */\n readonly value: string;\n\n /**\n * Whether the select is required.\n */\n readonly required: boolean;\n}\n\n/**\n * A validator that provides constraint validation that emulates `<select>`\n * validation.\n */\nexport class SelectValidator extends Validator<SelectState> {\n private selectControl?: HTMLSelectElement;\n\n protected override computeValidity(state: SelectState) {\n if (!this.selectControl) {\n // Lazily create the platform select\n this.selectControl = document.createElement('select');\n }\n\n render(html`<option value=${state.value}></option>`, this.selectControl);\n\n this.selectControl.value = state.value;\n this.selectControl.required = state.required;\n return {\n validity: this.selectControl.validity,\n validationMessage: this.selectControl.validationMessage,\n };\n }\n\n protected override equals(prev: SelectState, next: SelectState) {\n return prev.value === next.value && prev.required === next.required;\n }\n}\n"]}
@@ -73,7 +73,7 @@ export declare abstract class Validator<State> {
73
73
  * @param state The state to copy.
74
74
  * @return A copy of the state.
75
75
  */
76
- protected abstract copy(state: State): State;
76
+ protected copy(state: State): State;
77
77
  }
78
78
  /**
79
79
  * An object containing `ValidityStateFlags` and a corresponding validation
@@ -69,5 +69,15 @@ export class Validator {
69
69
  };
70
70
  return this.currentValidity;
71
71
  }
72
+ /**
73
+ * Creates a copy of a state. This is used to cache state and check if it
74
+ * changes.
75
+ *
76
+ * @param state The state to copy.
77
+ * @return A copy of the state.
78
+ */
79
+ copy(state) {
80
+ return { ...state };
81
+ }
72
82
  }
73
83
  //# sourceMappingURL=validator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validator.js","sourceRoot":"","sources":["validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,SAAS;IAgB7B;;;;;OAKG;IACH,YAA6B,eAA4B;QAA5B,oBAAe,GAAf,eAAe,CAAa;QAfzD;;;WAGG;QACK,oBAAe,GAAuB;YAC5C,QAAQ,EAAE,EAAE;YACZ,iBAAiB,EAAE,EAAE;SACtB,CAAC;IAQ0D,CAAC;IAE7D;;;;;;;;;OASG;IACH,WAAW;QACT,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACrC,MAAM,eAAe,GACnB,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACzD,IAAI,CAAC,eAAe,EAAE;YACpB,OAAO,IAAI,CAAC,eAAe,CAAC;SAC7B;QAED,MAAM,EAAC,QAAQ,EAAE,iBAAiB,EAAC,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAClE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,eAAe,GAAG;YACrB,iBAAiB;YACjB,QAAQ,EAAE;gBACR,uEAAuE;gBACvE,kDAAkD;gBAClD,QAAQ,EAAE,QAAQ,CAAC,QAAQ;gBAC3B,WAAW,EAAE,QAAQ,CAAC,WAAW;gBACjC,eAAe,EAAE,QAAQ,CAAC,eAAe;gBACzC,aAAa,EAAE,QAAQ,CAAC,aAAa;gBACrC,cAAc,EAAE,QAAQ,CAAC,cAAc;gBACvC,YAAY,EAAE,QAAQ,CAAC,YAAY;gBACnC,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;gBAC3B,YAAY,EAAE,QAAQ,CAAC,YAAY;gBACnC,YAAY,EAAE,QAAQ,CAAC,YAAY;aACpC;SACF,CAAC;QAEF,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;CAkCF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * A class that computes and caches `ValidityStateFlags` for a component with\n * a given `State` interface.\n *\n * Cached performance before computing validity is important since constraint\n * validation must be checked frequently and synchronously when properties\n * change.\n *\n * @template State The expected interface of properties relevant to constraint\n * validation.\n */\nexport abstract class Validator<State> {\n /**\n * The previous state, used to determine if state changed and validation needs\n * to be re-computed.\n */\n private prevState?: State;\n\n /**\n * The current validity state and message. This is cached and returns if\n * constraint validation state does not change.\n */\n private currentValidity: ValidityAndMessage = {\n validity: {},\n validationMessage: '',\n };\n\n /**\n * Creates a new validator.\n *\n * @param getCurrentState A callback that returns the current state of\n * constraint validation-related properties.\n */\n constructor(private readonly getCurrentState: () => State) {}\n\n /**\n * Returns the current `ValidityStateFlags` and validation message for the\n * validator.\n *\n * If the constraint validation state has not changed, this will return a\n * cached result. This is important since `getValidity()` can be called\n * frequently in response to synchronous property changes.\n *\n * @return The current validity and validation message.\n */\n getValidity(): ValidityAndMessage {\n const state = this.getCurrentState();\n const hasStateChanged =\n !this.prevState || !this.equals(this.prevState, state);\n if (!hasStateChanged) {\n return this.currentValidity;\n }\n\n const {validity, validationMessage} = this.computeValidity(state);\n this.prevState = this.copy(state);\n this.currentValidity = {\n validationMessage,\n validity: {\n // Change any `ValidityState` instances into `ValidityStateFlags` since\n // `ValidityState` cannot be easily `{...spread}`.\n badInput: validity.badInput,\n customError: validity.customError,\n patternMismatch: validity.patternMismatch,\n rangeOverflow: validity.rangeOverflow,\n rangeUnderflow: validity.rangeUnderflow,\n stepMismatch: validity.stepMismatch,\n tooLong: validity.tooLong,\n tooShort: validity.tooShort,\n typeMismatch: validity.typeMismatch,\n valueMissing: validity.valueMissing,\n },\n };\n\n return this.currentValidity;\n }\n\n /**\n * Computes the `ValidityStateFlags` and validation message for a given set\n * of constraint validation properties.\n *\n * Implementations can use platform elements like `<input>` and `<select>` to\n * sync state and compute validation along with i18n'd messages. This function\n * may be expensive, and is only called when state changes.\n *\n * @param state The new state of constraint validation properties.\n * @return An object containing a `validity` property with\n * `ValidityStateFlags` and a `validationMessage` property.\n */\n protected abstract computeValidity(state: State): ValidityAndMessage;\n\n /**\n * Checks if two states are equal. This is used to check against cached state\n * to see if validity needs to be re-computed.\n *\n * @param prev The previous state.\n * @param next The next state.\n * @return True if the states are equal, or false if not.\n */\n protected abstract equals(prev: State, next: State): boolean;\n\n /**\n * Creates a copy of a state. This is used to cache state and check if it\n * changes.\n *\n * @param state The state to copy.\n * @return A copy of the state.\n */\n protected abstract copy(state: State): State;\n}\n\n/**\n * An object containing `ValidityStateFlags` and a corresponding validation\n * message.\n */\nexport interface ValidityAndMessage {\n /**\n * Validity flags.\n */\n validity: ValidityStateFlags;\n\n /**\n * The validation message for the associated flags. It may not be an empty\n * string if any of the validity flags are `true`.\n */\n validationMessage: string;\n}\n"]}
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,SAAS;IAgB7B;;;;;OAKG;IACH,YAA6B,eAA4B;QAA5B,oBAAe,GAAf,eAAe,CAAa;QAfzD;;;WAGG;QACK,oBAAe,GAAuB;YAC5C,QAAQ,EAAE,EAAE;YACZ,iBAAiB,EAAE,EAAE;SACtB,CAAC;IAQ0D,CAAC;IAE7D;;;;;;;;;OASG;IACH,WAAW;QACT,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACrC,MAAM,eAAe,GACnB,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACzD,IAAI,CAAC,eAAe,EAAE;YACpB,OAAO,IAAI,CAAC,eAAe,CAAC;SAC7B;QAED,MAAM,EAAC,QAAQ,EAAE,iBAAiB,EAAC,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAClE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,eAAe,GAAG;YACrB,iBAAiB;YACjB,QAAQ,EAAE;gBACR,uEAAuE;gBACvE,kDAAkD;gBAClD,QAAQ,EAAE,QAAQ,CAAC,QAAQ;gBAC3B,WAAW,EAAE,QAAQ,CAAC,WAAW;gBACjC,eAAe,EAAE,QAAQ,CAAC,eAAe;gBACzC,aAAa,EAAE,QAAQ,CAAC,aAAa;gBACrC,cAAc,EAAE,QAAQ,CAAC,cAAc;gBACvC,YAAY,EAAE,QAAQ,CAAC,YAAY;gBACnC,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;gBAC3B,YAAY,EAAE,QAAQ,CAAC,YAAY;gBACnC,YAAY,EAAE,QAAQ,CAAC,YAAY;aACpC;SACF,CAAC;QAEF,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IA0BD;;;;;;OAMG;IACO,IAAI,CAAC,KAAY;QACzB,OAAO,EAAC,GAAG,KAAK,EAAC,CAAC;IACpB,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * A class that computes and caches `ValidityStateFlags` for a component with\n * a given `State` interface.\n *\n * Cached performance before computing validity is important since constraint\n * validation must be checked frequently and synchronously when properties\n * change.\n *\n * @template State The expected interface of properties relevant to constraint\n * validation.\n */\nexport abstract class Validator<State> {\n /**\n * The previous state, used to determine if state changed and validation needs\n * to be re-computed.\n */\n private prevState?: State;\n\n /**\n * The current validity state and message. This is cached and returns if\n * constraint validation state does not change.\n */\n private currentValidity: ValidityAndMessage = {\n validity: {},\n validationMessage: '',\n };\n\n /**\n * Creates a new validator.\n *\n * @param getCurrentState A callback that returns the current state of\n * constraint validation-related properties.\n */\n constructor(private readonly getCurrentState: () => State) {}\n\n /**\n * Returns the current `ValidityStateFlags` and validation message for the\n * validator.\n *\n * If the constraint validation state has not changed, this will return a\n * cached result. This is important since `getValidity()` can be called\n * frequently in response to synchronous property changes.\n *\n * @return The current validity and validation message.\n */\n getValidity(): ValidityAndMessage {\n const state = this.getCurrentState();\n const hasStateChanged =\n !this.prevState || !this.equals(this.prevState, state);\n if (!hasStateChanged) {\n return this.currentValidity;\n }\n\n const {validity, validationMessage} = this.computeValidity(state);\n this.prevState = this.copy(state);\n this.currentValidity = {\n validationMessage,\n validity: {\n // Change any `ValidityState` instances into `ValidityStateFlags` since\n // `ValidityState` cannot be easily `{...spread}`.\n badInput: validity.badInput,\n customError: validity.customError,\n patternMismatch: validity.patternMismatch,\n rangeOverflow: validity.rangeOverflow,\n rangeUnderflow: validity.rangeUnderflow,\n stepMismatch: validity.stepMismatch,\n tooLong: validity.tooLong,\n tooShort: validity.tooShort,\n typeMismatch: validity.typeMismatch,\n valueMissing: validity.valueMissing,\n },\n };\n\n return this.currentValidity;\n }\n\n /**\n * Computes the `ValidityStateFlags` and validation message for a given set\n * of constraint validation properties.\n *\n * Implementations can use platform elements like `<input>` and `<select>` to\n * sync state and compute validation along with i18n'd messages. This function\n * may be expensive, and is only called when state changes.\n *\n * @param state The new state of constraint validation properties.\n * @return An object containing a `validity` property with\n * `ValidityStateFlags` and a `validationMessage` property.\n */\n protected abstract computeValidity(state: State): ValidityAndMessage;\n\n /**\n * Checks if two states are equal. This is used to check against cached state\n * to see if validity needs to be re-computed.\n *\n * @param prev The previous state.\n * @param next The next state.\n * @return True if the states are equal, or false if not.\n */\n protected abstract equals(prev: State, next: State): boolean;\n\n /**\n * Creates a copy of a state. This is used to cache state and check if it\n * changes.\n *\n * @param state The state to copy.\n * @return A copy of the state.\n */\n protected copy(state: State): State {\n return {...state};\n }\n}\n\n/**\n * An object containing `ValidityStateFlags` and a corresponding validation\n * message.\n */\nexport interface ValidityAndMessage {\n /**\n * Validity flags.\n */\n validity: ValidityStateFlags;\n\n /**\n * The validation message for the associated flags. It may not be an empty\n * string if any of the validity flags are `true`.\n */\n validationMessage: string;\n}\n"]}
@@ -37,6 +37,7 @@
37
37
  :host {
38
38
  border-radius: map.get($tokens, 'container-shape');
39
39
  display: flex;
40
+ -webkit-tap-highlight-color: transparent;
40
41
 
41
42
  @include ripple.theme(
42
43
  (