@webtides/element-library 0.3.1 → 0.5.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.
Files changed (252) hide show
  1. package/CHANGELOG.md +300 -0
  2. package/README.md +72 -56
  3. package/all.js +16 -0
  4. package/catalog.js +17 -1
  5. package/custom-elements.json +15912 -10065
  6. package/package.json +1 -1
  7. package/src/components/accordion/accordion.changelog.md +11 -0
  8. package/src/components/accordion/accordion.js +15 -3
  9. package/src/components/accordion/accordion.readme.md +27 -1
  10. package/src/components/accordion/accordion.style.js +19 -0
  11. package/src/components/app-bar/app-bar.changelog.md +24 -0
  12. package/src/components/app-bar/app-bar.define.js +3 -0
  13. package/src/components/app-bar/app-bar.js +91 -0
  14. package/src/components/app-bar/app-bar.readme.md +130 -0
  15. package/src/components/app-bar/app-bar.style.js +103 -0
  16. package/src/components/app-frame/app-frame.changelog.md +59 -0
  17. package/src/components/app-frame/app-frame.define.js +3 -0
  18. package/src/components/app-frame/app-frame.events.js +6 -0
  19. package/src/components/app-frame/app-frame.js +1085 -0
  20. package/src/components/app-frame/app-frame.readme.md +425 -0
  21. package/src/components/app-frame/app-frame.style.js +534 -0
  22. package/src/components/button/button.changelog.md +21 -0
  23. package/src/components/button/button.events.js +3 -0
  24. package/src/components/button/button.js +145 -3
  25. package/src/components/button/button.readme.md +72 -4
  26. package/src/components/button/button.style.js +167 -8
  27. package/src/components/button-group/button-group.changelog.md +10 -0
  28. package/src/components/button-group/button-group.readme.md +2 -0
  29. package/src/components/button-group/button-group.style.js +6 -2
  30. package/src/components/checkbox-group-field/checkbox-group-field.changelog.md +6 -0
  31. package/src/components/checkbox-group-field/checkbox-group-field.js +7 -2
  32. package/src/components/checkbox-group-field/checkbox-group-field.readme.md +23 -1
  33. package/src/components/combobox-field/combobox-field.changelog.md +6 -0
  34. package/src/components/combobox-field/combobox-field.readme.md +8 -0
  35. package/src/components/combobox-field/combobox-field.style.js +2 -0
  36. package/src/components/date-field/date-field.changelog.md +6 -0
  37. package/src/components/date-field/date-field.readme.md +10 -0
  38. package/src/components/date-field/date-field.style.js +8 -3
  39. package/src/components/description-list/description-list.changelog.md +42 -0
  40. package/src/components/description-list/description-list.define.js +3 -0
  41. package/src/components/description-list/description-list.js +49 -0
  42. package/src/components/description-list/description-list.readme.md +161 -0
  43. package/src/components/description-list/description-list.style.js +169 -0
  44. package/src/components/dialog/dialog.changelog.md +7 -0
  45. package/src/components/dialog/dialog.readme.md +5 -0
  46. package/src/components/dialog/dialog.style.js +17 -2
  47. package/src/components/divider/divider.changelog.md +6 -0
  48. package/src/components/divider/divider.readme.md +1 -1
  49. package/src/components/divider/divider.style.js +6 -0
  50. package/src/components/drawer/drawer.changelog.md +7 -0
  51. package/src/components/drawer/drawer.readme.md +7 -6
  52. package/src/components/drawer/drawer.style.js +35 -2
  53. package/src/components/dropdown/dropdown.readme.md +6 -1
  54. package/src/components/file-field/file-field.changelog.md +8 -0
  55. package/src/components/file-field/file-field.js +135 -5
  56. package/src/components/file-field/file-field.readme.md +35 -6
  57. package/src/components/file-field/file-field.style.js +71 -0
  58. package/src/components/form-field/form-field.js +1 -1
  59. package/src/components/input-field/input-field.changelog.md +10 -0
  60. package/src/components/input-field/input-field.js +192 -14
  61. package/src/components/input-field/input-field.readme.md +88 -2
  62. package/src/components/input-field/input-field.style.js +2 -0
  63. package/src/components/list/list.changelog.md +30 -0
  64. package/src/components/list/list.define.js +3 -0
  65. package/src/components/list/list.js +68 -0
  66. package/src/components/list/list.readme.md +123 -0
  67. package/src/components/list/list.style.js +56 -0
  68. package/src/components/list-item/list-item.changelog.md +40 -0
  69. package/src/components/list-item/list-item.define.js +3 -0
  70. package/src/components/list-item/list-item.js +130 -0
  71. package/src/components/list-item/list-item.readme.md +144 -0
  72. package/src/components/list-item/list-item.style.js +246 -0
  73. package/src/components/menu/menu.changelog.md +44 -0
  74. package/src/components/menu/menu.define.js +3 -0
  75. package/src/components/menu/menu.events.js +5 -0
  76. package/src/components/menu/menu.js +793 -0
  77. package/src/components/menu/menu.readme.md +313 -0
  78. package/src/components/menu/menu.style.js +59 -0
  79. package/src/components/menu-group/menu-group.changelog.md +20 -0
  80. package/src/components/menu-group/menu-group.define.js +3 -0
  81. package/src/components/menu-group/menu-group.js +44 -0
  82. package/src/components/menu-group/menu-group.readme.md +74 -0
  83. package/src/components/menu-group/menu-group.style.js +38 -0
  84. package/src/components/menu-item/menu-item.changelog.md +32 -0
  85. package/src/components/menu-item/menu-item.define.js +3 -0
  86. package/src/components/menu-item/menu-item.js +168 -0
  87. package/src/components/menu-item/menu-item.readme.md +132 -0
  88. package/src/components/menu-item/menu-item.style.js +117 -0
  89. package/src/components/nav/nav.changelog.md +35 -0
  90. package/src/components/nav/nav.define.js +3 -0
  91. package/src/components/nav/nav.js +212 -0
  92. package/src/components/nav/nav.readme.md +248 -0
  93. package/src/components/nav/nav.style.js +269 -0
  94. package/src/components/nav-item/nav-item.changelog.md +25 -0
  95. package/src/components/nav-item/nav-item.define.js +3 -0
  96. package/src/components/nav-item/nav-item.js +75 -0
  97. package/src/components/nav-item/nav-item.readme.md +111 -0
  98. package/src/components/nav-item/nav-item.style.js +159 -0
  99. package/src/components/otp-field/otp-field.changelog.md +6 -0
  100. package/src/components/otp-field/otp-field.readme.md +8 -0
  101. package/src/components/otp-field/otp-field.style.js +8 -3
  102. package/src/components/pagination/pagination.changelog.md +8 -0
  103. package/src/components/pagination/pagination.js +123 -49
  104. package/src/components/pagination/pagination.readme.md +24 -6
  105. package/src/components/pagination/pagination.style.js +11 -1
  106. package/src/components/password-field/password-field.changelog.md +7 -0
  107. package/src/components/password-field/password-field.readme.md +11 -1
  108. package/src/components/password-field/password-field.style.js +2 -0
  109. package/src/components/popover/popover.changelog.md +6 -0
  110. package/src/components/popover/popover.style.js +1 -0
  111. package/src/components/radio-field/radio-field.changelog.md +6 -0
  112. package/src/components/radio-field/radio-field.js +7 -2
  113. package/src/components/radio-field/radio-field.readme.md +23 -1
  114. package/src/components/scroll-to-top/scroll-to-top.changelog.md +7 -5
  115. package/src/components/scroll-to-top/scroll-to-top.js +16 -12
  116. package/src/components/scroll-to-top/scroll-to-top.readme.md +2 -0
  117. package/src/components/segmented-field/segmented-field.changelog.md +27 -0
  118. package/src/components/segmented-field/segmented-field.define.js +3 -0
  119. package/src/components/segmented-field/segmented-field.js +175 -0
  120. package/src/components/segmented-field/segmented-field.readme.md +140 -0
  121. package/src/components/segmented-field/segmented-field.style.js +193 -0
  122. package/src/components/splitter/splitter.changelog.md +24 -0
  123. package/src/components/splitter/splitter.define.js +3 -0
  124. package/src/components/splitter/splitter.events.js +4 -0
  125. package/src/components/splitter/splitter.js +237 -0
  126. package/src/components/splitter/splitter.readme.md +164 -0
  127. package/src/components/splitter/splitter.style.js +100 -0
  128. package/src/components/status-bar/status-bar.changelog.md +25 -0
  129. package/src/components/status-bar/status-bar.define.js +3 -0
  130. package/src/components/status-bar/status-bar.js +74 -0
  131. package/src/components/status-bar/status-bar.readme.md +139 -0
  132. package/src/components/status-bar/status-bar.style.js +122 -0
  133. package/src/components/tab-group/tab-group.changelog.md +7 -0
  134. package/src/components/tab-group/tab-group.js +30 -9
  135. package/src/components/tab-group/tab-group.readme.md +14 -0
  136. package/src/components/textarea-field/textarea-field.changelog.md +6 -0
  137. package/src/components/textarea-field/textarea-field.js +14 -1
  138. package/src/components/textarea-field/textarea-field.readme.md +23 -1
  139. package/src/components/toast/toast.changelog.md +6 -0
  140. package/src/components/toast/toast.readme.md +5 -3
  141. package/src/components/toast/toast.style.js +22 -6
  142. package/src/components/toolbar/toolbar.changelog.md +24 -0
  143. package/src/components/toolbar/toolbar.define.js +3 -0
  144. package/src/components/toolbar/toolbar.js +233 -0
  145. package/src/components/toolbar/toolbar.readme.md +156 -0
  146. package/src/components/toolbar/toolbar.style.js +49 -0
  147. package/src/components/tooltip/tooltip.changelog.md +11 -0
  148. package/src/components/tooltip/tooltip.js +51 -4
  149. package/src/components/tooltip/tooltip.readme.md +26 -1
  150. package/src/components/tree/tree.changelog.md +23 -0
  151. package/src/components/tree/tree.define.js +3 -0
  152. package/src/components/tree/tree.js +138 -0
  153. package/src/components/tree/tree.readme.md +119 -0
  154. package/src/components/tree/tree.style.js +16 -0
  155. package/src/components/tree-item/tree-item.changelog.md +23 -0
  156. package/src/components/tree-item/tree-item.define.js +3 -0
  157. package/src/components/tree-item/tree-item.events.js +3 -0
  158. package/src/components/tree-item/tree-item.js +246 -0
  159. package/src/components/tree-item/tree-item.readme.md +128 -0
  160. package/src/components/tree-item/tree-item.style.js +226 -0
  161. package/src/styles/appearance.style.js +47 -0
  162. package/src/styles/choice-group.style.js +27 -1
  163. package/src/styles/input-control.style.js +87 -0
  164. package/src/styles/modal.style.js +14 -1
  165. package/src/styles/native.css +100 -0
  166. package/src/styles/size.style.js +41 -0
  167. package/src/utils/floating.js +15 -1
  168. package/src/utils/focus.js +69 -0
  169. package/src/utils/options.js +35 -0
  170. package/src/utils/scroll.js +24 -0
  171. package/src/utils/text-entry-attributes.js +13 -0
  172. package/types/all.d.ts +16 -0
  173. package/types/src/components/accordion/accordion.d.ts +3 -1
  174. package/types/src/components/app-bar/app-bar.d.ts +43 -0
  175. package/types/src/components/app-bar/app-bar.define.d.ts +1 -0
  176. package/types/src/components/app-bar/app-bar.style.d.ts +2 -0
  177. package/types/src/components/app-frame/app-frame.d.ts +497 -0
  178. package/types/src/components/app-frame/app-frame.define.d.ts +1 -0
  179. package/types/src/components/app-frame/app-frame.events.d.ts +7 -0
  180. package/types/src/components/app-frame/app-frame.style.d.ts +8 -0
  181. package/types/src/components/button/button.d.ts +61 -0
  182. package/types/src/components/button/button.events.d.ts +4 -0
  183. package/types/src/components/checkbox-group-field/checkbox-group-field.d.ts +5 -2
  184. package/types/src/components/combobox-field/combobox-field.d.ts +10 -0
  185. package/types/src/components/date-field/date-field.d.ts +10 -0
  186. package/types/src/components/description-list/description-list.d.ts +34 -0
  187. package/types/src/components/description-list/description-list.define.d.ts +1 -0
  188. package/types/src/components/description-list/description-list.style.d.ts +2 -0
  189. package/types/src/components/file-field/file-field.d.ts +68 -3
  190. package/types/src/components/form-field/form-field.d.ts +1 -1
  191. package/types/src/components/input-field/input-field.d.ts +99 -0
  192. package/types/src/components/list/list.d.ts +41 -0
  193. package/types/src/components/list/list.define.d.ts +1 -0
  194. package/types/src/components/list/list.style.d.ts +2 -0
  195. package/types/src/components/list-item/list-item.d.ts +64 -0
  196. package/types/src/components/list-item/list-item.define.d.ts +1 -0
  197. package/types/src/components/list-item/list-item.style.d.ts +2 -0
  198. package/types/src/components/menu/menu.d.ts +362 -0
  199. package/types/src/components/menu/menu.define.d.ts +1 -0
  200. package/types/src/components/menu/menu.events.d.ts +6 -0
  201. package/types/src/components/menu/menu.style.d.ts +2 -0
  202. package/types/src/components/menu-group/menu-group.d.ts +24 -0
  203. package/types/src/components/menu-group/menu-group.define.d.ts +1 -0
  204. package/types/src/components/menu-group/menu-group.style.d.ts +2 -0
  205. package/types/src/components/menu-item/menu-item.d.ts +80 -0
  206. package/types/src/components/menu-item/menu-item.define.d.ts +1 -0
  207. package/types/src/components/menu-item/menu-item.style.d.ts +2 -0
  208. package/types/src/components/nav/nav.d.ts +103 -0
  209. package/types/src/components/nav/nav.define.d.ts +1 -0
  210. package/types/src/components/nav/nav.style.d.ts +2 -0
  211. package/types/src/components/nav-item/nav-item.d.ts +39 -0
  212. package/types/src/components/nav-item/nav-item.define.d.ts +1 -0
  213. package/types/src/components/nav-item/nav-item.style.d.ts +2 -0
  214. package/types/src/components/otp-field/otp-field.d.ts +10 -0
  215. package/types/src/components/pagination/pagination.d.ts +31 -2
  216. package/types/src/components/password-field/password-field.d.ts +10 -0
  217. package/types/src/components/radio-field/radio-field.d.ts +5 -2
  218. package/types/src/components/scroll-to-top/scroll-to-top.d.ts +6 -5
  219. package/types/src/components/segmented-field/segmented-field.d.ts +85 -0
  220. package/types/src/components/segmented-field/segmented-field.define.d.ts +1 -0
  221. package/types/src/components/segmented-field/segmented-field.style.d.ts +2 -0
  222. package/types/src/components/splitter/splitter.d.ts +127 -0
  223. package/types/src/components/splitter/splitter.define.d.ts +1 -0
  224. package/types/src/components/splitter/splitter.events.d.ts +5 -0
  225. package/types/src/components/splitter/splitter.style.d.ts +2 -0
  226. package/types/src/components/status-bar/status-bar.d.ts +44 -0
  227. package/types/src/components/status-bar/status-bar.define.d.ts +1 -0
  228. package/types/src/components/status-bar/status-bar.style.d.ts +2 -0
  229. package/types/src/components/tab-group/tab-group.d.ts +17 -0
  230. package/types/src/components/textarea-field/textarea-field.d.ts +7 -0
  231. package/types/src/components/toolbar/toolbar.d.ts +96 -0
  232. package/types/src/components/toolbar/toolbar.define.d.ts +1 -0
  233. package/types/src/components/toolbar/toolbar.style.d.ts +2 -0
  234. package/types/src/components/tooltip/tooltip.d.ts +26 -0
  235. package/types/src/components/tree/tree.d.ts +62 -0
  236. package/types/src/components/tree/tree.define.d.ts +1 -0
  237. package/types/src/components/tree/tree.style.d.ts +2 -0
  238. package/types/src/components/tree-item/tree-item.d.ts +106 -0
  239. package/types/src/components/tree-item/tree-item.define.d.ts +1 -0
  240. package/types/src/components/tree-item/tree-item.events.d.ts +4 -0
  241. package/types/src/components/tree-item/tree-item.style.d.ts +2 -0
  242. package/types/src/styles/appearance.style.d.ts +31 -0
  243. package/types/src/styles/choice-group.style.d.ts +1 -1
  244. package/types/src/styles/input-control.style.d.ts +15 -0
  245. package/types/src/styles/modal.style.d.ts +5 -0
  246. package/types/src/styles/size.style.d.ts +24 -0
  247. package/types/src/utils/floating.d.ts +11 -0
  248. package/types/src/utils/focus.d.ts +25 -0
  249. package/types/src/utils/options.d.ts +17 -0
  250. package/types/src/utils/scroll.d.ts +11 -0
  251. package/types/src/utils/text-entry-attributes.d.ts +10 -0
  252. package/web-types.json +2935 -308
@@ -44,6 +44,14 @@ function focusIsVisible() {
44
44
  *
45
45
  * @property {string} for - The id of the anchor: the element the tooltip explains and opens from.
46
46
  * It is looked up in the document or the shadow root the tooltip is in.
47
+ * @property {Element | null} anchor - The anchor as an element, for one that an id cannot name: an
48
+ * element in another tree than the tooltip. A property only, and it comes before `for`. Default
49
+ * `null`.
50
+ * @property {'description'|'label'} type - What the tooltip is to its anchor. `'description'`
51
+ * (the default): it explains the anchor, and is its description for a screen reader.
52
+ * `'label'`: it shows the name the anchor already has, of a button with an icon alone for
53
+ * example. The anchor is not described by it then, and the tooltip is hidden from assistive
54
+ * technology, which would read the name twice.
47
55
  * @property {boolean} open - Whether the tooltip is shown. Reflected to the `open` attribute.
48
56
  * @property {'top'|'top-start'|'top-end'|'bottom'|'bottom-start'|'bottom-end'|'left'|'left-start'|'left-end'|'right'|'right-start'|'right-end'} placement -
49
57
  * The side of the anchor the tooltip is placed at, and with `-start` or `-end` the edge of the
@@ -72,6 +80,14 @@ export default class Tooltip extends TemplateElement {
72
80
  * @type {Set<'anchor' | 'tooltip' | 'focus'>}
73
81
  */
74
82
  this._reasons = new Set();
83
+
84
+ /**
85
+ * Whether the tooltip is shown, as it has said last (`:state(open)`). Kept here, and not
86
+ * read back from the states of the element: WebKit forgets what was added to them a
87
+ * moment later (`states.has()` is `false`), while the state still matches.
88
+ * @private
89
+ */
90
+ this._shown = false;
75
91
  }
76
92
 
77
93
  properties() {
@@ -84,9 +100,29 @@ export default class Tooltip extends TemplateElement {
84
100
  hideDelay: 0,
85
101
  arrow: false,
86
102
  disabled: false,
103
+ type: 'description',
87
104
  };
88
105
  }
89
106
 
107
+ /**
108
+ * The anchor as an element. No property of element-js: an element is nothing to compare or to
109
+ * keep as state.
110
+ * @returns {Element | null}
111
+ */
112
+ get anchor() {
113
+ return this._givenAnchor ?? null;
114
+ }
115
+
116
+ set anchor(anchor) {
117
+ const given = anchor instanceof Element ? anchor : null;
118
+ if (given === (this._givenAnchor ?? null)) return;
119
+ this._givenAnchor = given;
120
+ if (!this.isConnected) return;
121
+ // What opened the tooltip, a pointer or the focus, was on the anchor it had.
122
+ this._dismiss();
123
+ this._attach();
124
+ }
125
+
90
126
  connected() {
91
127
  this._attach();
92
128
  // The watcher does not run for the first value, so a tooltip that is open from the start is
@@ -124,6 +160,9 @@ export default class Tooltip extends TemplateElement {
124
160
  disabled: (disabled) => {
125
161
  if (disabled) this._dismiss();
126
162
  },
163
+ type: () => {
164
+ if (this.isConnected) this._attach();
165
+ },
127
166
  };
128
167
  }
129
168
 
@@ -165,7 +204,7 @@ export default class Tooltip extends TemplateElement {
165
204
  this._detach();
166
205
 
167
206
  const id = String(this.for ?? '');
168
- const anchor = id ? (this.getRootNode().getElementById?.(id) ?? null) : null;
207
+ const anchor = this.anchor ?? (id ? (this.getRootNode().getElementById?.(id) ?? null) : null);
169
208
  if (!anchor) {
170
209
  // Nothing to be placed at.
171
210
  if (this.open) this.open = false;
@@ -173,7 +212,13 @@ export default class Tooltip extends TemplateElement {
173
212
  }
174
213
 
175
214
  this._anchor = anchor;
176
- this._describe(anchor, true);
215
+ // A tooltip that shows the name of its anchor is for the eye: the anchor has that name
216
+ // already, and a screen reader would read it a second time.
217
+ const isLabel = this.type === 'label';
218
+ if (isLabel) this.setAttribute('aria-hidden', 'true');
219
+ else this.removeAttribute('aria-hidden');
220
+ this._describes = !isLabel;
221
+ if (this._describes) this._describe(anchor, true);
177
222
 
178
223
  this._anchorListeners = new AbortController();
179
224
  const options = { signal: this._anchorListeners.signal };
@@ -190,7 +235,7 @@ export default class Tooltip extends TemplateElement {
190
235
  _detach() {
191
236
  this._anchorListeners?.abort();
192
237
  this._anchorListeners = undefined;
193
- if (this._anchor) this._describe(this._anchor, false);
238
+ if (this._anchor && this._describes) this._describe(this._anchor, false);
194
239
  this._anchor = undefined;
195
240
  }
196
241
 
@@ -300,6 +345,7 @@ export default class Tooltip extends TemplateElement {
300
345
  }
301
346
 
302
347
  if (!this.matches(':popover-open')) this.showPopover();
348
+ this._shown = true;
303
349
  this._internals.states.add('open');
304
350
  this._startPositioning();
305
351
 
@@ -317,7 +363,8 @@ export default class Tooltip extends TemplateElement {
317
363
  /** @private */
318
364
  _applyClose() {
319
365
  // Not shown: nothing to undo and nothing to report.
320
- if (!this._internals.states.has('open')) return;
366
+ if (!this._shown) return;
367
+ this._shown = false;
321
368
 
322
369
  this._stopPositioning();
323
370
  this._openListeners?.abort();
@@ -44,6 +44,8 @@ import '@webtides/element-library/tooltip/define';
44
44
  | Name | Type | Default | Description |
45
45
  | --- | --- | --- | --- |
46
46
  | `for` | `string` | `''` | The id of the anchor, in the document or the shadow root the tooltip is in. |
47
+ | `anchor` | `Element \| null` | `null` | The anchor as an element, for one that an id cannot name. A property only; it comes before `for`. |
48
+ | `type` | `'description' \| 'label'` | `'description'` | What the tooltip is to its anchor: its description, or the name the anchor already has, for the eye. See [A tooltip that shows a name](#a-tooltip-that-shows-a-name). |
47
49
  | `open` | `boolean` | `false` | Whether the tooltip is shown. Reflected to the `open` attribute. |
48
50
  | `placement` | `string` | `'top'` | `top`, `bottom`, `left` or `right`, each also with `-start` or `-end`. |
49
51
  | `distance` | `number` | `8` | The gap between the anchor and the tooltip, or the tip of its arrow, in pixels. |
@@ -138,10 +140,33 @@ Any element can be the anchor. One that takes the focus (a button, a link, a fie
138
140
 
139
141
  Without an anchor in the page the tooltip does not open.
140
142
 
143
+ #### An anchor in another tree
144
+
145
+ An id is known in the document or the shadow root it is in, and nowhere else. A tooltip in the shadow root of a component cannot name an element of the page by `for`. Such a tooltip gets its anchor as an element:
146
+
147
+ ```js
148
+ tooltip.anchor = button;
149
+ ```
150
+
151
+ `anchor` is a property only. While it is set, `for` is not looked at; `anchor = null` gives the anchor back to `for`. The tooltip closes when its anchor changes.
152
+
153
+ ## A tooltip that shows a name
154
+
155
+ A button with an icon alone has its name in `aria-label`, where the eye does not find it. A tooltip can show that name. It is no description then: a screen reader would read the name, and the same text again.
156
+
157
+ ```html
158
+ <el-button id="archive" circle="true" aria-label="Archive">…</el-button>
159
+ <el-tooltip for="archive" type="label">Archive</el-tooltip>
160
+ ```
161
+
162
+ With `type="label"` the tooltip does not write `aria-describedby` on its anchor and is hidden from assistive technology (`aria-hidden`). The anchor has to have the name itself. It opens, closes and is placed as every tooltip.
163
+
164
+ An [`el-toolbar`](../toolbar/toolbar.readme.md) makes these tooltips for its buttons itself.
165
+
141
166
  ## Accessibility
142
167
 
143
168
  - The tooltip adds its id to the `aria-describedby` of its anchor and keeps what is there. A screen reader reads the text of the tooltip after the name of the anchor, also while the tooltip is closed. A tooltip without an id gets one (`el-tooltip-1`).
144
- - The tooltip is a description, not a name. A button that shows only an icon needs `aria-label` as well.
169
+ - The tooltip is a description, not a name. A button that shows only an icon needs `aria-label` as well. To show that name to the eye, see [A tooltip that shows a name](#a-tooltip-that-shows-a-name).
145
170
  - An `el-button` as the anchor passes the description on to the control inside it.
146
171
  - The element has the role `tooltip`.
147
172
  - Put text into a tooltip, no links and no controls: the focus does not go into it, and it closes when the focus leaves the anchor. Content to interact with belongs into an `el-popover`.
@@ -0,0 +1,23 @@
1
+ # Change Log
2
+
3
+ All notable changes to this component live here. Versions refer to the parent `@webtides/element-library` release (see root [`CHANGELOG.md`](../../../CHANGELOG.md)); components no longer version independently.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/).
6
+
7
+ <!--
8
+ When your PR touches this component, add an entry under Unreleased and
9
+ mirror it (prefixed with the component name) in root CHANGELOG.md.
10
+ Uncomment headings as needed.
11
+ -->
12
+
13
+ ## Unreleased
14
+
15
+ ## [0.4.0] - 2026-11-27
16
+
17
+ ### Added
18
+
19
+ - Initial `el-tree`: entries that open and close, for folders, categories and a library beside the content. The tree is a list (`role="list"`, named by `label`), every `el-tree-item` in it is an entry, and an entry holds the entries below it, to any depth. ([#193](https://github.com/webtides/element-library/issues/193))
20
+ - To assistive technology it is nested lists of links with a button per branch, not a `role="tree"`: the entries stay links, and they work before the script has run. The readme says why.
21
+ - The keys of the WAI-ARIA tree view pattern, on top of the Tab key: up and down between the entries that are shown, right opens a branch or goes into it, left closes it or goes to the entry above, Home and End. The other way round for left and right in a text that runs from right to left.
22
+ - `--el-tree-indent` is how far the entries of a level stand in from the ones above, `--el-space-4` unset.
23
+ - The tree keeps no state: which branches are open is the `open` attribute of the entries. `tree-item-toggle` of an entry bubbles through the tree.
@@ -0,0 +1,3 @@
1
+ import { define } from './tree.js';
2
+
3
+ define();
@@ -0,0 +1,138 @@
1
+ import { TemplateElement, defineElement, html, spreadAttributes } from '@webtides/element-js';
2
+ import { activeElement } from '../../utils/focus.js';
3
+ import style from './tree.style.js';
4
+
5
+ /**
6
+ * A tree: entries that open and close, for folders, categories and a library beside the content.
7
+ * The tree is a list; every `el-tree-item` in it is an entry, and an entry holds the entries
8
+ * below it. An entry is a link, and one with entries below it has a button that opens and closes
9
+ * them.
10
+ *
11
+ * To assistive technology it is what it is in the markup: nested lists of links, each branch with
12
+ * a button that says whether it is open. It has no `role="tree"`: the links stay links, and they
13
+ * work before the script has run. The script adds the arrow keys of a tree.
14
+ *
15
+ * @element el-tree
16
+ *
17
+ * @slot - The entries of the first level: `el-tree-item` elements.
18
+ *
19
+ * @csspart base - The list of the first level (`role="list"`).
20
+ *
21
+ * @cssproperty --el-tree-indent - How far the entries of a level stand in from the ones of the
22
+ * level above. Unset, it is `--el-space-4`, and `1rem` without a theme. Read by the entries, so
23
+ * it can be set on the tree or for the page.
24
+ *
25
+ * @property {string} label - The name of the tree for assistive technology. Unset, the tree has
26
+ * none.
27
+ */
28
+ export default class Tree extends TemplateElement {
29
+ constructor() {
30
+ super({
31
+ styles: [style],
32
+ shadowRender: true,
33
+ });
34
+ }
35
+
36
+ properties() {
37
+ return {
38
+ label: '',
39
+ };
40
+ }
41
+
42
+ events() {
43
+ return {
44
+ this: {
45
+ keydown: (event) => this._onKeydown(event),
46
+ },
47
+ };
48
+ }
49
+
50
+ /**
51
+ * The entries that are shown, in their order: every entry that is in no closed branch. An
52
+ * entry is asked for the control the focus goes to, see `focusTarget` of `el-tree-item`; one
53
+ * that has none (a name without a link and without entries below it) is passed.
54
+ * @private
55
+ * @returns {HTMLElement[]}
56
+ */
57
+ _shownItems() {
58
+ const isShown = (item) => {
59
+ for (let parent = this._parentOf(item); parent; parent = this._parentOf(parent)) {
60
+ if (!parent.open) return false;
61
+ }
62
+ return true;
63
+ };
64
+ return [...this.querySelectorAll('el-tree-item')].filter((item) => item.focusTarget && isShown(item));
65
+ }
66
+
67
+ /**
68
+ * The entry an entry is below, or `null` for one of the first level.
69
+ * @private
70
+ * @param {Element} item
71
+ * @returns {Element | null}
72
+ */
73
+ _parentOf(item) {
74
+ const parent = item.parentElement?.closest('el-tree-item');
75
+ return parent && this.contains(parent) ? parent : null;
76
+ }
77
+
78
+ /**
79
+ * The keys of the WAI-ARIA tree view pattern. Up and down go to the entry before and after
80
+ * among the ones that are shown, Home and End to the first and the last. Right opens a branch,
81
+ * and goes to its first entry when it is open; left closes it, and goes to the entry above
82
+ * when it is closed or has nothing below it. In a text that runs from right to left, the two
83
+ * are the other way round.
84
+ * @private
85
+ * @param {KeyboardEvent} event
86
+ */
87
+ _onKeydown(event) {
88
+ if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.isComposing) return;
89
+
90
+ // The entry the focus is in: on its link, or on the button that opens it.
91
+ const focused = activeElement();
92
+ const current = event
93
+ .composedPath()
94
+ .find((node) => node instanceof Element && node.localName === 'el-tree-item' && this.contains(node));
95
+ if (!current || !current.shadowRoot?.contains(focused)) return;
96
+
97
+ const items = this._shownItems();
98
+ const index = items.indexOf(current);
99
+ const rtl = getComputedStyle(this).direction === 'rtl';
100
+ const [inwards, outwards] = rtl ? ['ArrowLeft', 'ArrowRight'] : ['ArrowRight', 'ArrowLeft'];
101
+ const focus = (item) => item?.focusTarget?.focus();
102
+
103
+ const keys = {
104
+ ArrowDown: () => focus(items[index + 1]),
105
+ ArrowUp: () => focus(items[index - 1]),
106
+ Home: () => focus(items[0]),
107
+ End: () => focus(items[items.length - 1]),
108
+ [inwards]: () => {
109
+ if (!current.hasItems) return;
110
+ if (!current.open) current.toggle(true);
111
+ else focus(items[index + 1]);
112
+ },
113
+ [outwards]: () => {
114
+ if (current.hasItems && current.open) current.toggle(false);
115
+ else focus(this._parentOf(current));
116
+ },
117
+ };
118
+ if (!Object.hasOwn(keys, event.key)) return;
119
+
120
+ // The keys would scroll the page.
121
+ event.preventDefault();
122
+ keys[event.key]();
123
+ }
124
+
125
+ template() {
126
+ // The role is inside of the shadow root, not on the element: it is part of the
127
+ // server-rendered markup that way, and needs no script.
128
+ return html`
129
+ <div part="base" class="tree" role="list" ${spreadAttributes({ 'aria-label': this.label || undefined })}>
130
+ <slot></slot>
131
+ </div>
132
+ `;
133
+ }
134
+ }
135
+
136
+ export function define() {
137
+ defineElement('el-tree', Tree);
138
+ }
@@ -0,0 +1,119 @@
1
+ # Tree
2
+
3
+ `tree` shows entries that open and close: folders, categories, the library beside the content. The tree is a list; every [`el-tree-item`](../tree-item/tree-item.readme.md) in it is an entry, and an entry holds the entries below it. An entry is a link, and one with entries below it has a button that opens and closes them.
4
+
5
+ ## How to use
6
+
7
+ #### Install
8
+
9
+ ```sh
10
+ npm i --save @webtides/element-library
11
+ ```
12
+
13
+ #### Use
14
+
15
+ ```js
16
+ import '@webtides/element-library/tree/define';
17
+ import '@webtides/element-library/tree-item/define';
18
+ ```
19
+
20
+ ```html
21
+ <el-tree label="Folders">
22
+ <el-tree-item label="Inbox" href="/inbox" open="true">
23
+ <span slot="end">12</span>
24
+ <el-tree-item label="Work" href="/inbox/work" current="true"></el-tree-item>
25
+ <el-tree-item label="Private" href="/inbox/private"></el-tree-item>
26
+ </el-tree-item>
27
+ <el-tree-item label="Drafts" href="/drafts"></el-tree-item>
28
+ </el-tree>
29
+ ```
30
+
31
+ > Boolean attributes are passed as strings (`open="true"`), matching the rest of the library.
32
+
33
+ ## API
34
+
35
+ #### Properties/Attributes
36
+
37
+ | Name | Type | Default | Description |
38
+ | ------- | -------- | ------- | ------------------------------------------------------------------------ |
39
+ | `label` | `string` | `''` | The name of the tree for assistive technology. Unset, the tree has none. |
40
+
41
+ #### Methods
42
+
43
+ _None._
44
+
45
+ #### Events
46
+
47
+ _None of its own. `tree-item-toggle` of an entry bubbles through the tree: listen for it there to keep the open branches._
48
+
49
+ #### Slots
50
+
51
+ | Name | Description |
52
+ | --------- | -------------------------------------------------------- |
53
+ | (default) | The entries of the first level: `el-tree-item` elements. |
54
+
55
+ #### CSS Parts
56
+
57
+ | Name | Description |
58
+ | ------ | -------------------------------------------- |
59
+ | `base` | The list of the first level (`role="list"`). |
60
+
61
+ #### CSS Custom Properties
62
+
63
+ | Name | Default | Description |
64
+ | --- | --- | --- |
65
+ | `--el-tree-indent` | `--el-space-4` | How far the entries of a level stand in from the ones of the level above. Read by the entries, so it can be set on the tree or for the page. Without a theme it is `1rem`. |
66
+
67
+ ## Open branches
68
+
69
+ Which branches are open is said by the `open` attribute of the entries, and by nothing else: the tree keeps no state of its own. So the page can render it, on a server as well, and keep it:
70
+
71
+ ```js
72
+ tree.addEventListener('tree-item-toggle', (event) => {
73
+ // The entry itself, not one further up: the event bubbles.
74
+ remember(event.target.id, event.detail.open);
75
+ });
76
+ ```
77
+
78
+ A branch that holds the current entry is not opened by the tree. Render `open="true"` on the entries above the current one.
79
+
80
+ ## What it is, and what it is not
81
+
82
+ To assistive technology the tree is what its markup says: a list of links, with a list below each entry that has entries, and a button per branch that says whether the branch is open (`aria-expanded`). It has no `role="tree"`.
83
+
84
+ That is a decision. `role="tree"` makes a widget of the list: a screen reader stops reading it as links, and its user has to know the keys of a tree and has nothing before the script has run. The WAI-ARIA Authoring Practices advise against it for a navigation. As nested lists the entries stay links: they are in the list of links of a screen reader, they say "current page" and "visited", and they work without JavaScript.
85
+
86
+ What the tree takes from the tree view pattern is its keyboard, on top of the Tab key.
87
+
88
+ ## Keyboard
89
+
90
+ Every link and every button of a branch is a stop of the Tab key, as on any page. With the focus on an entry, the script adds the keys of the WAI-ARIA tree view pattern:
91
+
92
+ | Key | What it does |
93
+ | --- | --- |
94
+ | Down arrow, up arrow | Moves the focus to the next and the previous entry that is shown. It stops at the ends. |
95
+ | Right arrow | Opens a closed branch. On an open one, moves the focus to its first entry. |
96
+ | Left arrow | Closes an open branch. On a closed one, or an entry without entries below, moves the focus to the entry above. |
97
+ | Home, End | Moves the focus to the first and the last entry that is shown. |
98
+ | Enter | Follows the link, as on any link. |
99
+
100
+ In a text that runs from right to left, the left arrow opens and goes in, and the right arrow closes and goes out.
101
+
102
+ ## Accessibility
103
+
104
+ - The tree has `role="list"`, every entry `role="listitem"`, and the entries below an entry are a list of their own: a screen reader says how many entries a level has.
105
+ - `label` names the tree. A tree that is the navigation of a page belongs into a `<nav>` of the page, which carries the name then.
106
+ - The entry of the page the user is on has `aria-current="page"`, see [`el-tree-item`](../tree-item/tree-item.readme.md#the-current-entry).
107
+ - The button of a branch is named by the name of its entry and says whether the branch is open.
108
+ - On a touch screen (`@media (any-pointer: coarse)`) a row is at least `--el-touch-target` high, and the button of a branch is that wide and high.
109
+
110
+ ## Server-side rendering
111
+
112
+ The lists, the links, the buttons and the open branches are part of the server-rendered markup (Declarative Shadow DOM): the stylesheet of an entry reads its `open` attribute. A server-rendered tree shows its open branches before the elements take over and looks the same after, and its links work without JavaScript. The script adds the opening and closing and the arrow keys.
113
+
114
+ The `hidden` attribute hides the tree, and an entry.
115
+
116
+ ## What it does not do
117
+
118
+ - No moving of entries by dragging, no renaming in place, no checkbox per entry.
119
+ - No loading of the entries below when a branch opens: the entries are in the page.
@@ -0,0 +1,16 @@
1
+ import hostStyle from '../../styles/host.style.js';
2
+
3
+ const css = String.raw;
4
+
5
+ const style = css`
6
+ :host {
7
+ display: block;
8
+ }
9
+
10
+ .tree {
11
+ font-family: var(--el-font-family, inherit);
12
+ line-height: var(--el-line-height, inherit);
13
+ }
14
+ `;
15
+
16
+ export default [hostStyle(), style].join('\n');
@@ -0,0 +1,23 @@
1
+ # Change Log
2
+
3
+ All notable changes to this component live here. Versions refer to the parent `@webtides/element-library` release (see root [`CHANGELOG.md`](../../../CHANGELOG.md)); components no longer version independently.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/).
6
+
7
+ <!--
8
+ When your PR touches this component, add an entry under Unreleased and
9
+ mirror it (prefixed with the component name) in root CHANGELOG.md.
10
+ Uncomment headings as needed.
11
+ -->
12
+
13
+ ## Unreleased
14
+
15
+ ## [0.4.0] - 2026-11-27
16
+
17
+ ### Added
18
+
19
+ - Initial `el-tree-item`: one entry of an `el-tree`, an item of its list (`role="listitem"`), with the entries below it in a list of their own. It has an icon at the start (`start` slot), its name (`label`, or the `label` slot) and a count at the end (`end`). ([#193](https://github.com/webtides/element-library/issues/193))
20
+ - With `href` the name is a native link whose target is the whole row. An entry that also has entries below it gets a button that opens and closes them, named by the name of the entry, with `aria-expanded`. Without `href`, an entry with entries below it is that button as a whole.
21
+ - `open` is the state of a branch, reflected to the attribute. The stylesheet reads the attribute: a server-rendered entry shows its entries, or hides them, from the first paint. The button, the arrow keys and `toggle()` change it and fire `tree-item-toggle`; setting `open` from a script fires nothing.
22
+ - `current` marks the entry of the page the user is on: `aria-current="page"`, a tint, a bar at the start in the accent colour and a heavier name. The bar is a border, so it stays where the user forces colours.
23
+ - A row is as wide as the tree on every level, and what stands in it is moved in by `--el-tree-indent` per level. A long name breaks, inside of a word where it has to. On a touch screen a row is at least `--el-touch-target` high, and the button of a branch that wide and high.
@@ -0,0 +1,3 @@
1
+ import { define } from './tree-item.js';
2
+
3
+ define();
@@ -0,0 +1,3 @@
1
+ export default {
2
+ TOGGLE: 'tree-item-toggle',
3
+ };