tyrell-components 1.0.0-TC59 → 1.0.0-TC61

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.
@@ -21,6 +21,8 @@ export declare abstract class TyComponent<T = any> extends HTMLElement {
21
21
  * its focusable role element lives in the shadow (checkbox/switch) —
22
22
  * Firefox checks the host, not the validation anchor, on a blocked submit. */
23
23
  protected static delegatesFocus: boolean;
24
+ /** 'manual': the component assigns its children to slots itself (ty-select). */
25
+ protected static slotAssignment: SlotAssignmentMode;
24
26
  /** A wrapping <label> delegates clicks to the host (see watchLabelForwards). */
25
27
  protected static labelClicks: boolean;
26
28
  protected props: PropertyManager<T>;
@@ -52,6 +54,9 @@ export declare abstract class TyComponent<T = any> extends HTMLElement {
52
54
  * Sync property value to HTML attribute
53
55
  */
54
56
  private _syncPropertyToAttribute;
57
+ /** Our own write of a property to its attribute is under way. */
58
+ private _reflecting;
59
+ private _writeAttribute;
55
60
  private _toKebabCase;
56
61
  private _toCamelCase;
57
62
  /**
@@ -31,13 +31,14 @@ super();
31
31
  this._connected = false;
32
32
  this._rendered = false;
33
33
  this._userEdited = false;
34
+ this._reflecting = false;
34
35
  this._resetDefaults = null;
35
36
  const ctor = this.constructor;
36
37
  this.props = new PropertyManager(ctor.properties);
37
38
  this._internals = this.attachInternals();
38
39
  this._validity = new ValidityController(this, this._internals);
39
40
  if (!this.shadowRoot) {
40
- this.attachShadow({ mode: 'open', delegatesFocus: ctor.delegatesFocus });
41
+ this.attachShadow({ mode: 'open', delegatesFocus: ctor.delegatesFocus, slotAssignment: ctor.slotAssignment });
41
42
  }
42
43
  if (ctor.labelClicks) {
43
44
  labelClickHosts.add(this);
@@ -46,13 +47,8 @@ watchLabelForwards();
46
47
  }
47
48
  static get observedAttributes() {
48
49
  const attrs = [];
49
- for (const [name, config] of Object.entries(this.properties)) {
50
+ for (const name of Object.keys(this.properties)) {
50
51
  attrs.push(name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase());
51
- if (config.aliases) {
52
- for (const alias of Object.keys(config.aliases)) {
53
- attrs.push(alias);
54
- }
55
- }
56
52
  }
57
53
  return attrs;
58
54
  }
@@ -72,7 +68,16 @@ const config = this.props.getConfig(name);
72
68
  if (!config)
73
69
  return;
74
70
  const attrName = this._toKebabCase(name);
75
- if (config.type === 'boolean') {
71
+ this._reflecting = true;
72
+ try {
73
+ this._writeAttribute(attrName, config.type, newValue);
74
+ }
75
+ finally {
76
+ this._reflecting = false;
77
+ }
78
+ }
79
+ _writeAttribute(attrName, type, newValue) {
80
+ if (type === 'boolean') {
76
81
  if (newValue) {
77
82
  this.setAttribute(attrName, '');
78
83
  }
@@ -99,12 +104,12 @@ return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
99
104
  attributeChangedCallback(name, oldValue, newValue) {
100
105
  if (oldValue === newValue)
101
106
  return;
102
- let change = this.props.handleAlias(name, newValue);
103
- if (!change) {
104
- const camelName = this._toCamelCase(name);
105
- const propName = this.props.hasConfig(name) ? name : camelName;
106
- change = this.props.updateProperty(propName, newValue, 'attribute');
107
+ const propName = this.props.hasConfig(name) ? name : this._toCamelCase(name);
108
+ if (!this._reflecting && this._resetDefaults?.has(propName)) {
109
+ const config = this.props.getConfig(propName);
110
+ this._resetDefaults.set(propName, newValue ?? (typeof config.default === 'function' ? config.default() : config.default) ?? null);
107
111
  }
112
+ const change = this.props.updateProperty(propName, newValue, 'attribute');
108
113
  if (change) {
109
114
  this._handlePropertyChanges([change]);
110
115
  }
@@ -262,4 +267,5 @@ onFormReset() {
262
267
  TyComponent.formAssociated = true;
263
268
  TyComponent.properties = {};
264
269
  TyComponent.delegatesFocus = false;
270
+ TyComponent.slotAssignment = 'named';
265
271
  TyComponent.labelClicks = false;
@@ -50,6 +50,7 @@ export declare class TyCalendar extends HTMLElement {
50
50
  private _internals?;
51
51
  private _validity?;
52
52
  private _initialValue;
53
+ private _initialized;
53
54
  private _valueSets;
54
55
  private _pressing;
55
56
  private _localeObserver?;
@@ -48,6 +48,7 @@ this._flavor = 'primary';
48
48
  this._view = 'days';
49
49
  this._dayGridHeight = 0;
50
50
  this._initialValue = '';
51
+ this._initialized = false;
51
52
  this._valueSets = 0;
52
53
  this._pressing = false;
53
54
  const current = getCurrentDate();
@@ -63,7 +64,10 @@ this._validity = new ValidityController(this, this._internals);
63
64
  }
64
65
  }
65
66
  connectedCallback() {
67
+ if (!this._initialized) {
66
68
  this.initializeFromAttributes();
69
+ this._initialized = true;
70
+ }
67
71
  upgradeProperties(this);
68
72
  this.render();
69
73
  this.updateFormValue();
@@ -54,6 +54,7 @@ const shadow = this.shadowRoot;
54
54
  ensureStyles(shadow, { css: inputStyles, id: 'ty-input' });
55
55
  }
56
56
  onConnect() {
57
+ if (!this._rendered)
57
58
  this.initializeShadowValue();
58
59
  this._localeObserver = observeLocaleChanges(this, () => {
59
60
  this.render();
@@ -1,14 +1,26 @@
1
1
  /**
2
2
  * TyOption Web Component - rich HTML alternative to native <option>.
3
3
  * Property-attribute synchronization keeps it compatible with frameworks.
4
+ *
5
+ * Two kinds of selection state, never mixed:
6
+ * - `selected` (attribute/property) is the APP's mark. Only ty-select's
7
+ * `external-selection` mode reads it; otherwise the select's `value` rules.
8
+ * - `checked` (property only) is what the parent ty-select decided: it draws
9
+ * the check and aria-selected. Never written to an attribute, so a server
10
+ * morph has nothing of ours to strip.
11
+ * role="option" is an attribute (audit tools like axe don't read
12
+ * ElementInternals); it never changes, and comes back if a morph strips it.
4
13
  */
5
14
  import type { TyOptionElement } from '../types/common.js';
6
15
  export declare class TyOption extends HTMLElement implements TyOptionElement {
7
16
  private _value;
8
17
  private _selected;
18
+ private _checked;
19
+ private _inTrigger;
9
20
  private _disabled;
10
21
  private _highlighted;
11
22
  private _hidden;
23
+ private _internals;
12
24
  constructor();
13
25
  static get observedAttributes(): string[];
14
26
  connectedCallback(): void;
@@ -20,8 +32,15 @@ export declare class TyOption extends HTMLElement implements TyOptionElement {
20
32
  private getOptionValue;
21
33
  get value(): string | undefined;
22
34
  set value(val: string | undefined);
35
+ /** The app's mark, read by ty-select only in `external-selection` mode. */
23
36
  get selected(): boolean;
24
37
  set selected(value: boolean);
38
+ /** Set by the parent ty-select: draws the check and aria-selected. */
39
+ get checked(): boolean;
40
+ set checked(value: boolean);
41
+ /** Set by the parent ty-select while this option is shown in its trigger. */
42
+ get inTrigger(): boolean;
43
+ set inTrigger(value: boolean);
25
44
  get disabled(): boolean;
26
45
  set disabled(value: boolean);
27
46
  get highlighted(): boolean;
@@ -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
- if (this._disabled) {
149
- content.setAttribute('disabled', '');
150
- }
151
- else {
152
- content.removeAttribute('disabled');
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
  }