@threadlabs/looma 0.53.16 → 0.53.18
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/components/ui-form-field/ui-form-field.html +1 -1
- package/components/ui-form-field/ui-form-field.js +43 -1
- package/components/ui-input/ui-input.html +35 -0
- package/dist/index.js +1 -1
- package/docs/catalog.json +48 -3
- package/editor/components.css +37 -0
- package/editor/index.js +36 -1
- package/package.json +1 -1
- package/styles/ui-input.css +37 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<defs>
|
|
3
3
|
<prop name="invalid" type="boolean" default="false"
|
|
4
4
|
>Marks the field's control invalid by setting aria-invalid on it. Only while invalid, the error slot appears and becomes part of the control's
|
|
5
|
-
description.</prop>
|
|
5
|
+
description. Clearing the field error restores the control's own validation state.</prop>
|
|
6
6
|
<prop name="disabled" type="boolean" default="false"
|
|
7
7
|
>Disables the control named by the label's for attribute, or the first field control inside it. Composite controls supply their focus target and form value.
|
|
8
8
|
The field writes this to the control whenever it updates, so set it here rather than on the control.</prop>
|
|
@@ -15,8 +15,48 @@ export function connect(host) {
|
|
|
15
15
|
const element = host.element;
|
|
16
16
|
let activeInput = null;
|
|
17
17
|
let owned = new Set();
|
|
18
|
+
// Save the control's state only while the field overrides it.
|
|
19
|
+
let controlInvalid;
|
|
18
20
|
let queued = false;
|
|
19
21
|
const warned = new Set();
|
|
22
|
+
const readControlInvalid = (records) => {
|
|
23
|
+
if (records.some((record) => record.attributeName === "aria-invalid")) {
|
|
24
|
+
controlInvalid = activeInput.getAttribute("aria-invalid") ?? "false";
|
|
25
|
+
} else if (records.some(({ attributeName }) =>
|
|
26
|
+
/^data-ui-[a-z-]+-prop-invalid$/.test(attributeName) && activeInput.getAttribute(attributeName) === "true")) {
|
|
27
|
+
// A control's new true prop can leave aria-invalid unchanged while the field holds it true.
|
|
28
|
+
controlInvalid = "true";
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const setNativeInvalid = (value) => {
|
|
32
|
+
if (activeInput.getAttribute("aria-invalid") === value) return;
|
|
33
|
+
activeInput.setAttribute("aria-invalid", value);
|
|
34
|
+
// Only changes from the control contribute to the value we restore.
|
|
35
|
+
invalidObserver.takeRecords();
|
|
36
|
+
};
|
|
37
|
+
const invalidObserver = new MutationObserver((records) => {
|
|
38
|
+
readControlInvalid(records);
|
|
39
|
+
if (host.props.invalid.value) setNativeInvalid("true");
|
|
40
|
+
});
|
|
41
|
+
const releaseInvalid = () => {
|
|
42
|
+
if (controlInvalid === undefined) return;
|
|
43
|
+
readControlInvalid(invalidObserver.takeRecords());
|
|
44
|
+
invalidObserver.disconnect();
|
|
45
|
+
setNativeInvalid(controlInvalid);
|
|
46
|
+
controlInvalid = undefined;
|
|
47
|
+
};
|
|
48
|
+
const updateInvalid = () => {
|
|
49
|
+
if (!host.props.invalid.value) {
|
|
50
|
+
releaseInvalid();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (controlInvalid === undefined) {
|
|
54
|
+
controlInvalid = activeInput.getAttribute("aria-invalid") ?? "false";
|
|
55
|
+
invalidObserver.observe(activeInput, { attributes: true });
|
|
56
|
+
}
|
|
57
|
+
readControlInvalid(invalidObserver.takeRecords());
|
|
58
|
+
setNativeInvalid("true");
|
|
59
|
+
};
|
|
20
60
|
const removeOwned = (input) => {
|
|
21
61
|
if (!input || owned.size === 0) return;
|
|
22
62
|
const remaining = descriptionIds(input).filter((value) => !owned.has(value));
|
|
@@ -35,6 +75,7 @@ export function connect(host) {
|
|
|
35
75
|
const errorRegion = element.querySelector(':scope > .error');
|
|
36
76
|
const error = element.querySelector(':scope > .error > *, [slot="error"], [role="alert"]') ?? (errorRegion?.textContent.trim() ? errorRegion : null);
|
|
37
77
|
if (input !== activeInput) {
|
|
78
|
+
releaseInvalid();
|
|
38
79
|
removeOwned(activeInput);
|
|
39
80
|
activeInput = input;
|
|
40
81
|
owned = new Set();
|
|
@@ -62,7 +103,7 @@ export function connect(host) {
|
|
|
62
103
|
for (const value of element.querySelectorAll("[data-ui-field-value]")) value.disabled = input.disabled;
|
|
63
104
|
}
|
|
64
105
|
input.required = Boolean(host.props.required.value);
|
|
65
|
-
|
|
106
|
+
updateInvalid();
|
|
66
107
|
};
|
|
67
108
|
const schedule = () => {
|
|
68
109
|
if (queued) return;
|
|
@@ -85,6 +126,7 @@ export function connect(host) {
|
|
|
85
126
|
return () => {
|
|
86
127
|
stop();
|
|
87
128
|
observer.disconnect();
|
|
129
|
+
releaseInvalid();
|
|
88
130
|
removeOwned(activeInput);
|
|
89
131
|
};
|
|
90
132
|
}
|
|
@@ -120,6 +120,41 @@
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/* The native file action uses the outline button palette. The input still owns pointer and keyboard activation. */
|
|
124
|
+
:host[type="file"]::file-selector-button {
|
|
125
|
+
appearance: none;
|
|
126
|
+
min-block-size: var(--ui-control-size-sm);
|
|
127
|
+
margin-inline-end: var(--ui-space-2) !important;
|
|
128
|
+
padding: var(--ui-control-inset-block-sm, var(--ui-space-1)) var(--ui-action-inset-sm, var(--ui-space-2)) !important;
|
|
129
|
+
border: var(--ui-border-width) solid var(--ui-accent-outline-border, var(--ui-accent-subtle-text));
|
|
130
|
+
border-radius: var(--ui-action-radius, var(--ui-radius-md));
|
|
131
|
+
background-color: transparent;
|
|
132
|
+
background-image: linear-gradient(var(--ui-accent-wash), var(--ui-accent-wash));
|
|
133
|
+
color: var(--ui-accent-subtle-text);
|
|
134
|
+
box-shadow: var(--ui-neutral-shadow);
|
|
135
|
+
font: inherit;
|
|
136
|
+
font-weight: var(--ui-font-medium);
|
|
137
|
+
cursor: pointer;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
:host[type="file"]:enabled:hover::file-selector-button {
|
|
141
|
+
background-image: linear-gradient(var(--ui-accent-wash-hover), var(--ui-accent-wash-hover));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
:host[type="file"]:enabled:active::file-selector-button {
|
|
145
|
+
background-image: none;
|
|
146
|
+
background-color: oklch(from var(--ui-accent) l c h / calc(18% * var(--ui-tonal-opacity, 1)));
|
|
147
|
+
box-shadow: var(--ui-pressed);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
:host[type="file"]:disabled::file-selector-button {
|
|
151
|
+
border-color: var(--ui-control-border);
|
|
152
|
+
background: transparent;
|
|
153
|
+
color: var(--ui-disabled-text);
|
|
154
|
+
box-shadow: none;
|
|
155
|
+
cursor: not-allowed;
|
|
156
|
+
}
|
|
157
|
+
|
|
123
158
|
/* Tabbing into a field selects its text; tint that selection softly instead of the page highlight. */
|
|
124
159
|
:host::selection {
|
|
125
160
|
background: color-mix(in srgb, var(--ui-accent-solid) 20%, transparent);
|