@m3e/form-field 1.0.0-rc.1 → 1.0.0-rc.2
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/README.md +1 -2
- package/dist/custom-elements.json +2573 -7
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +68 -68
- package/dist/index.min.js.map +1 -1
- package/package.json +3 -3
- package/cem.config.mjs +0 -16
- package/demo/index.html +0 -116
- package/dist/src/FloatLabelType.d.ts +0 -3
- package/dist/src/FloatLabelType.d.ts.map +0 -1
- package/dist/src/FormFieldControl.d.ts +0 -48
- package/dist/src/FormFieldControl.d.ts.map +0 -1
- package/dist/src/FormFieldElement.d.ts +0 -144
- package/dist/src/FormFieldElement.d.ts.map +0 -1
- package/dist/src/FormFieldVariant.d.ts +0 -3
- package/dist/src/FormFieldVariant.d.ts.map +0 -1
- package/dist/src/HideSubscriptType.d.ts +0 -3
- package/dist/src/HideSubscriptType.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.d.ts.map +0 -1
- package/eslint.config.mjs +0 -13
- package/rollup.config.js +0 -32
- package/src/FloatLabelType.ts +0 -2
- package/src/FormFieldControl.ts +0 -83
- package/src/FormFieldElement.ts +0 -876
- package/src/FormFieldVariant.ts +0 -2
- package/src/HideSubscriptType.ts +0 -2
- package/src/index.ts +0 -5
- package/tsconfig.json +0 -9
package/src/FormFieldElement.ts
DELETED
|
@@ -1,876 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapted from Angular Material Form Field
|
|
3
|
-
* Source: https://github.com/angular/components/blob/main/src/material/form-field/form-field.ts
|
|
4
|
-
*
|
|
5
|
-
* @license MIT
|
|
6
|
-
* Copyright (c) 2025 Google LLC
|
|
7
|
-
* See LICENSE file in the project root for full license text.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { css, CSSResultGroup, html, LitElement, nothing, PropertyValues, unsafeCSS } from "lit";
|
|
11
|
-
import { customElement, property, query, state } from "lit/decorators.js";
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
AttachInternals,
|
|
15
|
-
DesignToken,
|
|
16
|
-
FocusController,
|
|
17
|
-
getTextContent,
|
|
18
|
-
hasAssignedNodes,
|
|
19
|
-
HoverController,
|
|
20
|
-
isReadOnlyMixin,
|
|
21
|
-
MutationController,
|
|
22
|
-
PressedController,
|
|
23
|
-
ResizeController,
|
|
24
|
-
Role,
|
|
25
|
-
} from "@m3e/core";
|
|
26
|
-
|
|
27
|
-
import { M3eAriaDescriber } from "@m3e/core/a11y";
|
|
28
|
-
|
|
29
|
-
import { findFormFieldControl, FormFieldControl } from "./FormFieldControl";
|
|
30
|
-
import { FormFieldVariant } from "./FormFieldVariant";
|
|
31
|
-
import { HideSubscriptType } from "./HideSubscriptType";
|
|
32
|
-
import { FloatLabelType } from "./FloatLabelType";
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @summary
|
|
36
|
-
* A container for form controls that applies Material Design styling and behavior.
|
|
37
|
-
*
|
|
38
|
-
* @description
|
|
39
|
-
* The `m3e-form-field` component is a semantic, expressive container for form controls that anchors
|
|
40
|
-
* label behavior, subscript messaging, and variant-specific layout. Designed according to Material Design 3
|
|
41
|
-
* guidelines, it supports two visual variants—`outlined` and `filled`—each with dynamic elevation,
|
|
42
|
-
* shape transitions, and adaptive color theming. The component responds to control state changes
|
|
43
|
-
* (focus, hover, press, disabled, invalid) with smooth motion and semantic clarity, ensuring
|
|
44
|
-
* visual hierarchy and emotional resonance.
|
|
45
|
-
|
|
46
|
-
* The component is accessible by default, with ARIA annotations, contrast-safe color tokens,
|
|
47
|
-
* and dynamic descriptions for hint and error messaging. It supports prefix and suffix content,
|
|
48
|
-
* floating labels, and adaptive subscript visibility. When hosting a control with validation,
|
|
49
|
-
* error messages are surfaced with `aria-invalid` and described for assistive technology.
|
|
50
|
-
|
|
51
|
-
* Native form controls may not expose full state or messaging on their own. `m3e-form-field` bridges
|
|
52
|
-
* these gaps by coordinating label floating, container styling, and subscript feedback.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* The following example illustrates a basic usage of the `m3e-form-field`.
|
|
56
|
-
* ```html
|
|
57
|
-
* <m3e-form-field>
|
|
58
|
-
* <label slot="label" for="field">Text field</label>
|
|
59
|
-
* <input id="field" />
|
|
60
|
-
* </m3e-form-field>
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* @tag m3e-form-field
|
|
64
|
-
*
|
|
65
|
-
* @slot - Renders the control of the field.
|
|
66
|
-
* @slot prefix - Renders content before the fields's control.
|
|
67
|
-
* @slot prefix-text - Renders text before the fields's control.
|
|
68
|
-
* @slot suffix - Renders content after the fields's control.
|
|
69
|
-
* @slot suffix-text - Renders text after the fields's control.
|
|
70
|
-
* @slot hint - Renders hint text in the fields's subscript, when the control is valid.
|
|
71
|
-
* @slot error - Renders error text in the fields's subscript, when the control is invalid.
|
|
72
|
-
*
|
|
73
|
-
* @attr float-label - Specifies whether the label should float always or only when necessary.
|
|
74
|
-
* @attr hide-required-marker - Whether the required marker should be hidden.
|
|
75
|
-
* @attr hide-subscript - Whether subscript content is hidden.
|
|
76
|
-
* @attr variant - The appearance variant of the field.
|
|
77
|
-
*
|
|
78
|
-
* @cssprop --m3e-form-field-font-size - Font size for the form field container text.
|
|
79
|
-
* @cssprop --m3e-form-field-font-weight - Font weight for the form field container text.
|
|
80
|
-
* @cssprop --m3e-form-field-line-height - Line height for the form field container text.
|
|
81
|
-
* @cssprop --m3e-form-field-tracking - Letter spacing for the form field container text.
|
|
82
|
-
* @cssprop --m3e-form-field-label-font-size - Font size for the floating label.
|
|
83
|
-
* @cssprop --m3e-form-field-label-font-weight - Font weight for the floating label.
|
|
84
|
-
* @cssprop --m3e-form-field-label-line-height - Line height for the floating label.
|
|
85
|
-
* @cssprop --m3e-form-field-label-tracking - Letter spacing for the floating label.
|
|
86
|
-
* @cssprop --m3e-form-field-subscript-font-size - Font size for hint and error text.
|
|
87
|
-
* @cssprop --m3e-form-field-subscript-font-weight - Font weight for hint and error text.
|
|
88
|
-
* @cssprop --m3e-form-field-subscript-line-height - Line height for hint and error text.
|
|
89
|
-
* @cssprop --m3e-form-field-subscript-tracking - Letter spacing for hint and error text.
|
|
90
|
-
* @cssprop --m3e-form-field-color - Text color for the form field container.
|
|
91
|
-
* @cssprop --m3e-form-field-subscript-color - Color for hint and error text.
|
|
92
|
-
* @cssprop --m3e-form-field-invalid-color - Color used when the control is invalid.
|
|
93
|
-
* @cssprop --m3e-form-field-focused-outline-color - Outline color when focused.
|
|
94
|
-
* @cssprop --m3e-form-field-focused-color - Label color when focused.
|
|
95
|
-
* @cssprop --m3e-form-field-outline-color - Outline color in outlined variant.
|
|
96
|
-
* @cssprop --m3e-form-field-container-color - Background color in filled variant.
|
|
97
|
-
* @cssprop --m3e-form-field-hover-container-color - Hover background color in filled variant.
|
|
98
|
-
* @cssprop --m3e-form-field-width - Width of the form field container.
|
|
99
|
-
* @cssprop --m3e-form-field-icon-size - Size of prefix and suffix icons.
|
|
100
|
-
* @cssprop --m3e-outlined-form-field-container-shape - Corner radius for outlined container.
|
|
101
|
-
* @cssprop --m3e-form-field-container-shape - Corner radius for filled container.
|
|
102
|
-
* @cssprop --m3e-form-field-hover-container-opacity - Opacity for hover background in filled variant.
|
|
103
|
-
* @cssprop --m3e-form-field-disabled-opacity - Opacity for disabled text.
|
|
104
|
-
* @cssprop --m3e-form-field-disabled-container-opacity - Opacity for disabled container background.
|
|
105
|
-
*/
|
|
106
|
-
@customElement("m3e-form-field")
|
|
107
|
-
export class M3eFormFieldElement extends AttachInternals(Role(LitElement, "none")) {
|
|
108
|
-
/** The styles of the element. */
|
|
109
|
-
static override styles: CSSResultGroup = css`
|
|
110
|
-
:host {
|
|
111
|
-
display: inline-flex;
|
|
112
|
-
flex-direction: column;
|
|
113
|
-
vertical-align: middle;
|
|
114
|
-
font-size: var(--m3e-form-field-font-size, ${DesignToken.typescale.standard.body.large.fontSize});
|
|
115
|
-
font-weight: var(--m3e-form-field-font-weight, ${DesignToken.typescale.standard.body.large.fontWeight});
|
|
116
|
-
line-height: var(--m3e-form-field-line-height, ${DesignToken.typescale.standard.body.large.lineHeight});
|
|
117
|
-
letter-spacing: var(--m3e-form-field-tracking, ${DesignToken.typescale.standard.body.large.tracking});
|
|
118
|
-
width: var(--m3e-form-field-width, 14.5rem);
|
|
119
|
-
color: var(--_form-field-color);
|
|
120
|
-
}
|
|
121
|
-
.base {
|
|
122
|
-
display: flex;
|
|
123
|
-
align-items: center;
|
|
124
|
-
position: relative;
|
|
125
|
-
min-height: calc(3.5rem + ${DesignToken.density.calc(-2)});
|
|
126
|
-
--_form-field-label-font-size: var(
|
|
127
|
-
--m3e-form-field-label-font-size,
|
|
128
|
-
${DesignToken.typescale.standard.body.small.fontSize}
|
|
129
|
-
);
|
|
130
|
-
--_form-field-label-line-height: var(
|
|
131
|
-
--m3e-form-field-label-line-height,
|
|
132
|
-
${DesignToken.typescale.standard.body.small.lineHeight}
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
.content {
|
|
136
|
-
display: flex;
|
|
137
|
-
align-items: center;
|
|
138
|
-
position: relative;
|
|
139
|
-
flex: 1 1 auto;
|
|
140
|
-
min-width: 0;
|
|
141
|
-
min-height: var(--m3e-form-field-icon-size, 1.5rem);
|
|
142
|
-
}
|
|
143
|
-
.prefix,
|
|
144
|
-
.suffix {
|
|
145
|
-
display: flex;
|
|
146
|
-
align-items: center;
|
|
147
|
-
position: relative;
|
|
148
|
-
user-select: none;
|
|
149
|
-
flex: none;
|
|
150
|
-
font-size: var(--m3e-form-field-icon-size, 1.5rem);
|
|
151
|
-
}
|
|
152
|
-
.prefix-text,
|
|
153
|
-
.suffix-text {
|
|
154
|
-
opacity: 1;
|
|
155
|
-
transition: opacity ${DesignToken.motion.duration.extraLong1};
|
|
156
|
-
user-select: none;
|
|
157
|
-
flex: none;
|
|
158
|
-
}
|
|
159
|
-
.input {
|
|
160
|
-
display: inline-flex;
|
|
161
|
-
flex-wrap: wrap;
|
|
162
|
-
flex: 1 1 auto;
|
|
163
|
-
min-width: 0;
|
|
164
|
-
}
|
|
165
|
-
.label {
|
|
166
|
-
display: flex;
|
|
167
|
-
position: absolute;
|
|
168
|
-
pointer-events: none;
|
|
169
|
-
user-select: none;
|
|
170
|
-
top: 0;
|
|
171
|
-
left: 0;
|
|
172
|
-
right: 0;
|
|
173
|
-
font-size: var(--m3e-form-field-label-font-size, ${DesignToken.typescale.standard.body.small.fontSize});
|
|
174
|
-
font-weight: var(--m3e-form-field-label-font-weight, ${DesignToken.typescale.standard.body.small.fontWeight});
|
|
175
|
-
line-height: var(--m3e-form-field-label-line-height, ${DesignToken.typescale.standard.body.small.lineHeight});
|
|
176
|
-
letter-spacing: var(--m3e-form-field-label-tracking, ${DesignToken.typescale.standard.body.small.tracking});
|
|
177
|
-
color: var(--_form-field-label-color, inherit);
|
|
178
|
-
transition: ${unsafeCSS(
|
|
179
|
-
`top ${DesignToken.motion.duration.short4},
|
|
180
|
-
font-size ${DesignToken.motion.duration.short4},
|
|
181
|
-
line-height ${DesignToken.motion.duration.short4}`
|
|
182
|
-
)};
|
|
183
|
-
}
|
|
184
|
-
:host(.-with-select) .label {
|
|
185
|
-
margin-right: 1.5rem;
|
|
186
|
-
}
|
|
187
|
-
::slotted([slot="label"]) {
|
|
188
|
-
white-space: nowrap;
|
|
189
|
-
overflow: hidden;
|
|
190
|
-
text-overflow: ellipsis;
|
|
191
|
-
}
|
|
192
|
-
.subscript {
|
|
193
|
-
display: inline-flex;
|
|
194
|
-
width: 100%;
|
|
195
|
-
margin-top: 0.25rem;
|
|
196
|
-
font-size: var(--m3e-form-field-subscript-font-size, ${DesignToken.typescale.standard.body.small.fontSize});
|
|
197
|
-
font-weight: var(--m3e-form-field-subscript-font-weight, ${DesignToken.typescale.standard.body.small.fontWeight});
|
|
198
|
-
line-height: var(--m3e-form-field-subscript-line-height, ${DesignToken.typescale.standard.body.small.lineHeight});
|
|
199
|
-
letter-spacing: var(--m3e-form-field-subscript-tracking, ${DesignToken.typescale.standard.body.small.tracking});
|
|
200
|
-
min-height: var(--m3e-form-field-subscript-line-height, ${DesignToken.typescale.standard.body.small.lineHeight});
|
|
201
|
-
color: var(--m3e-form-field-subscript-color, ${DesignToken.color.onSurfaceVariant});
|
|
202
|
-
}
|
|
203
|
-
.error,
|
|
204
|
-
.hint {
|
|
205
|
-
flex: 1 1 auto;
|
|
206
|
-
}
|
|
207
|
-
:host([hide-subscript="always"]) .subscript {
|
|
208
|
-
display: none;
|
|
209
|
-
}
|
|
210
|
-
:host([hide-subscript="auto"]:not(.-invalid)) .subscript {
|
|
211
|
-
opacity: 0;
|
|
212
|
-
margin-top: 0px;
|
|
213
|
-
margin-bottom: 0.25rem;
|
|
214
|
-
transition: ${unsafeCSS(
|
|
215
|
-
`opacity ${DesignToken.motion.duration.short4},
|
|
216
|
-
margin-top ${DesignToken.motion.duration.short4},
|
|
217
|
-
margin-bottom ${DesignToken.motion.duration.short4}`
|
|
218
|
-
)};
|
|
219
|
-
}
|
|
220
|
-
:host([hide-subscript="auto"]:not(.-invalid):focus-within) .subscript,
|
|
221
|
-
:host([hide-subscript="auto"]:not(.-invalid).-pressed) .subscript {
|
|
222
|
-
opacity: 1;
|
|
223
|
-
margin-top: 0.25rem;
|
|
224
|
-
margin-bottom: 0;
|
|
225
|
-
}
|
|
226
|
-
:host(.-invalid) .hint {
|
|
227
|
-
display: none;
|
|
228
|
-
}
|
|
229
|
-
:host(:not(.-invalid)) .error {
|
|
230
|
-
display: none;
|
|
231
|
-
}
|
|
232
|
-
::slotted(input),
|
|
233
|
-
::slotted(textarea),
|
|
234
|
-
::slotted(select) {
|
|
235
|
-
outline: unset;
|
|
236
|
-
border: unset;
|
|
237
|
-
background-color: transparent;
|
|
238
|
-
box-shadow: none;
|
|
239
|
-
font-family: inherit;
|
|
240
|
-
font-size: inherit;
|
|
241
|
-
line-height: initial;
|
|
242
|
-
letter-spacing: inherit;
|
|
243
|
-
color: var(--_form-field-input-color, inherit);
|
|
244
|
-
flex: 1 1 auto;
|
|
245
|
-
min-width: 0;
|
|
246
|
-
padding: unset;
|
|
247
|
-
}
|
|
248
|
-
::slotted(textarea) {
|
|
249
|
-
scrollbar-width: ${DesignToken.scrollbar.thinWidth};
|
|
250
|
-
scrollbar-color: ${DesignToken.scrollbar.color};
|
|
251
|
-
}
|
|
252
|
-
::slotted(m3e-select),
|
|
253
|
-
::slotted(m3e-input-chip-set) {
|
|
254
|
-
flex: 1 1 auto;
|
|
255
|
-
min-width: 0;
|
|
256
|
-
}
|
|
257
|
-
:host([variant="outlined"]) ::slotted(m3e-input-chip-set) {
|
|
258
|
-
margin-block: calc(calc(3.5rem + ${DesignToken.density.calc(-2)}) / 4);
|
|
259
|
-
}
|
|
260
|
-
::slotted(:not([slot])::part(focus-ring)) {
|
|
261
|
-
display: none;
|
|
262
|
-
}
|
|
263
|
-
::slotted(input)::placeholder,
|
|
264
|
-
::slotted(textarea)::placeholder {
|
|
265
|
-
user-select: none;
|
|
266
|
-
color: currentColor;
|
|
267
|
-
transition: opacity ${DesignToken.motion.duration.extraLong1};
|
|
268
|
-
}
|
|
269
|
-
:host([float-label="auto"]:not(.-float-label):not(.-pressed)) .label {
|
|
270
|
-
font-size: inherit;
|
|
271
|
-
}
|
|
272
|
-
:host([float-label="auto"]:not(.-float-label).-with-label) ::slotted(input)::placeholder,
|
|
273
|
-
:host([float-label="auto"]:not(.-float-label).-with-label) ::slotted(textarea)::placeholder,
|
|
274
|
-
:host([float-label="auto"]:not(.-float-label).-with-label) .prefix-text,
|
|
275
|
-
:host([float-label="auto"]:not(.-float-label).-with-label) .suffix-text {
|
|
276
|
-
opacity: 0;
|
|
277
|
-
transition: opacity 0s;
|
|
278
|
-
}
|
|
279
|
-
.prefix {
|
|
280
|
-
margin-left: 1rem;
|
|
281
|
-
}
|
|
282
|
-
:host(.-with-prefix) .prefix {
|
|
283
|
-
margin-right: 1rem;
|
|
284
|
-
margin-left: 0.75rem;
|
|
285
|
-
}
|
|
286
|
-
.suffix {
|
|
287
|
-
margin-right: 1rem;
|
|
288
|
-
}
|
|
289
|
-
:host(.-with-suffix) .suffix {
|
|
290
|
-
margin-left: 1rem;
|
|
291
|
-
margin-right: 0.75rem;
|
|
292
|
-
}
|
|
293
|
-
:host(.-with-suffix.-with-select) .suffix {
|
|
294
|
-
margin-left: unset;
|
|
295
|
-
}
|
|
296
|
-
:host(.-with-select) .suffix-text {
|
|
297
|
-
display: none;
|
|
298
|
-
}
|
|
299
|
-
:host([variant="outlined"]) .label {
|
|
300
|
-
margin-top: calc(0px - var(--_form-field-label-line-height) / 2);
|
|
301
|
-
}
|
|
302
|
-
:host([variant="outlined"]) .outline {
|
|
303
|
-
position: absolute;
|
|
304
|
-
display: flex;
|
|
305
|
-
pointer-events: none;
|
|
306
|
-
left: 0;
|
|
307
|
-
top: 0;
|
|
308
|
-
bottom: 0;
|
|
309
|
-
right: 0;
|
|
310
|
-
}
|
|
311
|
-
:host([variant="outlined"]) .pseudo-label {
|
|
312
|
-
visibility: hidden;
|
|
313
|
-
margin-right: 0.25rem;
|
|
314
|
-
font-size: var(--_form-field-label-font-size);
|
|
315
|
-
line-height: var(--_form-field-label-line-height);
|
|
316
|
-
letter-spacing: var(--_form-field-label-tracking);
|
|
317
|
-
max-width: 100%;
|
|
318
|
-
transition-property: max-width, margin-right;
|
|
319
|
-
transition-duration: 1ms;
|
|
320
|
-
}
|
|
321
|
-
:host([variant="outlined"][float-label="auto"]:not(.-float-label):not(.-pressed)) .pseudo-label {
|
|
322
|
-
max-width: 0;
|
|
323
|
-
margin-right: 0px;
|
|
324
|
-
transition-delay: ${DesignToken.motion.duration.short2};
|
|
325
|
-
}
|
|
326
|
-
:host([variant="outlined"]) .outline-start,
|
|
327
|
-
:host([variant="outlined"]) .outline-notch,
|
|
328
|
-
:host([variant="outlined"]) .outline-end {
|
|
329
|
-
box-sizing: border-box;
|
|
330
|
-
border-width: var(--_form-field-outline-size, 0.0625rem);
|
|
331
|
-
border-color: var(--_form-field-outline-color);
|
|
332
|
-
transition: border-color ${DesignToken.motion.duration.short4};
|
|
333
|
-
}
|
|
334
|
-
:host([variant="outlined"]:not(.-with-label)) .outline-notch {
|
|
335
|
-
display: none;
|
|
336
|
-
}
|
|
337
|
-
:host([variant="outlined"].-with-suffix:not(.-with-select)) .outline-notch {
|
|
338
|
-
margin-right: -0.75rem;
|
|
339
|
-
}
|
|
340
|
-
:host([variant="outlined"]) .outline-start {
|
|
341
|
-
min-width: 0.75rem;
|
|
342
|
-
border-top-style: solid;
|
|
343
|
-
border-left-style: solid;
|
|
344
|
-
border-bottom-style: solid;
|
|
345
|
-
border-radius: var(--m3e-outlined-form-field-container-shape, ${DesignToken.shape.corner.extraSmall}) 0 0
|
|
346
|
-
var(--m3e-outlined-form-field-container-shape, ${DesignToken.shape.corner.extraSmall});
|
|
347
|
-
}
|
|
348
|
-
:host([variant="outlined"]) .outline-notch {
|
|
349
|
-
border-bottom-style: solid;
|
|
350
|
-
}
|
|
351
|
-
:host([variant="outlined"]) .outline-end {
|
|
352
|
-
flex-grow: 1;
|
|
353
|
-
min-width: 1rem;
|
|
354
|
-
border-top-style: solid;
|
|
355
|
-
border-right-style: solid;
|
|
356
|
-
border-bottom-style: solid;
|
|
357
|
-
border-radius: 0 var(--m3e-outlined-form-field-container-shape, ${DesignToken.shape.corner.extraSmall})
|
|
358
|
-
var(--m3e-outlined-form-field-container-shape, ${DesignToken.shape.corner.extraSmall}) 0;
|
|
359
|
-
}
|
|
360
|
-
:host([variant="outlined"].-with-prefix) .outline-start {
|
|
361
|
-
min-width: calc(1.25rem + var(--_prefix-width, 0px) + 0.25rem);
|
|
362
|
-
}
|
|
363
|
-
:host([variant="outlined"]:not(.-disabled)) .base:hover .outline,
|
|
364
|
-
:host([variant="outlined"]:not(.-disabled):focus-within) .outline,
|
|
365
|
-
:host([variant="outlined"]:not(.-disabled).-pressed) .outline {
|
|
366
|
-
--_form-field-outline-size: 0.125rem;
|
|
367
|
-
}
|
|
368
|
-
:host([variant="outlined"]) .subscript {
|
|
369
|
-
margin-inline: 1rem;
|
|
370
|
-
width: calc(100% - 2rem);
|
|
371
|
-
}
|
|
372
|
-
:host([variant="outlined"]) .content {
|
|
373
|
-
min-height: calc(3.5rem + ${DesignToken.density.calc(-2)});
|
|
374
|
-
--_form-field-label-font-size: var(
|
|
375
|
-
--m3e-form-field-label-font-size,
|
|
376
|
-
${DesignToken.typescale.standard.body.small.fontSize}
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
:host([variant="outlined"][float-label="auto"]:not(.-float-label):not(.-pressed)) .label {
|
|
380
|
-
margin-top: unset;
|
|
381
|
-
line-height: calc(3.5rem + ${DesignToken.density.calc(-2)});
|
|
382
|
-
--_form-field-label-font-size: var(
|
|
383
|
-
--m3e-form-field-label-font-size,
|
|
384
|
-
${DesignToken.typescale.standard.body.small.fontSize}
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
:host([variant="filled"]) .base {
|
|
388
|
-
--_select-arrow-margin-top: calc(
|
|
389
|
-
0px - calc(1rem / max(calc(0 - calc(var(--m3e-density-scale, 0) + var(--m3e-density-scale, 0))), 1))
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
|
-
:host([variant="filled"]) .base::before {
|
|
393
|
-
content: "";
|
|
394
|
-
box-sizing: border-box;
|
|
395
|
-
position: absolute;
|
|
396
|
-
pointer-events: none;
|
|
397
|
-
top: 0;
|
|
398
|
-
left: 0;
|
|
399
|
-
right: 0;
|
|
400
|
-
bottom: 0;
|
|
401
|
-
border-bottom-style: solid;
|
|
402
|
-
border-width: 0.0625rem;
|
|
403
|
-
border-radius: var(--m3e-form-field-container-shape, ${DesignToken.shape.corner.extraSmallTop});
|
|
404
|
-
border-color: var(--_form-field-outline-color);
|
|
405
|
-
background-color: var(--_form-field-container-color);
|
|
406
|
-
}
|
|
407
|
-
:host([variant="filled"]:not(.-disabled)) .base:hover::before,
|
|
408
|
-
:host([variant="filled"]:not(.-disabled):focus-within) .base::before,
|
|
409
|
-
:host([variant="filled"]:not(.-disabled).-pressed) .base::before {
|
|
410
|
-
border-width: 0.1875rem;
|
|
411
|
-
}
|
|
412
|
-
:host([variant="filled"]) .base::after {
|
|
413
|
-
content: "";
|
|
414
|
-
box-sizing: border-box;
|
|
415
|
-
position: absolute;
|
|
416
|
-
pointer-events: none;
|
|
417
|
-
top: 0;
|
|
418
|
-
left: 0;
|
|
419
|
-
right: 0;
|
|
420
|
-
bottom: 0;
|
|
421
|
-
background-color: var(--_form-field-hover-container-color);
|
|
422
|
-
transition: background-color ${DesignToken.motion.duration.short4};
|
|
423
|
-
}
|
|
424
|
-
:host([variant="filled"]) .subscript {
|
|
425
|
-
margin-inline: 1rem;
|
|
426
|
-
width: calc(100% - 2rem);
|
|
427
|
-
}
|
|
428
|
-
:host([variant="filled"]) .content {
|
|
429
|
-
padding-top: calc(1.5rem + ${DesignToken.density.calc(-2)});
|
|
430
|
-
margin-bottom: 0.5rem;
|
|
431
|
-
}
|
|
432
|
-
:host([variant="filled"]) .label {
|
|
433
|
-
top: calc(0.5rem + ${DesignToken.density.calc(-2)});
|
|
434
|
-
}
|
|
435
|
-
:host([variant="filled"][float-label="auto"]:not(.-float-label):not(.-pressed)) .label {
|
|
436
|
-
top: 0px;
|
|
437
|
-
line-height: calc(3.5rem + ${DesignToken.density.calc(-2)} - 0.0625rem);
|
|
438
|
-
--_form-field-label-font-size: var(
|
|
439
|
-
--m3e-form-field-label-font-size,
|
|
440
|
-
${DesignToken.typescale.standard.body.small.fontSize}
|
|
441
|
-
);
|
|
442
|
-
}
|
|
443
|
-
:host(:not(.-disabled):not(:focus-within):not(.-pressed)) .base:hover {
|
|
444
|
-
--_form-field-hover-container-color: color-mix(
|
|
445
|
-
in srgb,
|
|
446
|
-
var(--m3e-form-field-hover-container-color, ${DesignToken.color.onSurface})
|
|
447
|
-
var(--m3e-form-field-hover-container-opacity, 8%),
|
|
448
|
-
transparent
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
:host(:not(.-disabled):not(.-invalid)) {
|
|
452
|
-
color: var(--m3e-form-field-color, ${DesignToken.color.onSurface});
|
|
453
|
-
}
|
|
454
|
-
:host([variant="outlined"]:not(.-disabled):not(.-invalid)) .base {
|
|
455
|
-
--_form-field-outline-color: var(--m3e-form-field-outline-color, ${DesignToken.color.outline});
|
|
456
|
-
}
|
|
457
|
-
:host([variant="filled"]:not(.-disabled):not(.-invalid)) .base {
|
|
458
|
-
--_form-field-outline-color: var(--m3e-form-field-outline-color, ${DesignToken.color.onSurfaceVariant});
|
|
459
|
-
}
|
|
460
|
-
:host([variant="outlined"]:not(.-disabled):not(.-invalid):focus-within) .base,
|
|
461
|
-
:host([variant="outlined"]:not(.-disabled):not(.-invalid).-pressed) .base,
|
|
462
|
-
:host([variant="filled"]:not(.-disabled):not(.-invalid):focus-within) .base,
|
|
463
|
-
:host([variant="filled"]:not(.-disabled):not(.-invalid).-pressed) .base {
|
|
464
|
-
--_form-field-outline-color: var(--m3e-form-field-focused-outline-color, ${DesignToken.color.primary});
|
|
465
|
-
--_form-field-label-color: var(--m3e-form-field-focused-color, ${DesignToken.color.primary});
|
|
466
|
-
}
|
|
467
|
-
:host(:not(.-disabled)) .base {
|
|
468
|
-
--_form-field-container-color: var(
|
|
469
|
-
--m3e-form-field-container-color,
|
|
470
|
-
${DesignToken.color.surfaceContainerHighest}
|
|
471
|
-
);
|
|
472
|
-
}
|
|
473
|
-
:host(:not(.-disabled).-invalid) .base {
|
|
474
|
-
--_form-field-label-color: var(--m3e-form-field-invalid-color, ${DesignToken.color.error});
|
|
475
|
-
--_form-field-outline-color: var(--m3e-form-field-invalid-color, ${DesignToken.color.error});
|
|
476
|
-
}
|
|
477
|
-
:host(:not(.-disabled).-invalid) .subscript {
|
|
478
|
-
color: var(--m3e-form-field-invalid-color, ${DesignToken.color.error});
|
|
479
|
-
}
|
|
480
|
-
:host(.-disabled) {
|
|
481
|
-
color: color-mix(
|
|
482
|
-
in srgb,
|
|
483
|
-
var(--m3e-form-field-disabled-color, ${DesignToken.color.onSurface}) var(--m3e-form-field-disabled-opacity, 38%),
|
|
484
|
-
transparent
|
|
485
|
-
);
|
|
486
|
-
}
|
|
487
|
-
:host(.-disabled) .base {
|
|
488
|
-
--_form-field-container-color: color-mix(
|
|
489
|
-
in srgb,
|
|
490
|
-
var(--m3e-form-field-disabled-container-color, ${DesignToken.color.onSurface})
|
|
491
|
-
var(--m3e-form-field-disabled-container-opacity, 4%),
|
|
492
|
-
transparent
|
|
493
|
-
);
|
|
494
|
-
}
|
|
495
|
-
:host(.-no-animate) *,
|
|
496
|
-
:host(.-no-animate) *::before,
|
|
497
|
-
:host(.-no-animate) *::after {
|
|
498
|
-
transition: none !important;
|
|
499
|
-
}
|
|
500
|
-
@media (forced-colors: active) {
|
|
501
|
-
:host([variant="filled"]) .base::after {
|
|
502
|
-
transition: none;
|
|
503
|
-
}
|
|
504
|
-
:host {
|
|
505
|
-
--_form-field-outline-color: CanvasText;
|
|
506
|
-
}
|
|
507
|
-
:host(.-disabled) {
|
|
508
|
-
--_form-field-input-color: GrayText;
|
|
509
|
-
--_form-field-color: GrayText;
|
|
510
|
-
--_form-field-label-color: GrayText;
|
|
511
|
-
--_form-field-outline-color: GrayText;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
@media (prefers-reduced-motion) {
|
|
515
|
-
.base::before,
|
|
516
|
-
.prefix-text,
|
|
517
|
-
.suffix-text,
|
|
518
|
-
.label,
|
|
519
|
-
.subscript,
|
|
520
|
-
.outline-start,
|
|
521
|
-
.outline-notch,
|
|
522
|
-
.outline-end,
|
|
523
|
-
.pseudo-label,
|
|
524
|
-
::slotted(input)::placeholder,
|
|
525
|
-
::slotted(textarea)::placeholder {
|
|
526
|
-
transition: none !important;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
`;
|
|
530
|
-
|
|
531
|
-
/** @private */ #control: FormFieldControl | null = null;
|
|
532
|
-
/** @private */ readonly #formResetHandler = () => this.#handleFormReset();
|
|
533
|
-
/** @private */ readonly #controlInvalidHandler = () => this.#handleControlInvalid();
|
|
534
|
-
|
|
535
|
-
/** @private */
|
|
536
|
-
readonly #controlMutationController = new MutationController(this, {
|
|
537
|
-
target: null,
|
|
538
|
-
config: { attributeFilter: ["disabled", "readonly", "required"] },
|
|
539
|
-
callback: () => this.notifyControlStateChange(),
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
/** @private */
|
|
543
|
-
readonly #resizeController = new ResizeController(this, {
|
|
544
|
-
target: null,
|
|
545
|
-
callback: () => this.#handlePrefixResize(),
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
/** @private */
|
|
549
|
-
readonly #focusController = new FocusController(this, {
|
|
550
|
-
target: null,
|
|
551
|
-
callback: (focused) => {
|
|
552
|
-
focused = focused && !(this.#control?.disabled ?? true);
|
|
553
|
-
this.classList.toggle("-no-animate", false);
|
|
554
|
-
this.#focused = focused;
|
|
555
|
-
if (focused) {
|
|
556
|
-
this.classList.toggle("-float-label", true);
|
|
557
|
-
} else {
|
|
558
|
-
this._invalid = !(this.#control?.checkValidity?.() ?? true);
|
|
559
|
-
this.notifyControlStateChange();
|
|
560
|
-
}
|
|
561
|
-
},
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
/** @private */ @query(".base") private readonly _base!: HTMLElement;
|
|
565
|
-
/** @private */ @query(".prefix") private readonly _prefix!: HTMLElement;
|
|
566
|
-
/** @private */ @query(".error") private readonly _error!: HTMLElement;
|
|
567
|
-
/** @private */ @query(".hint") private readonly _hint!: HTMLElement;
|
|
568
|
-
|
|
569
|
-
/** @private */
|
|
570
|
-
readonly #hintMutationController = new MutationController(this, {
|
|
571
|
-
target: null,
|
|
572
|
-
config: { childList: true, subtree: true },
|
|
573
|
-
callback: () => this.#handleHintChange(),
|
|
574
|
-
});
|
|
575
|
-
|
|
576
|
-
/** @private */
|
|
577
|
-
readonly #errorMutationController = new MutationController(this, {
|
|
578
|
-
target: null,
|
|
579
|
-
config: { childList: true, subtree: true },
|
|
580
|
-
callback: () => this.#handleErrorChange(),
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
/** @private */ #focused = false;
|
|
584
|
-
/** @private */ @state() private _pseudoLabel = "";
|
|
585
|
-
/** @private */ @state() private _required = false;
|
|
586
|
-
/** @private */ @state() private _invalid = false;
|
|
587
|
-
/** @private */ @state() private _validationMessage = "";
|
|
588
|
-
/** @private */ #hintText = "";
|
|
589
|
-
/** @private */ #errorText = "";
|
|
590
|
-
|
|
591
|
-
constructor() {
|
|
592
|
-
super();
|
|
593
|
-
|
|
594
|
-
new HoverController(this, { callback: () => this.classList.toggle("-no-animate", false) });
|
|
595
|
-
new PressedController(this, {
|
|
596
|
-
callback: (pressed) => this.classList.toggle("-pressed", pressed && !(this.#control?.disabled ?? true)),
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
/** @private */
|
|
601
|
-
get #shouldFloatLabel(): boolean {
|
|
602
|
-
return this.#control?.shouldLabelFloat !== undefined
|
|
603
|
-
? this.#control.shouldLabelFloat === true
|
|
604
|
-
: typeof this.#control?.value == "string" && this.#control.value.length > 0;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
/** A reference to the hosted form field control. */
|
|
608
|
-
get control() {
|
|
609
|
-
return this.#control;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
/**
|
|
613
|
-
* The appearance variant of the field.
|
|
614
|
-
* @default "outlined"
|
|
615
|
-
*/
|
|
616
|
-
@property({ reflect: true }) variant: FormFieldVariant = "outlined";
|
|
617
|
-
|
|
618
|
-
/**
|
|
619
|
-
* Whether the required marker should be hidden.
|
|
620
|
-
* @default false
|
|
621
|
-
*/
|
|
622
|
-
@property({ attribute: "hide-required-marker", type: Boolean, reflect: true }) hideRequiredMarker = false;
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* Whether subscript content is hidden.
|
|
626
|
-
* @default "auto"
|
|
627
|
-
*/
|
|
628
|
-
@property({ attribute: "hide-subscript", reflect: true }) hideSubscript: HideSubscriptType = "auto";
|
|
629
|
-
|
|
630
|
-
/**
|
|
631
|
-
* Specifies whether the label should float always or only when necessary.
|
|
632
|
-
* @default "auto"
|
|
633
|
-
*/
|
|
634
|
-
@property({ attribute: "float-label", reflect: true }) floatLabel: FloatLabelType = "auto";
|
|
635
|
-
|
|
636
|
-
/**
|
|
637
|
-
* Notifies the form field that the state of the hosted `control` has changed.
|
|
638
|
-
* @param [checkValidity=false] Whether to check validity.
|
|
639
|
-
*/
|
|
640
|
-
notifyControlStateChange(checkValidity = false): void {
|
|
641
|
-
this._required = this.#control?.required === true;
|
|
642
|
-
this.classList.toggle("-required", this._required);
|
|
643
|
-
this.classList.toggle("-disabled", this.#control?.disabled === true);
|
|
644
|
-
this.classList.toggle("-readonly", isReadOnlyMixin(this.#control) && this.#control.readOnly === true);
|
|
645
|
-
if (this.floatLabel === "auto") {
|
|
646
|
-
this.classList.toggle("-float-label", this.#shouldFloatLabel || this.#focused);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
if (checkValidity) {
|
|
650
|
-
this._invalid = !(this.#control?.checkValidity?.() ?? true);
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
this.classList.toggle("-invalid", this._invalid);
|
|
654
|
-
|
|
655
|
-
this._validationMessage = this.#control?.validationMessage ?? "";
|
|
656
|
-
if (!this.isUpdatePending) {
|
|
657
|
-
this.performUpdate();
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
/** @inheritdoc */
|
|
662
|
-
override connectedCallback(): void {
|
|
663
|
-
super.connectedCallback();
|
|
664
|
-
// Label animations are disabled on initial paint.
|
|
665
|
-
this.classList.toggle("-no-animate", true);
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
/** @inheritdoc */
|
|
669
|
-
override disconnectedCallback(): void {
|
|
670
|
-
super.disconnectedCallback();
|
|
671
|
-
this.#changeControl(null);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
/** @private */
|
|
675
|
-
protected override firstUpdated(_changedProperties: PropertyValues): void {
|
|
676
|
-
super.firstUpdated(_changedProperties);
|
|
677
|
-
|
|
678
|
-
this.#focusController.observe(this._base);
|
|
679
|
-
|
|
680
|
-
this.#hintMutationController.observe(this._hint);
|
|
681
|
-
this.#handleHintChange();
|
|
682
|
-
|
|
683
|
-
this.#errorMutationController.observe(this._error);
|
|
684
|
-
this.#handleErrorChange();
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
/** @inheritdoc */
|
|
688
|
-
protected override update(changedProperties: PropertyValues): void {
|
|
689
|
-
super.update(changedProperties);
|
|
690
|
-
|
|
691
|
-
if (changedProperties.has("_invalid") && this.#control) {
|
|
692
|
-
this.#control.ariaInvalid = this._invalid ? "true" : null;
|
|
693
|
-
|
|
694
|
-
if (this.#errorText) {
|
|
695
|
-
if (this._invalid) {
|
|
696
|
-
M3eAriaDescriber.describe(this.#control, this.#errorText);
|
|
697
|
-
} else {
|
|
698
|
-
M3eAriaDescriber.removeDescription(this.#control, this.#errorText);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
/** @inheritdoc */
|
|
705
|
-
protected override render(): unknown {
|
|
706
|
-
return html`<div class="base" @click="${this.#handleContainerClick}">
|
|
707
|
-
${this.variant === "outlined"
|
|
708
|
-
? html`<div class="outline" aria-hidden="true">
|
|
709
|
-
<div class="outline-start"></div>
|
|
710
|
-
<div class="outline-notch">
|
|
711
|
-
<div class="pseudo-label">
|
|
712
|
-
${this._pseudoLabel} ${!this.hideRequiredMarker && this._required ? html` *` : nothing}
|
|
713
|
-
</div>
|
|
714
|
-
</div>
|
|
715
|
-
<div class="outline-end"></div>
|
|
716
|
-
</div>`
|
|
717
|
-
: nothing}
|
|
718
|
-
<div class="prefix">
|
|
719
|
-
<slot name="prefix" @slotchange="${this.#handlePrefixSlotChange}"></slot>
|
|
720
|
-
</div>
|
|
721
|
-
<div class="content">
|
|
722
|
-
<span class="prefix-text"><slot name="prefix-text"></slot></span>
|
|
723
|
-
<span class="input">
|
|
724
|
-
<slot @slotchange="${this.#handleSlotChange}" @change="${this.#handleControlChange}"></slot>
|
|
725
|
-
</span>
|
|
726
|
-
<span class="suffix-text"><slot name="suffix-text"></slot></span>
|
|
727
|
-
<span class="label">
|
|
728
|
-
<slot name="label" @slotchange="${this.#handleLabelSlotChange}"></slot>
|
|
729
|
-
${!this.hideRequiredMarker && this._required
|
|
730
|
-
? html`<span class="required-marker" aria-hidden="true"> *</span>`
|
|
731
|
-
: nothing}
|
|
732
|
-
</span>
|
|
733
|
-
</div>
|
|
734
|
-
<div class="suffix" @click="${this.#stopPropagation}">
|
|
735
|
-
<slot name="suffix" @slotchange="${this.#handleSuffixSlotChange}"></slot>
|
|
736
|
-
</div>
|
|
737
|
-
</div>
|
|
738
|
-
<span class="subscript" aria-hidden="true">
|
|
739
|
-
<span class="error"><slot name="error">${this._validationMessage}</slot></span>
|
|
740
|
-
<span class="hint"><slot name="hint"></slot></span>
|
|
741
|
-
</span>`;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
/** @private */
|
|
745
|
-
#stopPropagation(e: Event): void {
|
|
746
|
-
e.stopImmediatePropagation();
|
|
747
|
-
e.stopPropagation();
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
/** @private */
|
|
751
|
-
#handleLabelSlotChange(e: Event): void {
|
|
752
|
-
const assignedElements = (<HTMLSlotElement>e.target).assignedElements({ flatten: true });
|
|
753
|
-
this.classList.toggle("-with-label", assignedElements.length > 0);
|
|
754
|
-
this._pseudoLabel = assignedElements[0]?.textContent ?? "";
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
/** @private */
|
|
758
|
-
#handlePrefixSlotChange(e: Event): void {
|
|
759
|
-
this.classList.toggle("-with-prefix", hasAssignedNodes(<HTMLSlotElement>e.target));
|
|
760
|
-
this.#resizeController.observe(this._prefix);
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
/** @private */
|
|
764
|
-
#handleSuffixSlotChange(e: Event): void {
|
|
765
|
-
this.classList.toggle("-with-suffix", hasAssignedNodes(<HTMLSlotElement>e.target));
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
/** @private */
|
|
769
|
-
#handlePrefixResize(): void {
|
|
770
|
-
if (this.variant === "outlined") {
|
|
771
|
-
this._base.style.setProperty("--_prefix-width", `${this._prefix.clientWidth}px`);
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
/** @private */
|
|
776
|
-
#handleSlotChange(e: Event): void {
|
|
777
|
-
this.#changeControl(findFormFieldControl(<HTMLSlotElement>e.target));
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
/** @private */
|
|
781
|
-
#handleContainerClick(e: MouseEvent): void {
|
|
782
|
-
if (this.#control && !this.#focused && !this.#control.disabled) {
|
|
783
|
-
if (this.#control.onContainerClick) {
|
|
784
|
-
this.#control.onContainerClick(e);
|
|
785
|
-
} else {
|
|
786
|
-
this.#control.focus();
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
/** @private */
|
|
792
|
-
#handleControlInvalid(): void {
|
|
793
|
-
this._invalid = true;
|
|
794
|
-
this.notifyControlStateChange();
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
/** @private */
|
|
798
|
-
#handleControlChange(): void {
|
|
799
|
-
this._invalid = !(this.#control?.checkValidity?.() ?? true);
|
|
800
|
-
this.notifyControlStateChange();
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
/** @private */
|
|
804
|
-
#handleFormReset(): void {
|
|
805
|
-
this._invalid = false;
|
|
806
|
-
this.notifyControlStateChange();
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
/** @private */
|
|
810
|
-
#changeControl(control: FormFieldControl | null): void {
|
|
811
|
-
if (this.#control === control) return;
|
|
812
|
-
if (this.#control) {
|
|
813
|
-
if (this.#hintText) {
|
|
814
|
-
M3eAriaDescriber.removeDescription(this.#control, this.#hintText);
|
|
815
|
-
}
|
|
816
|
-
if (this.#errorText) {
|
|
817
|
-
M3eAriaDescriber.removeDescription(this.#control, this.#errorText);
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
this.#controlMutationController.unobserve(this.#control);
|
|
821
|
-
this.#control.removeEventListener("invalid", this.#controlInvalidHandler);
|
|
822
|
-
this.#control.form?.removeEventListener("reset", this.#formResetHandler);
|
|
823
|
-
}
|
|
824
|
-
this.#control = control;
|
|
825
|
-
if (this.#control) {
|
|
826
|
-
this.#controlMutationController.observe(this.#control);
|
|
827
|
-
this.#control.addEventListener("invalid", this.#controlInvalidHandler);
|
|
828
|
-
this.#control.form?.addEventListener("reset", this.#formResetHandler);
|
|
829
|
-
this.#control.removeAttribute("aria-invalid");
|
|
830
|
-
|
|
831
|
-
if (this.#hintText) {
|
|
832
|
-
M3eAriaDescriber.describe(this.#control, this.#hintText);
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
this.notifyControlStateChange();
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
/** @private */
|
|
840
|
-
#handleHintChange(): void {
|
|
841
|
-
const hintText = getTextContent(this._hint, true);
|
|
842
|
-
if (hintText === this.#hintText) return;
|
|
843
|
-
|
|
844
|
-
if (this.#control && this.#hintText) {
|
|
845
|
-
M3eAriaDescriber.removeDescription(this.#control, this.#hintText);
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
this.#hintText = hintText;
|
|
849
|
-
|
|
850
|
-
if (this.#control && this.#hintText) {
|
|
851
|
-
M3eAriaDescriber.describe(this.#control, this.#hintText);
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
/** @private */
|
|
856
|
-
#handleErrorChange(): void {
|
|
857
|
-
const errorText = getTextContent(this._error, true);
|
|
858
|
-
if (errorText === this.#errorText) return;
|
|
859
|
-
|
|
860
|
-
if (this.#control && this.#errorText) {
|
|
861
|
-
M3eAriaDescriber.removeDescription(this.#control, this.#errorText);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
this.#errorText = errorText;
|
|
865
|
-
|
|
866
|
-
if (this.#control && this.#errorText && this._invalid) {
|
|
867
|
-
M3eAriaDescriber.describe(this.#control, this.#errorText);
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
declare global {
|
|
873
|
-
interface HTMLElementTagNameMap {
|
|
874
|
-
"m3e-form-field": M3eFormFieldElement;
|
|
875
|
-
}
|
|
876
|
-
}
|