@material/web 1.1.2-nightly.035d155.0 → 1.1.2-nightly.3151fd8.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.
- package/button/internal/_filled-button.scss +1 -0
- package/button/internal/_filled-tonal-button.scss +1 -0
- package/button/internal/_text-button.scss +1 -0
- package/chips/internal/filter-chip.js +7 -1
- package/chips/internal/filter-chip.js.map +1 -1
- package/labs/behaviors/on-report-validity.js +107 -60
- package/labs/behaviors/on-report-validity.js.map +1 -1
- package/package.json +1 -1
- package/ripple/internal/ripple.js +1 -0
- package/ripple/internal/ripple.js.map +1 -1
- package/select/harness.d.ts +1 -0
- package/select/harness.js +7 -0
- package/select/harness.js.map +1 -1
- package/select/internal/select.js +4 -3
- package/select/internal/select.js.map +1 -1
- package/slider/internal/slider.js +2 -2
- package/slider/internal/slider.js.map +1 -1
- package/textfield/internal/_input.scss +12 -0
- package/textfield/internal/shared-styles.css.js +1 -1
- package/textfield/internal/shared-styles.css.js.map +1 -1
- package/textfield/internal/text-field.d.ts +5 -2
- package/textfield/internal/text-field.js +18 -9
- package/textfield/internal/text-field.js.map +1 -1
|
@@ -88,10 +88,16 @@ export class FilterChip extends MultiActionChip {
|
|
|
88
88
|
if (this.disabled) {
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
|
+
// Store prevValue to revert in case `chip.selected` is changed during an
|
|
92
|
+
// event listener.
|
|
93
|
+
const prevValue = this.selected;
|
|
91
94
|
this.selected = !this.selected;
|
|
92
95
|
const preventDefault = !redispatchEvent(this, event);
|
|
93
96
|
if (preventDefault) {
|
|
94
|
-
this.selected = !this.selected
|
|
97
|
+
// We should not do `this.selected = !this.selected`, since a client
|
|
98
|
+
// click listener could change its value. Instead, always revert to the
|
|
99
|
+
// original value.
|
|
100
|
+
this.selected = prevValue;
|
|
95
101
|
return;
|
|
96
102
|
}
|
|
97
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter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,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC;QAE/B,MAAM,cAAc,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACrD,IAAI,cAAc,EAAE;YAClB,oEAAoE;YACpE,uEAAuE;YACvE,kBAAkB;YAClB,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;YAC1B,OAAO;SACR;IACH,CAAC;CACF;AArG4B;IAA1B,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC;4CAAkB;AACjB;IAA1B,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC;6CAAmB;AACH;IAAzC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;4CAAkB;AAS3D;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,mBAAmB,EAAC,CAAC;mDACjD;AAOL;IADlB,KAAK,CAAC,iBAAiB,CAAC;iDAC6B;AAEnC;IADlB,KAAK,CAAC,kBAAkB,CAAC;kDAC6B","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport '../../elevation/elevation.js';\n\nimport {html, nothing} from 'lit';\nimport {property, query} from 'lit/decorators.js';\n\nimport {ARIAMixinStrict} from '../../internal/aria/aria.js';\nimport {redispatchEvent} from '../../internal/events/redispatch-event.js';\n\nimport {MultiActionChip} from './multi-action-chip.js';\nimport {renderRemoveButton} from './trailing-icons.js';\n\n/**\n * A filter chip component.\n *\n * @fires remove {Event} Dispatched when the remove button is clicked.\n */\nexport class FilterChip extends MultiActionChip {\n @property({type: Boolean}) elevated = false;\n @property({type: Boolean}) removable = false;\n @property({type: Boolean, reflect: true}) selected = false;\n\n /**\n * Only needed for SSR.\n *\n * Add this attribute when a filter chip has a `slot=\"selected-icon\"` to avoid\n * a Flash Of Unstyled Content.\n */\n @property({type: Boolean, reflect: true, attribute: 'has-selected-icon'})\n hasSelectedIcon = false;\n\n protected get primaryId() {\n return 'button';\n }\n\n @query('.primary.action')\n protected readonly primaryAction!: HTMLElement | null;\n @query('.trailing.action')\n protected readonly trailingAction!: HTMLElement | null;\n\n protected override getContainerClasses() {\n return {\n ...super.getContainerClasses(),\n elevated: this.elevated,\n selected: this.selected,\n 'has-trailing': this.removable,\n 'has-icon': this.hasIcon || this.selected,\n };\n }\n\n protected override renderPrimaryAction(content: unknown) {\n const {ariaLabel} = this as ARIAMixinStrict;\n return html`\n <button\n class=\"primary action\"\n id=\"button\"\n aria-label=${ariaLabel || nothing}\n aria-pressed=${this.selected}\n ?disabled=${this.disabled && !this.alwaysFocusable}\n @click=${this.handleClick}\n >${content}</button\n >\n `;\n }\n\n protected override renderLeadingIcon() {\n if (!this.selected) {\n return super.renderLeadingIcon();\n }\n\n return html`\n <slot name=\"selected-icon\">\n <svg class=\"checkmark\" viewBox=\"0 0 18 18\" aria-hidden=\"true\">\n <path\n d=\"M6.75012 12.1274L3.62262 8.99988L2.55762 10.0574L6.75012 14.2499L15.7501 5.24988L14.6926 4.19238L6.75012 12.1274Z\" />\n </svg>\n </slot>\n `;\n }\n\n protected override renderTrailingAction(focusListener: EventListener) {\n if (this.removable) {\n return renderRemoveButton({\n focusListener,\n ariaLabel: this.ariaLabelRemove,\n disabled: this.disabled,\n });\n }\n\n return nothing;\n }\n\n protected override renderOutline() {\n if (this.elevated) {\n return html`<md-elevation></md-elevation>`;\n }\n\n return super.renderOutline();\n }\n\n private handleClick(event: MouseEvent) {\n if (this.disabled) {\n return;\n }\n\n // Store prevValue to revert in case `chip.selected` is changed during an\n // event listener.\n const prevValue = this.selected;\n this.selected = !this.selected;\n\n const preventDefault = !redispatchEvent(this, event);\n if (preventDefault) {\n // We should not do `this.selected = !this.selected`, since a client\n // click listener could change its value. Instead, always revert to the\n // original value.\n this.selected = prevValue;\n return;\n }\n }\n}\n"]}
|
|
@@ -109,77 +109,124 @@ export function mixinOnReportValidity(base) {
|
|
|
109
109
|
if (super.formAssociatedCallback) {
|
|
110
110
|
super.formAssociatedCallback(form);
|
|
111
111
|
}
|
|
112
|
-
// Clean up previous
|
|
112
|
+
// Clean up previous form listeners.
|
|
113
113
|
this[privateCleanupFormListeners].abort();
|
|
114
114
|
if (!form) {
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
117
|
this[privateCleanupFormListeners] = new AbortController();
|
|
118
|
-
//
|
|
119
|
-
// the
|
|
120
|
-
//
|
|
121
|
-
form.
|
|
118
|
+
// Add a listener that fires when the form runs constraint validation and
|
|
119
|
+
// the control is valid, so that it may remove its error styles.
|
|
120
|
+
//
|
|
121
|
+
// This happens on `form.reportValidity()` and `form.requestSubmit()`
|
|
122
|
+
// (both when the submit fails and passes).
|
|
123
|
+
addFormReportValidListener(this, form, () => {
|
|
122
124
|
this[onReportValidity](null);
|
|
123
|
-
},
|
|
124
|
-
signal: this[privateCleanupFormListeners].signal,
|
|
125
|
-
});
|
|
126
|
-
// Inject a callback when `form.reportValidity()` is called and the form
|
|
127
|
-
// is valid. There isn't an event that is dispatched to alert us (unlike
|
|
128
|
-
// the 'invalid' event), and we need to remove error styles when
|
|
129
|
-
// `form.reportValidity()` is called and returns true.
|
|
130
|
-
let reportedInvalidEventFromForm = false;
|
|
131
|
-
let formReportValidityCleanup = new AbortController();
|
|
132
|
-
injectFormReportValidityHooks({
|
|
133
|
-
form,
|
|
134
|
-
cleanup: this[privateCleanupFormListeners].signal,
|
|
135
|
-
beforeReportValidity: () => {
|
|
136
|
-
reportedInvalidEventFromForm = false;
|
|
137
|
-
this.addEventListener('invalid', (invalidEvent) => {
|
|
138
|
-
reportedInvalidEventFromForm = true;
|
|
139
|
-
if (!invalidEvent.defaultPrevented) {
|
|
140
|
-
this[onReportValidity](invalidEvent);
|
|
141
|
-
}
|
|
142
|
-
}, { signal: formReportValidityCleanup.signal });
|
|
143
|
-
},
|
|
144
|
-
afterReportValidity: () => {
|
|
145
|
-
formReportValidityCleanup.abort();
|
|
146
|
-
formReportValidityCleanup = new AbortController();
|
|
147
|
-
if (reportedInvalidEventFromForm) {
|
|
148
|
-
reportedInvalidEventFromForm = false;
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
// Report successful form validation if an invalid event wasn't
|
|
152
|
-
// fired.
|
|
153
|
-
this[onReportValidity](null);
|
|
154
|
-
},
|
|
155
|
-
});
|
|
125
|
+
}, this[privateCleanupFormListeners].signal);
|
|
156
126
|
}
|
|
157
127
|
}
|
|
158
128
|
return OnReportValidityElement;
|
|
159
129
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Add a listener that fires when a form runs constraint validation on a control
|
|
132
|
+
* and it is valid. This is needed to clear previously invalid styles.
|
|
133
|
+
*
|
|
134
|
+
* @param control The control of the form to listen for valid events.
|
|
135
|
+
* @param form The control's form that can run constraint validation.
|
|
136
|
+
* @param onControlValid A listener that is called when the form runs constraint
|
|
137
|
+
* validation and the control is valid.
|
|
138
|
+
* @param cleanup A cleanup signal to remove the listener.
|
|
139
|
+
*/
|
|
140
|
+
function addFormReportValidListener(control, form, onControlValid, cleanup) {
|
|
141
|
+
const validateHooks = getFormValidateHooks(form);
|
|
142
|
+
// When a form validates its controls, check if an invalid event is dispatched
|
|
143
|
+
// on the control. If it is not, then inform the control to report its valid
|
|
144
|
+
// state.
|
|
145
|
+
let controlFiredInvalid = false;
|
|
146
|
+
let cleanupInvalidListener;
|
|
147
|
+
let isNextSubmitFromHook = false;
|
|
148
|
+
validateHooks.addEventListener('before', () => {
|
|
149
|
+
isNextSubmitFromHook = true;
|
|
150
|
+
cleanupInvalidListener = new AbortController();
|
|
151
|
+
controlFiredInvalid = false;
|
|
152
|
+
control.addEventListener('invalid', () => {
|
|
153
|
+
controlFiredInvalid = true;
|
|
154
|
+
}, {
|
|
155
|
+
signal: cleanupInvalidListener.signal,
|
|
156
|
+
});
|
|
157
|
+
}, { signal: cleanup });
|
|
158
|
+
validateHooks.addEventListener('after', () => {
|
|
159
|
+
isNextSubmitFromHook = false;
|
|
160
|
+
cleanupInvalidListener?.abort();
|
|
161
|
+
if (controlFiredInvalid) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
onControlValid();
|
|
165
|
+
}, { signal: cleanup });
|
|
166
|
+
// The above hooks handle imperatively submitting the form, but not
|
|
167
|
+
// declaratively submitting the form. This happens when:
|
|
168
|
+
// 1. A non-custom element `<button type="submit">` is clicked.
|
|
169
|
+
// 2. Enter is pressed on a non-custom element text editable `<input>`.
|
|
170
|
+
form.addEventListener('submit', () => {
|
|
171
|
+
// This submit was from `form.requestSubmit()`, which already calls the
|
|
172
|
+
// listener.
|
|
173
|
+
if (isNextSubmitFromHook) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
onControlValid();
|
|
177
|
+
}, {
|
|
178
|
+
signal: cleanup,
|
|
179
|
+
});
|
|
180
|
+
// Note: it is a known limitation that we cannot detect if a form tries to
|
|
181
|
+
// submit declaratively, but fails to do so because an unrelated sibling
|
|
182
|
+
// control failed its constraint validation.
|
|
183
|
+
//
|
|
184
|
+
// Since we cannot detect when that happens, a previously invalid control may
|
|
185
|
+
// not clear its error styling when it becomes valid again.
|
|
186
|
+
//
|
|
187
|
+
// To work around this, call `form.reportValidity()` when submitting a form
|
|
188
|
+
// declaratively. This can be down on the `<button type="submit">`'s click or
|
|
189
|
+
// the text editable `<input>`'s 'Enter' keydown.
|
|
190
|
+
}
|
|
191
|
+
const FORM_VALIDATE_HOOKS = new WeakMap();
|
|
192
|
+
/**
|
|
193
|
+
* Get a hooks `EventTarget` that dispatches 'before' and 'after' events that
|
|
194
|
+
* fire before a form runs constraint validation and immediately after it
|
|
195
|
+
* finishes running constraint validation on its controls.
|
|
196
|
+
*
|
|
197
|
+
* This happens during `form.reportValidity()` and `form.requestSubmit()`.
|
|
198
|
+
*
|
|
199
|
+
* @param form The form to get or set up hooks for.
|
|
200
|
+
* @return A hooks `EventTarget` to add listeners to.
|
|
201
|
+
*/
|
|
202
|
+
function getFormValidateHooks(form) {
|
|
203
|
+
if (!FORM_VALIDATE_HOOKS.has(form)) {
|
|
204
|
+
// Patch form methods to add event listener hooks. These are needed to react
|
|
205
|
+
// to form behaviors that do not dispatch events, such as a form asking its
|
|
206
|
+
// controls to report their validity.
|
|
207
|
+
//
|
|
208
|
+
// We should only patch the methods once, since multiple controls and other
|
|
209
|
+
// forces may want to patch this method. We cannot reliably clean it up if
|
|
210
|
+
// there are multiple patched and re-patched methods referring holding
|
|
211
|
+
// references to each other.
|
|
212
|
+
//
|
|
213
|
+
// Instead, we never clean up the patch but add and clean up event listeners
|
|
214
|
+
// added to the hooks after the patch.
|
|
171
215
|
const hooks = new EventTarget();
|
|
172
|
-
|
|
173
|
-
form
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
216
|
+
FORM_VALIDATE_HOOKS.set(form, hooks);
|
|
217
|
+
// Add hooks to support notifying before and after a form has run constraint
|
|
218
|
+
// validation on its controls.
|
|
219
|
+
// Note: `form.submit()` does not run constraint validation per spec.
|
|
220
|
+
for (const methodName of ['reportValidity', 'requestSubmit']) {
|
|
221
|
+
const superMethod = form[methodName];
|
|
222
|
+
form[methodName] = function () {
|
|
223
|
+
hooks.dispatchEvent(new Event('before'));
|
|
224
|
+
const result = Reflect.apply(superMethod, this, arguments);
|
|
225
|
+
hooks.dispatchEvent(new Event('after'));
|
|
226
|
+
return result;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
180
229
|
}
|
|
181
|
-
|
|
182
|
-
hooks.addEventListener('before', beforeReportValidity, { signal: cleanup });
|
|
183
|
-
hooks.addEventListener('after', afterReportValidity, { signal: cleanup });
|
|
230
|
+
return FORM_VALIDATE_HOOKS.get(form);
|
|
184
231
|
}
|
|
185
232
|
//# sourceMappingURL=on-report-validity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"on-report-validity.js","sourceRoot":"","sources":["on-report-validity.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAa,QAAQ,EAAC,MAAM,KAAK,CAAC;AAmCzC;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAE3D,uDAAuD;AACvD,MAAM,2BAA2B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;AAC1E,MAAM,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,qBAAqB,CAEnC,IAAO;;IACP,MAAe,uBACb,SAAQ,IAAI;QAcZ,uDAAuD;QACvD,kCAAkC;QAClC,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAdjB;;eAEG;YACH,QAA6B,GAAG,IAAI,eAAe,EAAE,CAAC;YAEtD;;;eAGG;YACH,QAA2B,GAAG,KAAK,CAAC;YAMlC,IAAI,QAAQ,EAAE;gBACZ,OAAO;aACR;YAED,IAAI,CAAC,gBAAgB,CACnB,SAAS,EACT,CAAC,YAAY,EAAE,EAAE;gBACf,sEAAsE;gBACtE,sEAAsE;gBACtE,mEAAmE;gBACnE,+DAA+D;gBAC/D,WAAW;gBACX,IAAI,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE;oBAC9D,OAAO;iBACR;gBAED,IAAI,CAAC,gBAAgB,CACnB,SAAS,EACT,GAAG,EAAE;oBACH,gEAAgE;oBAChE,gEAAgE;oBAChE,kBAAkB;oBAClB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IAAI,EACJ,oBAAoB,EACpB,mBAAmB,EACnB,OAAO,GAMR;IACC,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACzC,yEAAyE;QACzE,mCAAmC;QACnC,2EAA2E;QAC3E,0EAA0E;QAC1E,wEAAwE;QACxE,YAAY;QACZ,2EAA2E;QAC3E,2BAA2B;QAC3B,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC;QAChC,MAAM,mBAAmB,GAAG,IAAI,CAAC,cAAc,CAAC;QAChD,IAAI,CAAC,cAAc,GAAG;YACpB,KAAK,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;YACzC,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7C,KAAK,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YACxC,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;QAEF,0BAA0B,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;KAC7C;IAED,MAAM,KAAK,GAAG,0BAA0B,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;IACpD,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC,CAAC;IAC1E,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,EAAE,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {LitElement, isServer} 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');\nconst privateDoNotReportInvalid = Symbol('privateDoNotReportInvalid');\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 /**\n * Used to determine if an invalid event should report validity. Invalid\n * events from `checkValidity()` do not trigger reporting.\n */\n [privateDoNotReportInvalid] = false;\n\n // Mixins must have a constructor with `...args: any[]`\n // tslint:disable-next-line:no-any\n constructor(...args: any[]) {\n super(...args);\n if (isServer) {\n return;\n }\n\n this.addEventListener(\n 'invalid',\n (invalidEvent) => {\n // Listen for invalid events dispatched by a `<form>` when it tries to\n // submit and the element is invalid. We ignore events dispatched when\n // calling `checkValidity()` as well as untrusted events, since the\n // `reportValidity()` and `<form>`-dispatched events are always\n // trusted.\n if (this[privateDoNotReportInvalid] || !invalidEvent.isTrusted) {\n return;\n }\n\n this.addEventListener(\n 'invalid',\n () => {\n // A normal bubbling phase event listener. By adding it here, we\n // ensure it's the last event listener that is called during the\n // bubbling phase.\n if (!invalidEvent.defaultPrevented) {\n this[onReportValidity](invalidEvent);\n }\n },\n {once: true},\n );\n },\n {\n // Listen during the capture phase, which will happen before the\n // bubbling phase. That way, we can add a final event listener that\n // will run after other event listeners, and we can check if it was\n // default prevented. This works because invalid does not bubble.\n capture: true,\n },\n );\n }\n\n override checkValidity() {\n this[privateDoNotReportInvalid] = true;\n const valid = super.checkValidity();\n this[privateDoNotReportInvalid] = false;\n return valid;\n }\n\n override reportValidity() {\n const valid = super.reportValidity();\n // Constructor's invalid listener will handle reporting invalid events.\n if (valid) {\n this[onReportValidity](null);\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"]}
|
|
1
|
+
{"version":3,"file":"on-report-validity.js","sourceRoot":"","sources":["on-report-validity.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAa,QAAQ,EAAC,MAAM,KAAK,CAAC;AAmCzC;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAE3D,uDAAuD;AACvD,MAAM,2BAA2B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;AAC1E,MAAM,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,qBAAqB,CAEnC,IAAO;;IACP,MAAe,uBACb,SAAQ,IAAI;QAcZ,uDAAuD;QACvD,kCAAkC;QAClC,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAdjB;;eAEG;YACH,QAA6B,GAAG,IAAI,eAAe,EAAE,CAAC;YAEtD;;;eAGG;YACH,QAA2B,GAAG,KAAK,CAAC;YAMlC,IAAI,QAAQ,EAAE;gBACZ,OAAO;aACR;YAED,IAAI,CAAC,gBAAgB,CACnB,SAAS,EACT,CAAC,YAAY,EAAE,EAAE;gBACf,sEAAsE;gBACtE,sEAAsE;gBACtE,mEAAmE;gBACnE,+DAA+D;gBAC/D,WAAW;gBACX,IAAI,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE;oBAC9D,OAAO;iBACR;gBAED,IAAI,CAAC,gBAAgB,CACnB,SAAS,EACT,GAAG,EAAE;oBACH,gEAAgE;oBAChE,gEAAgE;oBAChE,kBAAkB;oBAClB,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE;wBAClC,IAAI,CAAC,gBAAgB,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,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;AACxC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {LitElement, isServer} 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');\nconst privateDoNotReportInvalid = Symbol('privateDoNotReportInvalid');\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 /**\n * Used to determine if an invalid event should report validity. Invalid\n * events from `checkValidity()` do not trigger reporting.\n */\n [privateDoNotReportInvalid] = false;\n\n // Mixins must have a constructor with `...args: any[]`\n // tslint:disable-next-line:no-any\n constructor(...args: any[]) {\n super(...args);\n if (isServer) {\n return;\n }\n\n this.addEventListener(\n 'invalid',\n (invalidEvent) => {\n // Listen for invalid events dispatched by a `<form>` when it tries to\n // submit and the element is invalid. We ignore events dispatched when\n // calling `checkValidity()` as well as untrusted events, since the\n // `reportValidity()` and `<form>`-dispatched events are always\n // trusted.\n if (this[privateDoNotReportInvalid] || !invalidEvent.isTrusted) {\n return;\n }\n\n this.addEventListener(\n 'invalid',\n () => {\n // A normal bubbling phase event listener. By adding it here, we\n // ensure it's the last event listener that is called during the\n // bubbling phase.\n if (!invalidEvent.defaultPrevented) {\n this[onReportValidity](invalidEvent);\n }\n },\n {once: true},\n );\n },\n {\n // Listen during the capture phase, which will happen before the\n // bubbling phase. That way, we can add a final event listener that\n // will run after other event listeners, and we can check if it was\n // default prevented. This works because invalid does not bubble.\n capture: true,\n },\n );\n }\n\n override checkValidity() {\n this[privateDoNotReportInvalid] = true;\n const valid = super.checkValidity();\n this[privateDoNotReportInvalid] = false;\n return valid;\n }\n\n override reportValidity() {\n const valid = super.reportValidity();\n // Constructor's invalid listener will handle reporting invalid events.\n if (valid) {\n this[onReportValidity](null);\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 form listeners.\n this[privateCleanupFormListeners].abort();\n if (!form) {\n return;\n }\n\n this[privateCleanupFormListeners] = new AbortController();\n\n // Add a listener that fires when the form runs constraint validation and\n // the control is valid, so that it may remove its error styles.\n //\n // This happens on `form.reportValidity()` and `form.requestSubmit()`\n // (both when the submit fails and passes).\n addFormReportValidListener(\n this,\n form,\n () => {\n this[onReportValidity](null);\n },\n this[privateCleanupFormListeners].signal,\n );\n }\n }\n\n return OnReportValidityElement;\n}\n\n/**\n * Add a listener that fires when a form runs constraint validation on a control\n * and it is valid. This is needed to clear previously invalid styles.\n *\n * @param control The control of the form to listen for valid events.\n * @param form The control's form that can run constraint validation.\n * @param onControlValid A listener that is called when the form runs constraint\n * validation and the control is valid.\n * @param cleanup A cleanup signal to remove the listener.\n */\nfunction addFormReportValidListener(\n control: Element,\n form: HTMLFormElement,\n onControlValid: () => void,\n cleanup: AbortSignal,\n) {\n const validateHooks = getFormValidateHooks(form);\n\n // When a form validates its controls, check if an invalid event is dispatched\n // on the control. If it is not, then inform the control to report its valid\n // state.\n let controlFiredInvalid = false;\n let cleanupInvalidListener: AbortController | undefined;\n let isNextSubmitFromHook = false;\n validateHooks.addEventListener(\n 'before',\n () => {\n isNextSubmitFromHook = true;\n cleanupInvalidListener = new AbortController();\n controlFiredInvalid = false;\n control.addEventListener(\n 'invalid',\n () => {\n controlFiredInvalid = true;\n },\n {\n signal: cleanupInvalidListener.signal,\n },\n );\n },\n {signal: cleanup},\n );\n\n validateHooks.addEventListener(\n 'after',\n () => {\n isNextSubmitFromHook = false;\n cleanupInvalidListener?.abort();\n if (controlFiredInvalid) {\n return;\n }\n\n onControlValid();\n },\n {signal: cleanup},\n );\n\n // The above hooks handle imperatively submitting the form, but not\n // declaratively submitting the form. This happens when:\n // 1. A non-custom element `<button type=\"submit\">` is clicked.\n // 2. Enter is pressed on a non-custom element text editable `<input>`.\n form.addEventListener(\n 'submit',\n () => {\n // This submit was from `form.requestSubmit()`, which already calls the\n // listener.\n if (isNextSubmitFromHook) {\n return;\n }\n\n onControlValid();\n },\n {\n signal: cleanup,\n },\n );\n\n // Note: it is a known limitation that we cannot detect if a form tries to\n // submit declaratively, but fails to do so because an unrelated sibling\n // control failed its constraint validation.\n //\n // Since we cannot detect when that happens, a previously invalid control may\n // not clear its error styling when it becomes valid again.\n //\n // To work around this, call `form.reportValidity()` when submitting a form\n // declaratively. This can be down on the `<button type=\"submit\">`'s click or\n // the text editable `<input>`'s 'Enter' keydown.\n}\n\nconst FORM_VALIDATE_HOOKS = new WeakMap<HTMLFormElement, EventTarget>();\n\n/**\n * Get a hooks `EventTarget` that dispatches 'before' and 'after' events that\n * fire before a form runs constraint validation and immediately after it\n * finishes running constraint validation on its controls.\n *\n * This happens during `form.reportValidity()` and `form.requestSubmit()`.\n *\n * @param form The form to get or set up hooks for.\n * @return A hooks `EventTarget` to add listeners to.\n */\nfunction getFormValidateHooks(form: HTMLFormElement) {\n if (!FORM_VALIDATE_HOOKS.has(form)) {\n // Patch form methods to add event listener hooks. These are needed to react\n // to form behaviors that do not dispatch events, such as a form asking its\n // controls to report their validity.\n //\n // We should only patch the methods once, since multiple controls and other\n // forces may want to patch this method. We cannot reliably clean it up if\n // there are multiple patched and re-patched methods referring holding\n // references to each other.\n //\n // Instead, we never clean up the patch but add and clean up event listeners\n // added to the hooks after the patch.\n const hooks = new EventTarget();\n FORM_VALIDATE_HOOKS.set(form, hooks);\n\n // Add hooks to support notifying before and after a form has run constraint\n // validation on its controls.\n // Note: `form.submit()` does not run constraint validation per spec.\n for (const methodName of ['reportValidity', 'requestSubmit'] as const) {\n const superMethod = form[methodName];\n form[methodName] = function (this: HTMLFormElement) {\n hooks.dispatchEvent(new Event('before'));\n const result = Reflect.apply(superMethod, this, arguments);\n hooks.dispatchEvent(new Event('after'));\n return result;\n };\n }\n }\n\n return FORM_VALIDATE_HOOKS.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,IAAI,EAAE,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;SACrC;IACH,CAAC;CACF;AAhY2C;IAAzC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;wCAAkB;AAiB1C;IAAhB,KAAK,EAAE;uCAAyB;AAChB;IAAhB,KAAK,EAAE;uCAAyB;AAEG;IAAnC,KAAK,CAAC,UAAU,CAAC;sCAA8C","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {html, isServer, LitElement, PropertyValues} from 'lit';\nimport {property, query, state} from 'lit/decorators.js';\nimport {classMap} from 'lit/directives/class-map.js';\n\nimport {\n Attachable,\n AttachableController,\n} from '../../internal/controller/attachable-controller.js';\nimport {EASING} from '../../internal/motion/animation.js';\n\nconst PRESS_GROW_MS = 450;\nconst MINIMUM_PRESS_MS = 225;\nconst INITIAL_ORIGIN_SCALE = 0.2;\nconst PADDING = 10;\nconst SOFT_EDGE_MINIMUM_SIZE = 75;\nconst SOFT_EDGE_CONTAINER_RATIO = 0.35;\nconst PRESS_PSEUDO = '::after';\nconst ANIMATION_FILL = 'forwards';\n\n/**\n * Interaction states for the ripple.\n *\n * On Touch:\n * - `INACTIVE -> TOUCH_DELAY -> WAITING_FOR_CLICK -> INACTIVE`\n * - `INACTIVE -> TOUCH_DELAY -> HOLDING -> WAITING_FOR_CLICK -> INACTIVE`\n *\n * On Mouse or Pen:\n * - `INACTIVE -> WAITING_FOR_CLICK -> INACTIVE`\n */\nenum State {\n /**\n * Initial state of the control, no touch in progress.\n *\n * Transitions:\n * - on touch down: transition to `TOUCH_DELAY`.\n * - on mouse down: transition to `WAITING_FOR_CLICK`.\n */\n INACTIVE,\n /**\n * Touch down has been received, waiting to determine if it's a swipe or\n * scroll.\n *\n * Transitions:\n * - on touch up: begin press; transition to `WAITING_FOR_CLICK`.\n * - on cancel: transition to `INACTIVE`.\n * - after `TOUCH_DELAY_MS`: begin press; transition to `HOLDING`.\n */\n TOUCH_DELAY,\n /**\n * A touch has been deemed to be a press\n *\n * Transitions:\n * - on up: transition to `WAITING_FOR_CLICK`.\n */\n HOLDING,\n /**\n * The user touch has finished, transition into rest state.\n *\n * Transitions:\n * - on click end press; transition to `INACTIVE`.\n */\n WAITING_FOR_CLICK,\n}\n\n/**\n * Events that the ripple listens to.\n */\nconst EVENTS = [\n 'click',\n 'contextmenu',\n 'pointercancel',\n 'pointerdown',\n 'pointerenter',\n 'pointerleave',\n 'pointerup',\n];\n\n/**\n * Delay reacting to touch so that we do not show the ripple for a swipe or\n * scroll interaction.\n */\nconst TOUCH_DELAY_MS = 150;\n\n/**\n * Used to detect if HCM is active. Events do not process during HCM when the\n * ripple is not displayed.\n */\nconst FORCED_COLORS = isServer\n ? null\n : window.matchMedia('(forced-colors: active)');\n\n/**\n * A ripple component.\n */\nexport class Ripple extends LitElement implements Attachable {\n /**\n * Disables the ripple.\n */\n @property({type: Boolean, reflect: true}) disabled = false;\n\n get htmlFor() {\n return this.attachableController.htmlFor;\n }\n\n set htmlFor(htmlFor: string | null) {\n this.attachableController.htmlFor = htmlFor;\n }\n\n get control() {\n return this.attachableController.control;\n }\n set control(control: HTMLElement | null) {\n this.attachableController.control = control;\n }\n\n @state() private hovered = false;\n @state() private pressed = false;\n\n @query('.surface') private readonly mdRoot!: HTMLElement | null;\n private rippleSize = '';\n private rippleScale = '';\n private initialSize = 0;\n private growAnimation?: Animation;\n private state = State.INACTIVE;\n private rippleStartEvent?: PointerEvent;\n private checkBoundsAfterContextMenu = false;\n private readonly attachableController = new AttachableController(\n this,\n this.onControlChange.bind(this),\n );\n\n attach(control: HTMLElement) {\n this.attachableController.attach(control);\n }\n\n detach() {\n this.attachableController.detach();\n }\n\n override connectedCallback() {\n super.connectedCallback();\n // Needed for VoiceOver, which will create a \"group\" if the element is a\n // sibling to other content.\n this.setAttribute('aria-hidden', 'true');\n }\n\n protected override render() {\n const classes = {\n 'hovered': this.hovered,\n 'pressed': this.pressed,\n };\n\n return html`<div class=\"surface ${classMap(classes)}\"></div>`;\n }\n\n protected override update(changedProps: PropertyValues<Ripple>) {\n if (changedProps.has('disabled') && this.disabled) {\n this.hovered = false;\n this.pressed = false;\n }\n super.update(changedProps);\n }\n\n /**\n * TODO(b/269799771): make private\n * @private only public for slider\n */\n handlePointerenter(event: PointerEvent) {\n if (!this.shouldReactToEvent(event)) {\n return;\n }\n\n this.hovered = true;\n }\n\n /**\n * TODO(b/269799771): make private\n * @private only public for slider\n */\n handlePointerleave(event: PointerEvent) {\n if (!this.shouldReactToEvent(event)) {\n return;\n }\n\n this.hovered = false;\n\n // release a held mouse or pen press that moves outside the element\n if (this.state !== State.INACTIVE) {\n this.endPressAnimation();\n }\n }\n\n private handlePointerup(event: PointerEvent) {\n if (!this.shouldReactToEvent(event)) {\n return;\n }\n\n if (this.state === State.HOLDING) {\n this.state = State.WAITING_FOR_CLICK;\n return;\n }\n\n if (this.state === State.TOUCH_DELAY) {\n this.state = State.WAITING_FOR_CLICK;\n this.startPressAnimation(this.rippleStartEvent);\n return;\n }\n }\n\n private async handlePointerdown(event: PointerEvent) {\n if (!this.shouldReactToEvent(event)) {\n return;\n }\n\n this.rippleStartEvent = event;\n if (!this.isTouch(event)) {\n this.state = State.WAITING_FOR_CLICK;\n this.startPressAnimation(event);\n return;\n }\n\n // after a longpress contextmenu event, an extra `pointerdown` can be\n // dispatched to the pressed element. Check that the down is within\n // bounds of the element in this case.\n if (this.checkBoundsAfterContextMenu && !this.inBounds(event)) {\n return;\n }\n\n this.checkBoundsAfterContextMenu = false;\n\n // Wait for a hold after touch delay\n this.state = State.TOUCH_DELAY;\n await new Promise((resolve) => {\n setTimeout(resolve, TOUCH_DELAY_MS);\n });\n\n if (this.state !== State.TOUCH_DELAY) {\n return;\n }\n\n this.state = State.HOLDING;\n this.startPressAnimation(event);\n }\n\n private handleClick() {\n // Click is a MouseEvent in Firefox and Safari, so we cannot use\n // `shouldReactToEvent`\n if (this.disabled) {\n return;\n }\n\n if (this.state === State.WAITING_FOR_CLICK) {\n this.endPressAnimation();\n return;\n }\n\n if (this.state === State.INACTIVE) {\n // keyboard synthesized click event\n this.startPressAnimation();\n this.endPressAnimation();\n }\n }\n\n private handlePointercancel(event: PointerEvent) {\n if (!this.shouldReactToEvent(event)) {\n return;\n }\n\n this.endPressAnimation();\n }\n\n private handleContextmenu() {\n if (this.disabled) {\n return;\n }\n\n this.checkBoundsAfterContextMenu = true;\n this.endPressAnimation();\n }\n\n private determineRippleSize() {\n const {height, width} = this.getBoundingClientRect();\n const maxDim = Math.max(height, width);\n const softEdgeSize = Math.max(\n SOFT_EDGE_CONTAINER_RATIO * maxDim,\n SOFT_EDGE_MINIMUM_SIZE,\n );\n\n const initialSize = Math.floor(maxDim * INITIAL_ORIGIN_SCALE);\n const hypotenuse = Math.sqrt(width ** 2 + height ** 2);\n const maxRadius = hypotenuse + PADDING;\n\n this.initialSize = initialSize;\n this.rippleScale = `${(maxRadius + softEdgeSize) / initialSize}`;\n this.rippleSize = `${initialSize}px`;\n }\n\n private getNormalizedPointerEventCoords(pointerEvent: PointerEvent): {\n x: number;\n y: number;\n } {\n const {scrollX, scrollY} = window;\n const {left, top} = this.getBoundingClientRect();\n const documentX = scrollX + left;\n const documentY = scrollY + top;\n const {pageX, pageY} = pointerEvent;\n return {x: pageX - documentX, y: pageY - documentY};\n }\n\n private getTranslationCoordinates(positionEvent?: Event) {\n const {height, width} = this.getBoundingClientRect();\n // end in the center\n const endPoint = {\n x: (width - this.initialSize) / 2,\n y: (height - this.initialSize) / 2,\n };\n\n let startPoint;\n if (positionEvent instanceof PointerEvent) {\n startPoint = this.getNormalizedPointerEventCoords(positionEvent);\n } else {\n startPoint = {\n x: width / 2,\n y: height / 2,\n };\n }\n\n // center around start point\n startPoint = {\n x: startPoint.x - this.initialSize / 2,\n y: startPoint.y - this.initialSize / 2,\n };\n\n return {startPoint, endPoint};\n }\n\n private startPressAnimation(positionEvent?: Event) {\n if (!this.mdRoot) {\n return;\n }\n\n this.pressed = true;\n this.growAnimation?.cancel();\n this.determineRippleSize();\n const {startPoint, endPoint} =\n this.getTranslationCoordinates(positionEvent);\n const translateStart = `${startPoint.x}px, ${startPoint.y}px`;\n const translateEnd = `${endPoint.x}px, ${endPoint.y}px`;\n\n this.growAnimation = this.mdRoot.animate(\n {\n top: [0, 0],\n left: [0, 0],\n height: [this.rippleSize, this.rippleSize],\n width: [this.rippleSize, this.rippleSize],\n transform: [\n `translate(${translateStart}) scale(1)`,\n `translate(${translateEnd}) scale(${this.rippleScale})`,\n ],\n },\n {\n pseudoElement: PRESS_PSEUDO,\n duration: PRESS_GROW_MS,\n easing: EASING.STANDARD,\n fill: ANIMATION_FILL,\n },\n );\n }\n\n private async endPressAnimation() {\n this.state = State.INACTIVE;\n const animation = this.growAnimation;\n let pressAnimationPlayState = Infinity;\n if (typeof animation?.currentTime === 'number') {\n pressAnimationPlayState = animation.currentTime;\n } else if (animation?.currentTime) {\n pressAnimationPlayState = animation.currentTime.to('ms').value;\n }\n\n if (pressAnimationPlayState >= MINIMUM_PRESS_MS) {\n this.pressed = false;\n return;\n }\n\n await new Promise((resolve) => {\n setTimeout(resolve, MINIMUM_PRESS_MS - pressAnimationPlayState);\n });\n\n if (this.growAnimation !== animation) {\n // A new press animation was started. The old animation was canceled and\n // should not finish the pressed state.\n return;\n }\n\n this.pressed = false;\n }\n\n /**\n * Returns `true` if\n * - the ripple element is enabled\n * - the pointer is primary for the input type\n * - the pointer is the pointer that started the interaction, or will start\n * the interaction\n * - the pointer is a touch, or the pointer state has the primary button\n * held, or the pointer is hovering\n */\n private shouldReactToEvent(event: PointerEvent) {\n if (this.disabled || !event.isPrimary) {\n return false;\n }\n\n if (\n this.rippleStartEvent &&\n this.rippleStartEvent.pointerId !== event.pointerId\n ) {\n return false;\n }\n\n if (event.type === 'pointerenter' || event.type === 'pointerleave') {\n return !this.isTouch(event);\n }\n\n const isPrimaryButton = event.buttons === 1;\n return this.isTouch(event) || isPrimaryButton;\n }\n\n /**\n * Check if the event is within the bounds of the element.\n *\n * This is only needed for the \"stuck\" contextmenu longpress on Chrome.\n */\n private inBounds({x, y}: PointerEvent) {\n const {top, left, bottom, right} = this.getBoundingClientRect();\n return x >= left && x <= right && y >= top && y <= bottom;\n }\n\n private isTouch({pointerType}: PointerEvent) {\n return pointerType === 'touch';\n }\n\n /** @private */\n async handleEvent(event: Event) {\n if (FORCED_COLORS?.matches) {\n // Skip event logic since the ripple is `display: none`.\n return;\n }\n\n switch (event.type) {\n case 'click':\n this.handleClick();\n break;\n case 'contextmenu':\n this.handleContextmenu();\n break;\n case 'pointercancel':\n this.handlePointercancel(event as PointerEvent);\n break;\n case 'pointerdown':\n await this.handlePointerdown(event as PointerEvent);\n break;\n case 'pointerenter':\n this.handlePointerenter(event as PointerEvent);\n break;\n case 'pointerleave':\n this.handlePointerleave(event as PointerEvent);\n break;\n case 'pointerup':\n this.handlePointerup(event as PointerEvent);\n break;\n default:\n break;\n }\n }\n\n private onControlChange(prev: HTMLElement | null, next: HTMLElement | null) {\n if (isServer) return;\n\n for (const event of EVENTS) {\n prev?.removeEventListener(event, this);\n next?.addEventListener(event, this);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ripple.js","sourceRoot":"","sources":["ripple.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAEH,OAAO,EAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAiB,MAAM,KAAK,CAAC;AAC/D,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAC,QAAQ,EAAC,MAAM,6BAA6B,CAAC;AAErD,OAAO,EAEL,oBAAoB,GACrB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAC,MAAM,EAAC,MAAM,oCAAoC,CAAC;AAE1D,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,gBAAgB,GAAG,GAAG,C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O;gBACV,IAAI,CAAC,WAAW,EAAE,CAAC;gBACnB,MAAM;YACR,KAAK,aAAa;gBAChB,IAAI,CAAC,iBAAiB,EAAE,CAAC;gBACzB,MAAM;YACR,KAAK,eAAe;gBAClB,IAAI,CAAC,mBAAmB,CAAC,KAAqB,CAAC,CAAC;gBAChD,MAAM;YACR,KAAK,aAAa;gBAChB,MAAM,IAAI,CAAC,iBAAiB,CAAC,KAAqB,CAAC,CAAC;gBACpD,MAAM;YACR,KAAK,cAAc;gBACjB,IAAI,CAAC,kBAAkB,CAAC,KAAqB,CAAC,CAAC;gBAC/C,MAAM;YACR,KAAK,cAAc;gBACjB,IAAI,CAAC,kBAAkB,CAAC,KAAqB,CAAC,CAAC;gBAC/C,MAAM;YACR,KAAK,WAAW;gBACd,IAAI,CAAC,eAAe,CAAC,KAAqB,CAAC,CAAC;gBAC5C,MAAM;YACR;gBACE,MAAM;SACT;IACH,CAAC;IAEO,eAAe,CAAC,IAAwB,EAAE,IAAwB;QACxE,IAAI,QAAQ;YAAE,OAAO;QAErB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,IAAI,EAAE,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YACvC,IAAI,EAAE,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;SACrC;IACH,CAAC;CACF;AAjY2C;IAAzC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;wCAAkB;AAiB1C;IAAhB,KAAK,EAAE;uCAAyB;AAChB;IAAhB,KAAK,EAAE;uCAAyB;AAEG;IAAnC,KAAK,CAAC,UAAU,CAAC;sCAA8C","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {html, isServer, LitElement, PropertyValues} from 'lit';\nimport {property, query, state} from 'lit/decorators.js';\nimport {classMap} from 'lit/directives/class-map.js';\n\nimport {\n Attachable,\n AttachableController,\n} from '../../internal/controller/attachable-controller.js';\nimport {EASING} from '../../internal/motion/animation.js';\n\nconst PRESS_GROW_MS = 450;\nconst MINIMUM_PRESS_MS = 225;\nconst INITIAL_ORIGIN_SCALE = 0.2;\nconst PADDING = 10;\nconst SOFT_EDGE_MINIMUM_SIZE = 75;\nconst SOFT_EDGE_CONTAINER_RATIO = 0.35;\nconst PRESS_PSEUDO = '::after';\nconst ANIMATION_FILL = 'forwards';\n\n/**\n * Interaction states for the ripple.\n *\n * On Touch:\n * - `INACTIVE -> TOUCH_DELAY -> WAITING_FOR_CLICK -> INACTIVE`\n * - `INACTIVE -> TOUCH_DELAY -> HOLDING -> WAITING_FOR_CLICK -> INACTIVE`\n *\n * On Mouse or Pen:\n * - `INACTIVE -> WAITING_FOR_CLICK -> INACTIVE`\n */\nenum State {\n /**\n * Initial state of the control, no touch in progress.\n *\n * Transitions:\n * - on touch down: transition to `TOUCH_DELAY`.\n * - on mouse down: transition to `WAITING_FOR_CLICK`.\n */\n INACTIVE,\n /**\n * Touch down has been received, waiting to determine if it's a swipe or\n * scroll.\n *\n * Transitions:\n * - on touch up: begin press; transition to `WAITING_FOR_CLICK`.\n * - on cancel: transition to `INACTIVE`.\n * - after `TOUCH_DELAY_MS`: begin press; transition to `HOLDING`.\n */\n TOUCH_DELAY,\n /**\n * A touch has been deemed to be a press\n *\n * Transitions:\n * - on up: transition to `WAITING_FOR_CLICK`.\n */\n HOLDING,\n /**\n * The user touch has finished, transition into rest state.\n *\n * Transitions:\n * - on click end press; transition to `INACTIVE`.\n */\n WAITING_FOR_CLICK,\n}\n\n/**\n * Events that the ripple listens to.\n */\nconst EVENTS = [\n 'click',\n 'contextmenu',\n 'pointercancel',\n 'pointerdown',\n 'pointerenter',\n 'pointerleave',\n 'pointerup',\n];\n\n/**\n * Delay reacting to touch so that we do not show the ripple for a swipe or\n * scroll interaction.\n */\nconst TOUCH_DELAY_MS = 150;\n\n/**\n * Used to detect if HCM is active. Events do not process during HCM when the\n * ripple is not displayed.\n */\nconst FORCED_COLORS = isServer\n ? null\n : window.matchMedia('(forced-colors: active)');\n\n/**\n * A ripple component.\n */\nexport class Ripple extends LitElement implements Attachable {\n /**\n * Disables the ripple.\n */\n @property({type: Boolean, reflect: true}) disabled = false;\n\n get htmlFor() {\n return this.attachableController.htmlFor;\n }\n\n set htmlFor(htmlFor: string | null) {\n this.attachableController.htmlFor = htmlFor;\n }\n\n get control() {\n return this.attachableController.control;\n }\n set control(control: HTMLElement | null) {\n this.attachableController.control = control;\n }\n\n @state() private hovered = false;\n @state() private pressed = false;\n\n @query('.surface') private readonly mdRoot!: HTMLElement | null;\n private rippleSize = '';\n private rippleScale = '';\n private initialSize = 0;\n private growAnimation?: Animation;\n private state = State.INACTIVE;\n private rippleStartEvent?: PointerEvent;\n private checkBoundsAfterContextMenu = false;\n private readonly attachableController = new AttachableController(\n this,\n this.onControlChange.bind(this),\n );\n\n attach(control: HTMLElement) {\n this.attachableController.attach(control);\n }\n\n detach() {\n this.attachableController.detach();\n }\n\n override connectedCallback() {\n super.connectedCallback();\n // Needed for VoiceOver, which will create a \"group\" if the element is a\n // sibling to other content.\n this.setAttribute('aria-hidden', 'true');\n }\n\n protected override render() {\n const classes = {\n 'hovered': this.hovered,\n 'pressed': this.pressed,\n };\n\n return html`<div class=\"surface ${classMap(classes)}\"></div>`;\n }\n\n protected override update(changedProps: PropertyValues<Ripple>) {\n if (changedProps.has('disabled') && this.disabled) {\n this.hovered = false;\n this.pressed = false;\n }\n super.update(changedProps);\n }\n\n /**\n * TODO(b/269799771): make private\n * @private only public for slider\n */\n handlePointerenter(event: PointerEvent) {\n if (!this.shouldReactToEvent(event)) {\n return;\n }\n\n this.hovered = true;\n }\n\n /**\n * TODO(b/269799771): make private\n * @private only public for slider\n */\n handlePointerleave(event: PointerEvent) {\n if (!this.shouldReactToEvent(event)) {\n return;\n }\n\n this.hovered = false;\n\n // release a held mouse or pen press that moves outside the element\n if (this.state !== State.INACTIVE) {\n this.endPressAnimation();\n }\n }\n\n private handlePointerup(event: PointerEvent) {\n if (!this.shouldReactToEvent(event)) {\n return;\n }\n\n if (this.state === State.HOLDING) {\n this.state = State.WAITING_FOR_CLICK;\n return;\n }\n\n if (this.state === State.TOUCH_DELAY) {\n this.state = State.WAITING_FOR_CLICK;\n this.startPressAnimation(this.rippleStartEvent);\n return;\n }\n }\n\n private async handlePointerdown(event: PointerEvent) {\n if (!this.shouldReactToEvent(event)) {\n return;\n }\n\n this.rippleStartEvent = event;\n if (!this.isTouch(event)) {\n this.state = State.WAITING_FOR_CLICK;\n this.startPressAnimation(event);\n return;\n }\n\n // after a longpress contextmenu event, an extra `pointerdown` can be\n // dispatched to the pressed element. Check that the down is within\n // bounds of the element in this case.\n if (this.checkBoundsAfterContextMenu && !this.inBounds(event)) {\n return;\n }\n\n this.checkBoundsAfterContextMenu = false;\n\n // Wait for a hold after touch delay\n this.state = State.TOUCH_DELAY;\n await new Promise((resolve) => {\n setTimeout(resolve, TOUCH_DELAY_MS);\n });\n\n if (this.state !== State.TOUCH_DELAY) {\n return;\n }\n\n this.state = State.HOLDING;\n this.startPressAnimation(event);\n }\n\n private handleClick() {\n // Click is a MouseEvent in Firefox and Safari, so we cannot use\n // `shouldReactToEvent`\n if (this.disabled) {\n return;\n }\n\n if (this.state === State.WAITING_FOR_CLICK) {\n this.endPressAnimation();\n return;\n }\n\n if (this.state === State.INACTIVE) {\n // keyboard synthesized click event\n this.startPressAnimation();\n this.endPressAnimation();\n }\n }\n\n private handlePointercancel(event: PointerEvent) {\n if (!this.shouldReactToEvent(event)) {\n return;\n }\n\n this.endPressAnimation();\n }\n\n private handleContextmenu() {\n if (this.disabled) {\n return;\n }\n\n this.checkBoundsAfterContextMenu = true;\n this.endPressAnimation();\n }\n\n private determineRippleSize() {\n const {height, width} = this.getBoundingClientRect();\n const maxDim = Math.max(height, width);\n const softEdgeSize = Math.max(\n SOFT_EDGE_CONTAINER_RATIO * maxDim,\n SOFT_EDGE_MINIMUM_SIZE,\n );\n\n const initialSize = Math.floor(maxDim * INITIAL_ORIGIN_SCALE);\n const hypotenuse = Math.sqrt(width ** 2 + height ** 2);\n const maxRadius = hypotenuse + PADDING;\n\n this.initialSize = initialSize;\n this.rippleScale = `${(maxRadius + softEdgeSize) / initialSize}`;\n this.rippleSize = `${initialSize}px`;\n }\n\n private getNormalizedPointerEventCoords(pointerEvent: PointerEvent): {\n x: number;\n y: number;\n } {\n const {scrollX, scrollY} = window;\n const {left, top} = this.getBoundingClientRect();\n const documentX = scrollX + left;\n const documentY = scrollY + top;\n const {pageX, pageY} = pointerEvent;\n return {x: pageX - documentX, y: pageY - documentY};\n }\n\n private getTranslationCoordinates(positionEvent?: Event) {\n const {height, width} = this.getBoundingClientRect();\n // end in the center\n const endPoint = {\n x: (width - this.initialSize) / 2,\n y: (height - this.initialSize) / 2,\n };\n\n let startPoint;\n if (positionEvent instanceof PointerEvent) {\n startPoint = this.getNormalizedPointerEventCoords(positionEvent);\n } else {\n startPoint = {\n x: width / 2,\n y: height / 2,\n };\n }\n\n // center around start point\n startPoint = {\n x: startPoint.x - this.initialSize / 2,\n y: startPoint.y - this.initialSize / 2,\n };\n\n return {startPoint, endPoint};\n }\n\n private startPressAnimation(positionEvent?: Event) {\n if (!this.mdRoot) {\n return;\n }\n\n this.pressed = true;\n this.growAnimation?.cancel();\n this.determineRippleSize();\n const {startPoint, endPoint} =\n this.getTranslationCoordinates(positionEvent);\n const translateStart = `${startPoint.x}px, ${startPoint.y}px`;\n const translateEnd = `${endPoint.x}px, ${endPoint.y}px`;\n\n this.growAnimation = this.mdRoot.animate(\n {\n top: [0, 0],\n left: [0, 0],\n height: [this.rippleSize, this.rippleSize],\n width: [this.rippleSize, this.rippleSize],\n transform: [\n `translate(${translateStart}) scale(1)`,\n `translate(${translateEnd}) scale(${this.rippleScale})`,\n ],\n },\n {\n pseudoElement: PRESS_PSEUDO,\n duration: PRESS_GROW_MS,\n easing: EASING.STANDARD,\n fill: ANIMATION_FILL,\n },\n );\n }\n\n private async endPressAnimation() {\n this.rippleStartEvent = undefined;\n this.state = State.INACTIVE;\n const animation = this.growAnimation;\n let pressAnimationPlayState = Infinity;\n if (typeof animation?.currentTime === 'number') {\n pressAnimationPlayState = animation.currentTime;\n } else if (animation?.currentTime) {\n pressAnimationPlayState = animation.currentTime.to('ms').value;\n }\n\n if (pressAnimationPlayState >= MINIMUM_PRESS_MS) {\n this.pressed = false;\n return;\n }\n\n await new Promise((resolve) => {\n setTimeout(resolve, MINIMUM_PRESS_MS - pressAnimationPlayState);\n });\n\n if (this.growAnimation !== animation) {\n // A new press animation was started. The old animation was canceled and\n // should not finish the pressed state.\n return;\n }\n\n this.pressed = false;\n }\n\n /**\n * Returns `true` if\n * - the ripple element is enabled\n * - the pointer is primary for the input type\n * - the pointer is the pointer that started the interaction, or will start\n * the interaction\n * - the pointer is a touch, or the pointer state has the primary button\n * held, or the pointer is hovering\n */\n private shouldReactToEvent(event: PointerEvent) {\n if (this.disabled || !event.isPrimary) {\n return false;\n }\n\n if (\n this.rippleStartEvent &&\n this.rippleStartEvent.pointerId !== event.pointerId\n ) {\n return false;\n }\n\n if (event.type === 'pointerenter' || event.type === 'pointerleave') {\n return !this.isTouch(event);\n }\n\n const isPrimaryButton = event.buttons === 1;\n return this.isTouch(event) || isPrimaryButton;\n }\n\n /**\n * Check if the event is within the bounds of the element.\n *\n * This is only needed for the \"stuck\" contextmenu longpress on Chrome.\n */\n private inBounds({x, y}: PointerEvent) {\n const {top, left, bottom, right} = this.getBoundingClientRect();\n return x >= left && x <= right && y >= top && y <= bottom;\n }\n\n private isTouch({pointerType}: PointerEvent) {\n return pointerType === 'touch';\n }\n\n /** @private */\n async handleEvent(event: Event) {\n if (FORCED_COLORS?.matches) {\n // Skip event logic since the ripple is `display: none`.\n return;\n }\n\n switch (event.type) {\n case 'click':\n this.handleClick();\n break;\n case 'contextmenu':\n this.handleContextmenu();\n break;\n case 'pointercancel':\n this.handlePointercancel(event as PointerEvent);\n break;\n case 'pointerdown':\n await this.handlePointerdown(event as PointerEvent);\n break;\n case 'pointerenter':\n this.handlePointerenter(event as PointerEvent);\n break;\n case 'pointerleave':\n this.handlePointerleave(event as PointerEvent);\n break;\n case 'pointerup':\n this.handlePointerup(event as PointerEvent);\n break;\n default:\n break;\n }\n }\n\n private onControlChange(prev: HTMLElement | null, next: HTMLElement | null) {\n if (isServer) return;\n\n for (const event of EVENTS) {\n prev?.removeEventListener(event, this);\n next?.addEventListener(event, this);\n }\n }\n}\n"]}
|
package/select/harness.d.ts
CHANGED
package/select/harness.js
CHANGED
|
@@ -40,6 +40,13 @@ export class SelectHarness extends Harness {
|
|
|
40
40
|
}
|
|
41
41
|
(await this.getItems()[index].getInteractiveElement()).click();
|
|
42
42
|
}
|
|
43
|
+
get isOpen() {
|
|
44
|
+
const menu = this.element.renderRoot.querySelector('md-menu');
|
|
45
|
+
if (!menu) {
|
|
46
|
+
throw new Error('Internal md-menu is not found. md-select may not have finished rendering when isOpen has been checked');
|
|
47
|
+
}
|
|
48
|
+
return menu.open;
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
// Private class (not exported)
|
|
45
52
|
class SelectFieldHardness extends FieldHarness {
|
package/select/harness.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harness.js","sourceRoot":"","sources":["harness.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAC,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAG9C,OAAO,EAAC,mBAAmB,EAAC,MAAM,oCAAoC,CAAC;AAEvE;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,OAAe;IACtC,QAAQ;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAU,CAAC;IAClE,CAAC;IACD;;OAEG;IACgB,KAAK,CAAC,qBAAqB;QAC5C,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC;QAClC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAEQ,KAAK,CAAC,UAAU;QACvB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,MAAM,IAAI,mBAAmB,CAC3C,KAAK,CACN,CAAC,qBAAqB,EAAE,CAAC;QAC1B,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,uDAAuD;IACvD,QAAQ;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAC7B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,mBAAmB,CAAC,IAAgC,CAAC,CACpE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpC,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAAa;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,SAAS,CAAE,CAAC;QAC/D,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACd,OAAO,CAAC,IAAI,CACV,wEAAwE,CACzE,CAAC;SACH;QACD,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,qBAAqB,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IACjE,CAAC;CACF;AAED,+BAA+B;AAC/B,MAAM,mBAAoB,SAAQ,YAAY;IAC5C,4EAA4E;IACnE,qBAAqB;QAC5B,OAAO,KAAK,CAAC,qBAAqB,EAAE,CAAC;IACvC,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {LitElement} from 'lit';\n\nimport {FieldHarness} from '../field/harness.js';\nimport {Field} from '../field/internal/field.js';\nimport {Harness} from '../testing/harness.js';\n\nimport {Select} from './internal/select.js';\nimport {SelectOptionHarness} from './internal/selectoption/harness.js';\n\n/**\n * Test harness for menu.\n */\nexport class SelectHarness extends Harness<Select> {\n protected getField() {\n return this.element.renderRoot.querySelector('.field') as Field;\n }\n /**\n * Shows the menu and returns the first list item element.\n */\n protected override async getInteractiveElement() {\n await this.element.updateComplete;\n return this.getField();\n }\n\n override async startHover() {\n const field = await this.getField();\n const element = await new SelectFieldHardness(\n field,\n ).getInteractiveElement();\n this.simulateStartHover(element);\n }\n\n /** @return ListItem harnesses for the menu's items. */\n getItems() {\n return this.element.options.map(\n (item) => new SelectOptionHarness(item as typeof item & LitElement),\n );\n }\n\n async click() {\n const field = await this.getField();\n field.click();\n }\n\n async clickOption(index: number) {\n const menu = this.element.renderRoot.querySelector('md-menu')!;\n if (!menu.open) {\n console.warn(\n 'Internal menu is not open. Try calling SelectHarness.prototype.click()',\n );\n }\n (await this.getItems()[index].getInteractiveElement()).click();\n }\n}\n\n// Private class (not exported)\nclass SelectFieldHardness extends FieldHarness {\n /* Expose so that we can call it from our internal code in SelectHarness. */\n override getInteractiveElement() {\n return super.getInteractiveElement();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"harness.js","sourceRoot":"","sources":["harness.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAC,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAG9C,OAAO,EAAC,mBAAmB,EAAC,MAAM,oCAAoC,CAAC;AAEvE;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,OAAe;IACtC,QAAQ;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAU,CAAC;IAClE,CAAC;IACD;;OAEG;IACgB,KAAK,CAAC,qBAAqB;QAC5C,MAAM,IAAI,CAAC,OAA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M,mBAAoB,SAAQ,YAAY;IAC5C,4EAA4E;IACnE,qBAAqB;QAC5B,OAAO,KAAK,CAAC,qBAAqB,EAAE,CAAC;IACvC,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {LitElement} from 'lit';\n\nimport {FieldHarness} from '../field/harness.js';\nimport {Field} from '../field/internal/field.js';\nimport {Harness} from '../testing/harness.js';\n\nimport {Select} from './internal/select.js';\nimport {SelectOptionHarness} from './internal/selectoption/harness.js';\n\n/**\n * Test harness for menu.\n */\nexport class SelectHarness extends Harness<Select> {\n protected getField() {\n return this.element.renderRoot.querySelector('.field') as Field;\n }\n /**\n * Shows the menu and returns the first list item element.\n */\n protected override async getInteractiveElement() {\n await this.element.updateComplete;\n return this.getField();\n }\n\n override async startHover() {\n const field = await this.getField();\n const element = await new SelectFieldHardness(\n field,\n ).getInteractiveElement();\n this.simulateStartHover(element);\n }\n\n /** @return ListItem harnesses for the menu's items. */\n getItems() {\n return this.element.options.map(\n (item) => new SelectOptionHarness(item as typeof item & LitElement),\n );\n }\n\n async click() {\n const field = await this.getField();\n field.click();\n }\n\n async clickOption(index: number) {\n const menu = this.element.renderRoot.querySelector('md-menu')!;\n if (!menu.open) {\n console.warn(\n 'Internal menu is not open. Try calling SelectHarness.prototype.click()',\n );\n }\n (await this.getItems()[index].getInteractiveElement()).click();\n }\n\n get isOpen() {\n const menu = this.element.renderRoot.querySelector('md-menu')!;\n if (!menu) {\n throw new Error(\n 'Internal md-menu is not found. md-select may not have finished rendering when isOpen has been checked',\n );\n }\n return menu.open;\n }\n}\n\n// Private class (not exported)\nclass SelectFieldHardness extends FieldHarness {\n /* Expose so that we can call it from our internal code in SelectHarness. */\n override getInteractiveElement() {\n return super.getInteractiveElement();\n }\n}\n"]}
|
|
@@ -300,7 +300,7 @@ export class Select extends selectBaseClass {
|
|
|
300
300
|
tabindex=${this.disabled ? '-1' : '0'}
|
|
301
301
|
aria-label=${this.ariaLabel || nothing}
|
|
302
302
|
aria-describedby="description"
|
|
303
|
-
aria-expanded=${this.open ? 'true' :
|
|
303
|
+
aria-expanded=${this.open ? 'true' : 'false'}
|
|
304
304
|
aria-controls="listbox"
|
|
305
305
|
class="field"
|
|
306
306
|
label=${this.label}
|
|
@@ -455,7 +455,7 @@ export class Select extends selectBaseClass {
|
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
457
|
handleClick() {
|
|
458
|
-
this.open =
|
|
458
|
+
this.open = !this.open;
|
|
459
459
|
}
|
|
460
460
|
handleFocus() {
|
|
461
461
|
this.focused = true;
|
|
@@ -586,7 +586,8 @@ export class Select extends selectBaseClass {
|
|
|
586
586
|
* @return Whether the last selected option has changed.
|
|
587
587
|
*/
|
|
588
588
|
selectItem(item) {
|
|
589
|
-
this.
|
|
589
|
+
const selectedOptions = this.getSelectedOptions() ?? [];
|
|
590
|
+
selectedOptions.forEach(([option]) => {
|
|
590
591
|
if (item !== option) {
|
|
591
592
|
option.selected = false;
|
|
592
593
|
}
|