@fusion.dev/helix-headless 0.233.0 → 0.235.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.
@@ -37,6 +37,17 @@ declare const HelixHeadlessTreeItem_base: (new (...args: any[]) => import("@fusi
37
37
  * sends `helix-load`, the row says it is busy, and the children you add appear
38
38
  * in it. Remove `lazy` once they are in.
39
39
  *
40
+ * **The `actions` slot holds the row's own controls**, such as a button that
41
+ * opens a menu of what you can do with the item. A press, a key or a
42
+ * right-click there stays with the control: it does not choose, open, follow
43
+ * or move the row. The actions show while the pointer is over the row, while
44
+ * the row has focus, and while focus is inside them. Tab moves from the focused
45
+ * row into its actions and Shift+Tab back. Every other row's actions are
46
+ * `inert`, so Tab leaves the tree after the focused row's. A row with actions
47
+ * is named by its label alone, so the controls are not read as part of its
48
+ * name. On a touch screen the first tap on a row chooses and focuses it, which
49
+ * shows its actions.
50
+ *
40
51
  * **In a `reorderable` tree, the row has a grip** at its far end, which a
41
52
  * pointer drags to move the item among its siblings. The tree says which item
42
53
  * is moving and where the drop indicator is, with the `dragging`,
@@ -48,6 +59,7 @@ declare const HelixHeadlessTreeItem_base: (new (...args: any[]) => import("@fusi
48
59
  * @documentation https://fusion.dev/helix/components/tree
49
60
  *
50
61
  * @slot - The item's label. A nested item does not go here: give it `slot="children"`. In a development build, an item nested here is reported.
62
+ * @slot actions - Controls for the row, after `end`, such as a button that opens a menu. Shown while the row is hovered or focused.
51
63
  * @slot chevron - Replaces the expand and collapse mark of a branch, such as with your own icon.
52
64
  * @slot children - Nested items, which make this a branch.
53
65
  * @slot end - Content after the label, at the far side of the row, such as a count or a state.
@@ -59,6 +71,7 @@ declare const HelixHeadlessTreeItem_base: (new (...args: any[]) => import("@fusi
59
71
  * @event {HelixLoadEvent} helix-load - Fired when a `lazy` item opens, so you can load its children.
60
72
  * @event {ToggleEvent} toggle - Sent when the branch opens or closes, with `newState` and `oldState`.
61
73
  *
74
+ * @csspart actions - The `actions` slot, which draws no box of its own. `inert` while the actions are not shown, which takes what it holds off the tab order and out of reach of the pointer.
62
75
  * @csspart checkbox - The check mark's box, in a tree with `selection-mode="multiple"`.
63
76
  * @csspart checkbox-checked - The check mark's box while the item is checked.
64
77
  * @csspart checkbox-mixed - The check mark's box while some of a branch's items are checked.
@@ -72,6 +85,7 @@ declare const HelixHeadlessTreeItem_base: (new (...args: any[]) => import("@fusi
72
85
  *
73
86
  * @cssproperty --tree-level - How deep this row sits, counting from one as `aria-level` does, for the indent.
74
87
  *
88
+ * @cssstate actions-shown - While the row's actions are shown: the row is hovered or focused, or focus is inside the actions.
75
89
  * @cssstate checked - While it is checked, in a tree with `selection-mode="multiple"`.
76
90
  * @cssstate dragging - The item is being moved, in a `reorderable` tree.
77
91
  * @cssstate drop-after - The item being moved goes after this one when it is dropped.
@@ -162,6 +176,33 @@ export declare class HelixHeadlessTreeItem extends HelixHeadlessTreeItem_base {
162
176
  * sent.
163
177
  */
164
178
  private branch;
179
+ /** Whether the pointer is over the row. */
180
+ private hovered;
181
+ /** Whether focus is on the row, or inside its actions. */
182
+ private focusedHere;
183
+ /** Whether the row's actions are shown and can be reached. */
184
+ private get actionsShown();
185
+ /**
186
+ * Focus on this row or inside its actions shows them. Focus anywhere else,
187
+ * such as on a nested row, does not. A move from the row into its actions is
188
+ * a `focusout` and then a `focusin` in the same task, so the update between
189
+ * them never draws.
190
+ */
191
+ private readonly handleFocusIn;
192
+ /**
193
+ * **Read where focus is going, never cleared and set again.** The update a
194
+ * `focusout` asks for runs before the browser moves focus on, so clearing
195
+ * here made the actions `inert` under a Tab already headed into them, and
196
+ * focus fell to the page. Measured in Chromium: Tab from a row landed on
197
+ * `<body>`.
198
+ */
199
+ private readonly handleFocusOut;
200
+ /** Whether a node is inside what is slotted into `actions`, read up the page's own tree to this item. */
201
+ private intoActions;
202
+ private readonly handleRowEnter;
203
+ private readonly handleRowLeave;
204
+ connectedCallback(): void;
205
+ disconnectedCallback(): void;
165
206
  protected firstUpdated(changed: PropertyValues): void;
166
207
  /**
167
208
  * Moves focus to this node.
@@ -222,6 +263,8 @@ export declare class HelixHeadlessTreeItem extends HelixHeadlessTreeItem_base {
222
263
  private readonly handleCheckClick;
223
264
  private readonly handleToggleClick;
224
265
  private readonly handleRowClick;
266
+ /** Whether a press inside the actions landed on a control, which then acts on it instead of the row's link. */
267
+ private landedOnControl;
225
268
  /**
226
269
  * The expand and collapse mark of a branch, as the `chevron` slot's
227
270
  * fallback, so an icon of your own replaces it by being slotted.
@@ -21,6 +21,22 @@ let HelixHeadlessTreeItem = class HelixHeadlessTreeItem extends MixinControllerO
21
21
  this.focusable = false;
22
22
  this.value = '';
23
23
  this.branch = false;
24
+ this.hovered = false;
25
+ this.focusedHere = false;
26
+ this.handleFocusIn = (event) => {
27
+ const first = event.composedPath()[0];
28
+ this.focusedHere =
29
+ this.fromActions(event) || first === this.partNamed('item') || first === this.partNamed('row');
30
+ };
31
+ this.handleFocusOut = (event) => {
32
+ this.focusedHere = this.intoActions(event.relatedTarget);
33
+ };
34
+ this.handleRowEnter = () => {
35
+ this.hovered = true;
36
+ };
37
+ this.handleRowLeave = () => {
38
+ this.hovered = false;
39
+ };
24
40
  this.handleBeforeMatch = (event) => {
25
41
  if (this.open || this.requestOpen(true)) {
26
42
  return;
@@ -45,6 +61,12 @@ let HelixHeadlessTreeItem = class HelixHeadlessTreeItem extends MixinControllerO
45
61
  this.toggleOpen();
46
62
  };
47
63
  this.handleRowClick = (event) => {
64
+ if (this.fromActions(event)) {
65
+ if (this.href !== '' && !this.landedOnControl(event)) {
66
+ event.preventDefault();
67
+ }
68
+ return;
69
+ }
48
70
  if (fromGrip(event)) {
49
71
  event.preventDefault();
50
72
  return;
@@ -69,6 +91,33 @@ let HelixHeadlessTreeItem = class HelixHeadlessTreeItem extends MixinControllerO
69
91
  }
70
92
  };
71
93
  }
94
+ get actionsShown() {
95
+ return this.hovered || this.focusedHere;
96
+ }
97
+ fromActions(event) {
98
+ const actions = this.partNamed('actions');
99
+ return event
100
+ .composedPath()
101
+ .some((node) => node === actions ||
102
+ (node instanceof Element && node.parentElement === this && node.slot === 'actions'));
103
+ }
104
+ intoActions(node) {
105
+ let at = node instanceof Node ? node : null;
106
+ while (at && at.parentNode !== this) {
107
+ at = at.parentNode;
108
+ }
109
+ return at instanceof Element && at.slot === 'actions';
110
+ }
111
+ connectedCallback() {
112
+ super.connectedCallback();
113
+ this.addEventListener('focusin', this.handleFocusIn);
114
+ this.addEventListener('focusout', this.handleFocusOut);
115
+ }
116
+ disconnectedCallback() {
117
+ super.disconnectedCallback();
118
+ this.removeEventListener('focusin', this.handleFocusIn);
119
+ this.removeEventListener('focusout', this.handleFocusOut);
120
+ }
72
121
  firstUpdated(changed) {
73
122
  super.firstUpdated(changed);
74
123
  this.finishHydration();
@@ -126,6 +175,20 @@ let HelixHeadlessTreeItem = class HelixHeadlessTreeItem extends MixinControllerO
126
175
  }
127
176
  }
128
177
  }
178
+ landedOnControl(event) {
179
+ const row = this.partNamed('row');
180
+ for (const node of event.composedPath()) {
181
+ if (node === row) {
182
+ return false;
183
+ }
184
+ if (node instanceof HTMLElement &&
185
+ (node.matches('a[href], button, input, label, select, summary, textarea') ||
186
+ node.getAttribute('role') === 'button')) {
187
+ return true;
188
+ }
189
+ }
190
+ return false;
191
+ }
129
192
  renderToggle() {
130
193
  return html `<slot
131
194
  name="chevron"
@@ -154,8 +217,14 @@ let HelixHeadlessTreeItem = class HelixHeadlessTreeItem extends MixinControllerO
154
217
  renderRow() {
155
218
  return html `${this.isBranch ? this.renderToggle() : nothing}${this.renderCheckbox()}
156
219
  <slot name="start"></slot>
157
- <span part="label"><slot></slot></span>
158
- <slot name="end"></slot>${this.grip && !this.disabled
220
+ <span part="label" id="label"><slot></slot></span>
221
+ <slot name="end"></slot>
222
+ <slot
223
+ name="actions"
224
+ part="actions"
225
+ ?inert=${!this.actionsShown}
226
+ @slotchange=${() => this.requestUpdate()}
227
+ ></slot>${this.grip && !this.disabled
159
228
  ? html `<span part="grip" aria-hidden="true"
160
229
  ><svg part="grip-mark" fill="currentColor" viewBox=${dotsSixVertical.viewBox}>
161
230
  ${unsafeSVG(dotsSixVertical.content)}
@@ -172,6 +241,7 @@ let HelixHeadlessTreeItem = class HelixHeadlessTreeItem extends MixinControllerO
172
241
  this.toggleState('dragging', this.move === 'dragging');
173
242
  this.toggleState('drop-after', this.move === 'drop-after');
174
243
  this.toggleState('drop-before', this.move === 'drop-before');
244
+ this.toggleState('actions-shown', this.actionsShown);
175
245
  if (this.childrenKnown) {
176
246
  this.branch = this.knownChildren.some((child) => child.slot === 'children');
177
247
  }
@@ -198,6 +268,7 @@ let HelixHeadlessTreeItem = class HelixHeadlessTreeItem extends MixinControllerO
198
268
  const busy = this.open && this.lazy ? 'true' : nothing;
199
269
  const off = this.disabled ? 'true' : nothing;
200
270
  const tabIndex = this.focusable || !this.childrenKnown ? '0' : '-1';
271
+ const named = this.knownChildren.some((child) => child.slot === 'actions') ? 'label' : nothing;
201
272
  return html `<div
202
273
  part="item"
203
274
  role=${linked ? 'none' : 'treeitem'}
@@ -209,6 +280,7 @@ let HelixHeadlessTreeItem = class HelixHeadlessTreeItem extends MixinControllerO
209
280
  aria-level=${linked ? nothing : depth}
210
281
  aria-posinset=${linked ? nothing : position}
211
282
  aria-setsize=${linked ? nothing : size}
283
+ aria-labelledby=${linked ? nothing : named}
212
284
  tabindex=${linked ? nothing : tabIndex}
213
285
  >
214
286
  ${linked
@@ -226,14 +298,19 @@ let HelixHeadlessTreeItem = class HelixHeadlessTreeItem extends MixinControllerO
226
298
  aria-level=${depth}
227
299
  aria-posinset=${position}
228
300
  aria-setsize=${size}
301
+ aria-labelledby=${named}
229
302
  tabindex=${tabIndex}
230
303
  style="--tree-level: ${level}"
231
304
  @click=${this.handleRowClick}
305
+ @pointerenter=${this.handleRowEnter}
306
+ @pointerleave=${this.handleRowLeave}
232
307
  >${this.renderRow()}</a>`
233
308
  : html `<div
234
309
  part="row"
235
310
  style="--tree-level: ${level}"
236
311
  @click=${this.handleRowClick}
312
+ @pointerenter=${this.handleRowEnter}
313
+ @pointerleave=${this.handleRowLeave}
237
314
  >${this.renderRow()}</div>`}
238
315
  <!-- Inside the treeitem, not beside it. As a sibling, the row's
239
316
  \`aria-expanded\` describes a group the row does not own and the
@@ -302,6 +379,12 @@ __decorate([
302
379
  __decorate([
303
380
  state()
304
381
  ], HelixHeadlessTreeItem.prototype, "branch", void 0);
382
+ __decorate([
383
+ state()
384
+ ], HelixHeadlessTreeItem.prototype, "hovered", void 0);
385
+ __decorate([
386
+ state()
387
+ ], HelixHeadlessTreeItem.prototype, "focusedHere", void 0);
305
388
  HelixHeadlessTreeItem = __decorate([
306
389
  customElement('helix-headless-tree-item')
307
390
  ], HelixHeadlessTreeItem);
@@ -39,6 +39,10 @@ declare const HelixHeadlessTree_base: (new (...args: any[]) => import("@fusion.d
39
39
  * and Control+Shift+Home or End checks every item from the focused one to the
40
40
  * first or the last, then moves there, as the tree pattern's range keys do.
41
41
  *
42
+ * Tab moves from the focused item into its `actions`, and out of the tree
43
+ * after them. A key pressed there is the control's, so the arrows, Enter,
44
+ * Space and typed letters move and choose nothing in the tree.
45
+ *
42
46
  * A tree with no name of its own is announced as "Tree", which says nothing
43
47
  * about what it holds, so a development build warns once with the kind
44
48
  * `missing-name` where neither `label` nor an `aria-label` names it.
@@ -74,6 +74,9 @@ let HelixHeadlessTree = class HelixHeadlessTree extends MixinCollection(MixinCon
74
74
  if (!current || !this.items.includes(current)) {
75
75
  return;
76
76
  }
77
+ if (current.fromActions(event)) {
78
+ return;
79
+ }
77
80
  if (this.multiple && this.handleMultiple(current, event)) {
78
81
  event.preventDefault();
79
82
  return;