tyrell-components 1.0.0-TC58 → 1.0.0-TC60
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 -1
- package/css/tyrell-colors-static.css +14 -0
- package/css/tyrell-theme.css +6 -5
- package/css/tyrell.css +8 -6
- package/dist/tyrell-colors-static.css +1 -1
- package/dist/tyrell-theme.css +1 -1
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.d.ts +13 -12
- package/lib/base/ty-component.js +56 -21
- package/lib/components/button.d.ts +10 -0
- package/lib/components/button.js +22 -1
- package/lib/components/calendar-month.d.ts +7 -1
- package/lib/components/calendar-month.js +32 -18
- package/lib/components/calendar-navigation.js +19 -6
- package/lib/components/calendar.d.ts +25 -5
- package/lib/components/calendar.js +87 -37
- package/lib/components/checkbox.d.ts +5 -0
- package/lib/components/checkbox.js +18 -5
- package/lib/components/copy.d.ts +2 -0
- package/lib/components/copy.js +15 -31
- package/lib/components/date-picker.d.ts +7 -26
- package/lib/components/date-picker.js +14 -84
- package/lib/components/file-upload.js +6 -2
- package/lib/components/input.d.ts +0 -9
- package/lib/components/input.js +18 -40
- package/lib/components/modal.js +59 -18
- package/lib/components/option.d.ts +19 -0
- package/lib/components/option.js +38 -26
- package/lib/components/popup.js +56 -5
- package/lib/components/radio.d.ts +6 -0
- package/lib/components/radio.js +12 -28
- package/lib/components/select.d.ts +132 -194
- package/lib/components/select.js +436 -836
- package/lib/components/selected-tags.d.ts +8 -4
- package/lib/components/selected-tags.js +26 -8
- package/lib/components/switch.d.ts +4 -0
- package/lib/components/switch.js +18 -5
- package/lib/components/tabs.js +1 -1
- package/lib/components/textarea.d.ts +1 -0
- package/lib/components/textarea.js +21 -8
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/styles/button.js +1 -0
- package/lib/styles/calendar-month.js +1 -1
- package/lib/styles/calendar.js +3 -0
- package/lib/styles/checkbox.js +11 -5
- package/lib/styles/date-picker.js +5 -10
- package/lib/styles/input.js +5 -9
- package/lib/styles/option.d.ts +1 -1
- package/lib/styles/option.js +6 -7
- package/lib/styles/popup.d.ts +1 -1
- package/lib/styles/popup.js +2 -0
- package/lib/styles/radio.js +10 -4
- package/lib/styles/select-base.js +6 -70
- package/lib/styles/select.d.ts +1 -1
- package/lib/styles/select.js +13 -2
- package/lib/styles/switch.js +10 -5
- package/lib/styles/tag.js +2 -1
- package/lib/types/common.d.ts +3 -1
- package/lib/utils/calendar-utils.d.ts +49 -0
- package/lib/utils/calendar-utils.js +63 -6
- package/lib/utils/property-manager.d.ts +0 -5
- package/lib/utils/property-manager.js +0 -11
- package/lib/utils/scroll-lock.d.ts +10 -4
- package/lib/utils/scroll-lock.js +102 -2
- package/lib/utils/validity.d.ts +27 -1
- package/lib/utils/validity.js +68 -16
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/dist/tyrell.js.map +0 -1
- package/lib/utils/error-flavor.d.ts +0 -8
- package/lib/utils/error-flavor.js +0 -1
package/lib/components/option.js
CHANGED
|
@@ -13,18 +13,24 @@ constructor() {
|
|
|
13
13
|
super();
|
|
14
14
|
this._value = undefined;
|
|
15
15
|
this._selected = false;
|
|
16
|
+
this._checked = false;
|
|
17
|
+
this._inTrigger = false;
|
|
16
18
|
this._disabled = false;
|
|
17
19
|
this._highlighted = false;
|
|
18
20
|
this._hidden = false;
|
|
19
21
|
const shadow = this.attachShadow({ mode: 'open' });
|
|
20
22
|
ensureStyles(shadow, { css: optionStyles, id: 'ty-option' });
|
|
23
|
+
this._internals = this.attachInternals();
|
|
24
|
+
this._internals.ariaSelected = 'false';
|
|
21
25
|
this.render();
|
|
22
26
|
}
|
|
23
27
|
static get observedAttributes() {
|
|
24
|
-
return ['value', 'disabled', 'selected', 'highlighted', 'hidden'];
|
|
28
|
+
return ['value', 'disabled', 'selected', 'highlighted', 'hidden', 'role'];
|
|
25
29
|
}
|
|
26
30
|
connectedCallback() {
|
|
27
31
|
upgradeProperties(this);
|
|
32
|
+
if (!this.hasAttribute('role'))
|
|
33
|
+
this.setAttribute('role', 'option');
|
|
28
34
|
this.render();
|
|
29
35
|
}
|
|
30
36
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
@@ -35,7 +41,7 @@ case 'value':
|
|
|
35
41
|
this._value = newValue || undefined;
|
|
36
42
|
break;
|
|
37
43
|
case 'selected':
|
|
38
|
-
this._selected = newValue !== null;
|
|
44
|
+
this._selected = newValue !== null && !/^(false|0)$/i.test(newValue.trim());
|
|
39
45
|
break;
|
|
40
46
|
case 'disabled':
|
|
41
47
|
this._disabled = newValue !== null;
|
|
@@ -46,6 +52,10 @@ break;
|
|
|
46
52
|
case 'hidden':
|
|
47
53
|
this._hidden = newValue !== null;
|
|
48
54
|
break;
|
|
55
|
+
case 'role':
|
|
56
|
+
if (newValue === null && this.isConnected)
|
|
57
|
+
this.setAttribute('role', 'option');
|
|
58
|
+
return;
|
|
49
59
|
}
|
|
50
60
|
this.render();
|
|
51
61
|
}
|
|
@@ -87,6 +97,26 @@ this.setAttribute('selected', '');
|
|
|
87
97
|
else {
|
|
88
98
|
this.removeAttribute('selected');
|
|
89
99
|
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
get checked() {
|
|
103
|
+
return this._checked;
|
|
104
|
+
}
|
|
105
|
+
set checked(value) {
|
|
106
|
+
value = coerceBoolean(value);
|
|
107
|
+
if (this._checked !== value) {
|
|
108
|
+
this._checked = value;
|
|
109
|
+
this._internals.ariaSelected = String(value);
|
|
110
|
+
this.render();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
get inTrigger() {
|
|
114
|
+
return this._inTrigger;
|
|
115
|
+
}
|
|
116
|
+
set inTrigger(value) {
|
|
117
|
+
value = coerceBoolean(value);
|
|
118
|
+
if (this._inTrigger !== value) {
|
|
119
|
+
this._inTrigger = value;
|
|
90
120
|
this.render();
|
|
91
121
|
}
|
|
92
122
|
}
|
|
@@ -143,32 +173,14 @@ const shadow = this.shadowRoot;
|
|
|
143
173
|
if (!shadow.querySelector('.option-content')) {
|
|
144
174
|
shadow.innerHTML = `<div class="option-content"><slot></slot>${CHECK_SVG}</div>`;
|
|
145
175
|
}
|
|
176
|
+
this._internals.ariaDisabled = this._disabled ? 'true' : null;
|
|
146
177
|
const content = shadow.querySelector('.option-content');
|
|
147
178
|
if (content) {
|
|
148
|
-
|
|
149
|
-
content.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
content.
|
|
153
|
-
}
|
|
154
|
-
if (this._selected) {
|
|
155
|
-
content.setAttribute('selected', '');
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
content.removeAttribute('selected');
|
|
159
|
-
}
|
|
160
|
-
if (this._highlighted) {
|
|
161
|
-
content.setAttribute('highlighted', '');
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
content.removeAttribute('highlighted');
|
|
165
|
-
}
|
|
166
|
-
if (this._hidden) {
|
|
167
|
-
content.setAttribute('hidden', '');
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
content.removeAttribute('hidden');
|
|
171
|
-
}
|
|
179
|
+
content.toggleAttribute('disabled', this._disabled);
|
|
180
|
+
content.toggleAttribute('selected', this._checked);
|
|
181
|
+
content.toggleAttribute('highlighted', this._highlighted);
|
|
182
|
+
content.toggleAttribute('hidden', this._hidden);
|
|
183
|
+
content.classList.toggle('in-trigger', this._inTrigger);
|
|
172
184
|
}
|
|
173
185
|
}
|
|
174
186
|
}
|
package/lib/components/popup.js
CHANGED
|
@@ -9,6 +9,8 @@ const closeTimers = new WeakMap();
|
|
|
9
9
|
const escapeHandlers = new WeakMap();
|
|
10
10
|
const closeRequestHandlers = new WeakMap();
|
|
11
11
|
const popupIds = new WeakMap();
|
|
12
|
+
const anchors = new WeakMap();
|
|
13
|
+
const escapeGuards = new WeakMap();
|
|
12
14
|
const pointerPresses = new WeakSet();
|
|
13
15
|
function parseBoolAttr(el, name) {
|
|
14
16
|
return el.hasAttribute(name);
|
|
@@ -88,7 +90,7 @@ dialog.close();
|
|
|
88
90
|
function openPopup(el) {
|
|
89
91
|
const shadowRoot = el.shadowRoot;
|
|
90
92
|
const dialog = shadowRoot ? getPopupDialog(shadowRoot) : null;
|
|
91
|
-
if (!dialog)
|
|
93
|
+
if (!dialog || !el.isConnected)
|
|
92
94
|
return;
|
|
93
95
|
const anchor = getAnchorElement(el);
|
|
94
96
|
if (dialog.open) {
|
|
@@ -105,14 +107,28 @@ return;
|
|
|
105
107
|
const popupId = getPopupId(el);
|
|
106
108
|
lockScroll(popupId);
|
|
107
109
|
dialog.showModal();
|
|
110
|
+
guardEscape(el);
|
|
108
111
|
if (anchor?.hasAttribute('aria-haspopup'))
|
|
109
112
|
anchor.setAttribute('aria-expanded', 'true');
|
|
110
113
|
requestAnimationFrame(() => {
|
|
111
114
|
updatePosition(el);
|
|
112
115
|
dialog.classList.add('preparing-animation');
|
|
113
|
-
|
|
116
|
+
dialog.getBoundingClientRect();
|
|
114
117
|
requestAnimationFrame(() => {
|
|
115
118
|
dialog.classList.add('open');
|
|
119
|
+
if (!el.matches(':focus-within')) {
|
|
120
|
+
const target = el.querySelector('[autofocus]');
|
|
121
|
+
target?.focus({ preventScroll: true });
|
|
122
|
+
if (!el.matches(':focus-within')) {
|
|
123
|
+
dialog.focus({ preventScroll: true });
|
|
124
|
+
if (target) {
|
|
125
|
+
requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
126
|
+
if (dialog.open && shadowRoot.activeElement === dialog)
|
|
127
|
+
target.focus({ preventScroll: true });
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
116
132
|
el.dispatchEvent(new CustomEvent('open'));
|
|
117
133
|
});
|
|
118
134
|
});
|
|
@@ -153,6 +169,23 @@ return true;
|
|
|
153
169
|
}
|
|
154
170
|
return false;
|
|
155
171
|
}
|
|
172
|
+
function guardEscape(el) {
|
|
173
|
+
if (escapeGuards.has(el))
|
|
174
|
+
return;
|
|
175
|
+
const guard = (e) => {
|
|
176
|
+
if (e.key === 'Escape' && getPopupAttributes(el).disableClose && !fromNestedDialog(el, e))
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
};
|
|
179
|
+
escapeGuards.set(el, guard);
|
|
180
|
+
document.addEventListener('keydown', guard, true);
|
|
181
|
+
}
|
|
182
|
+
function unguardEscape(el) {
|
|
183
|
+
const guard = escapeGuards.get(el);
|
|
184
|
+
if (!guard)
|
|
185
|
+
return;
|
|
186
|
+
document.removeEventListener('keydown', guard, true);
|
|
187
|
+
escapeGuards.delete(el);
|
|
188
|
+
}
|
|
156
189
|
function handleEscape(el, event) {
|
|
157
190
|
if (fromNestedDialog(el, event))
|
|
158
191
|
return;
|
|
@@ -179,14 +212,16 @@ return;
|
|
|
179
212
|
anchor.setAttribute('aria-haspopup', 'dialog');
|
|
180
213
|
if (!anchor.hasAttribute('aria-expanded'))
|
|
181
214
|
anchor.setAttribute('aria-expanded', 'false');
|
|
215
|
+
const previous = anchors.get(el) ?? anchor;
|
|
182
216
|
const existingHandler = anchorClickHandlers.get(el);
|
|
183
217
|
if (existingHandler) {
|
|
184
|
-
|
|
218
|
+
previous.removeEventListener('pointerdown', existingHandler);
|
|
185
219
|
}
|
|
186
220
|
const existingKeyHandler = anchorKeyClickHandlers.get(el);
|
|
187
221
|
if (existingKeyHandler) {
|
|
188
|
-
|
|
222
|
+
previous.removeEventListener('click', existingKeyHandler);
|
|
189
223
|
}
|
|
224
|
+
anchors.set(el, anchor);
|
|
190
225
|
const handler = (e) => {
|
|
191
226
|
pointerPresses.add(el);
|
|
192
227
|
handleAnchorClick(el, e);
|
|
@@ -208,7 +243,8 @@ anchorKeyClickHandlers.set(el, keyHandler);
|
|
|
208
243
|
anchor.addEventListener('click', keyHandler);
|
|
209
244
|
}
|
|
210
245
|
function cleanupAnchorEvents(el) {
|
|
211
|
-
const anchor =
|
|
246
|
+
const anchor = anchors.get(el);
|
|
247
|
+
anchors.delete(el);
|
|
212
248
|
const handler = anchorClickHandlers.get(el);
|
|
213
249
|
if (anchor && handler) {
|
|
214
250
|
anchor.removeEventListener('pointerdown', handler);
|
|
@@ -233,6 +269,7 @@ const dialog = document.createElement('dialog');
|
|
|
233
269
|
const container = document.createElement('div');
|
|
234
270
|
const content = document.createElement('slot');
|
|
235
271
|
dialog.className = 'popup-dialog';
|
|
272
|
+
dialog.tabIndex = -1;
|
|
236
273
|
container.className = 'popup-container';
|
|
237
274
|
content.id = 'popup-content';
|
|
238
275
|
shadowRoot.appendChild(dialog);
|
|
@@ -246,12 +283,23 @@ dialog.addEventListener('pointerdown', outsideHandler);
|
|
|
246
283
|
const escapeHandler = (e) => handleEscape(el, e);
|
|
247
284
|
escapeHandlers.set(el, escapeHandler);
|
|
248
285
|
el.addEventListener('keydown', escapeHandler);
|
|
286
|
+
const inertKeys = (e) => {
|
|
287
|
+
if ((e.key === 'Enter' || e.key === ' ') && e.composedPath()[0] === dialog)
|
|
288
|
+
e.preventDefault();
|
|
289
|
+
};
|
|
290
|
+
for (const type of ['keydown', 'keypress', 'keyup'])
|
|
291
|
+
dialog.addEventListener(type, inertKeys);
|
|
292
|
+
dialog.addEventListener('cancel', (e) => {
|
|
293
|
+
if (getPopupAttributes(el).disableClose)
|
|
294
|
+
e.preventDefault();
|
|
295
|
+
});
|
|
249
296
|
new MutationObserver(() => {
|
|
250
297
|
if (dialog.open)
|
|
251
298
|
return;
|
|
252
299
|
clearTimeout(closeTimers.get(el));
|
|
253
300
|
closeTimers.delete(el);
|
|
254
301
|
pointerPresses.delete(el);
|
|
302
|
+
unguardEscape(el);
|
|
255
303
|
unlockScroll(getPopupId(el));
|
|
256
304
|
dialog.classList.remove('open');
|
|
257
305
|
dialog.classList.remove('preparing-animation');
|
|
@@ -289,12 +337,15 @@ if (outsideHandler) {
|
|
|
289
337
|
dialog.removeEventListener('pointerdown', outsideHandler);
|
|
290
338
|
outsideClickHandlers.delete(el);
|
|
291
339
|
}
|
|
340
|
+
if (dialog.open)
|
|
341
|
+
dialog.close();
|
|
292
342
|
}
|
|
293
343
|
const escapeHandler = escapeHandlers.get(el);
|
|
294
344
|
if (escapeHandler) {
|
|
295
345
|
el.removeEventListener('keydown', escapeHandler);
|
|
296
346
|
escapeHandlers.delete(el);
|
|
297
347
|
}
|
|
348
|
+
unguardEscape(el);
|
|
298
349
|
const closeRequestHandler = closeRequestHandlers.get(el);
|
|
299
350
|
if (closeRequestHandler) {
|
|
300
351
|
el.removeEventListener('ty:close-popup', closeRequestHandler);
|
|
@@ -17,6 +17,7 @@ export interface TyRadioElement extends HTMLElement {
|
|
|
17
17
|
flavor: Flavor;
|
|
18
18
|
}
|
|
19
19
|
export declare class TyRadio extends TyComponent<RadioState> implements TyRadioElement {
|
|
20
|
+
protected static labelClicks: boolean;
|
|
20
21
|
protected static properties: {
|
|
21
22
|
value: {
|
|
22
23
|
type: "string";
|
|
@@ -169,6 +170,11 @@ export declare class TyRadioGroup extends TyComponent<RadioGroupState> implement
|
|
|
169
170
|
radio's; it needs a name, a nameless radio never reports valueMissing. */
|
|
170
171
|
private updateValidity;
|
|
171
172
|
private handleRadioSelect;
|
|
173
|
+
/**
|
|
174
|
+
* Select a value as the user did: input + change, like a native radio,
|
|
175
|
+
* whether by click, arrow keys or Space. Nothing fires when it is already selected.
|
|
176
|
+
*/
|
|
177
|
+
private select;
|
|
172
178
|
/**
|
|
173
179
|
* Arrow-key navigation within group (W3C radio practice: arrow keys move
|
|
174
180
|
* focus and selection together).
|
package/lib/components/radio.js
CHANGED
|
@@ -134,6 +134,7 @@ set size(v) { this.setProperty("size", v); }
|
|
|
134
134
|
get flavor() { return this.getProperty("flavor"); }
|
|
135
135
|
set flavor(v) { this.setProperty("flavor", v); }
|
|
136
136
|
}
|
|
137
|
+
TyRadio.labelClicks = true;
|
|
137
138
|
TyRadio.properties = {
|
|
138
139
|
value: { type: "string", default: "" },
|
|
139
140
|
checked: {
|
|
@@ -237,16 +238,17 @@ const detail = e.detail;
|
|
|
237
238
|
const newValue = detail?.value;
|
|
238
239
|
if (typeof newValue !== "string" || newValue === this.value)
|
|
239
240
|
return;
|
|
240
|
-
this.
|
|
241
|
+
this.select(newValue, e);
|
|
242
|
+
}
|
|
243
|
+
select(value, originalEvent) {
|
|
244
|
+
if (value === this.value)
|
|
245
|
+
return;
|
|
246
|
+
this.value = value;
|
|
241
247
|
this.syncChildren();
|
|
248
|
+
const detail = { value, formValue: value, originalEvent };
|
|
242
249
|
setTimeout(() => {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
formValue: newValue,
|
|
246
|
-
originalEvent: e,
|
|
247
|
-
};
|
|
248
|
-
this.dispatchEvent(new CustomEvent("input", { detail: eventDetail, bubbles: true, composed: true }));
|
|
249
|
-
this.dispatchEvent(new CustomEvent("change", { detail: eventDetail, bubbles: true, composed: true }));
|
|
250
|
+
this.dispatchEvent(new CustomEvent("input", { detail, bubbles: true, composed: true }));
|
|
251
|
+
this.dispatchEvent(new CustomEvent("change", { detail, bubbles: true, composed: true }));
|
|
250
252
|
}, 0);
|
|
251
253
|
}
|
|
252
254
|
handleKeydown(e) {
|
|
@@ -271,16 +273,7 @@ nextIndex = current
|
|
|
271
273
|
else if (["Space", " ", "Enter"].includes(e.key)) {
|
|
272
274
|
if (current) {
|
|
273
275
|
e.preventDefault();
|
|
274
|
-
this.
|
|
275
|
-
this.syncChildren();
|
|
276
|
-
const eventDetail = {
|
|
277
|
-
value: current.value,
|
|
278
|
-
formValue: current.value,
|
|
279
|
-
originalEvent: e,
|
|
280
|
-
};
|
|
281
|
-
setTimeout(() => {
|
|
282
|
-
this.dispatchEvent(new CustomEvent("change", { detail: eventDetail, bubbles: true, composed: true }));
|
|
283
|
-
}, 0);
|
|
276
|
+
this.select(current.value, e);
|
|
284
277
|
}
|
|
285
278
|
return;
|
|
286
279
|
}
|
|
@@ -290,16 +283,7 @@ return;
|
|
|
290
283
|
const next = radios[nextIndex];
|
|
291
284
|
if (next) {
|
|
292
285
|
next.focus();
|
|
293
|
-
this.
|
|
294
|
-
this.syncChildren();
|
|
295
|
-
const eventDetail = {
|
|
296
|
-
value: next.value,
|
|
297
|
-
formValue: next.value,
|
|
298
|
-
originalEvent: e,
|
|
299
|
-
};
|
|
300
|
-
setTimeout(() => {
|
|
301
|
-
this.dispatchEvent(new CustomEvent("change", { detail: eventDetail, bubbles: true, composed: true }));
|
|
302
|
-
}, 0);
|
|
286
|
+
this.select(next.value, e);
|
|
303
287
|
}
|
|
304
288
|
}
|
|
305
289
|
removeEventListeners() {
|