@webtides/element-library 0.3.0 → 0.4.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 (199) hide show
  1. package/CHANGELOG.md +208 -0
  2. package/README.md +72 -56
  3. package/all.js +16 -0
  4. package/catalog.js +17 -1
  5. package/custom-elements.json +14731 -10193
  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 +45 -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 +1073 -0
  20. package/src/components/app-frame/app-frame.readme.md +416 -0
  21. package/src/components/app-frame/app-frame.style.js +527 -0
  22. package/src/components/button/button.changelog.md +25 -0
  23. package/src/components/button/button.events.js +3 -0
  24. package/src/components/button/button.js +209 -14
  25. package/src/components/button/button.readme.md +82 -6
  26. package/src/components/button/button.style.js +161 -7
  27. package/src/components/checkbox-field/checkbox-field.changelog.md +6 -0
  28. package/src/components/checkbox-field/checkbox-field.js +7 -1
  29. package/src/components/description-list/description-list.changelog.md +25 -0
  30. package/src/components/description-list/description-list.define.js +3 -0
  31. package/src/components/description-list/description-list.js +44 -0
  32. package/src/components/description-list/description-list.readme.md +135 -0
  33. package/src/components/description-list/description-list.style.js +140 -0
  34. package/src/components/dialog/dialog.changelog.md +7 -0
  35. package/src/components/dialog/dialog.readme.md +5 -0
  36. package/src/components/dialog/dialog.style.js +17 -2
  37. package/src/components/drawer/drawer.changelog.md +7 -0
  38. package/src/components/drawer/drawer.readme.md +7 -6
  39. package/src/components/drawer/drawer.style.js +35 -2
  40. package/src/components/dropdown/dropdown.readme.md +6 -1
  41. package/src/components/list/list.changelog.md +24 -0
  42. package/src/components/list/list.define.js +3 -0
  43. package/src/components/list/list.js +66 -0
  44. package/src/components/list/list.readme.md +122 -0
  45. package/src/components/list/list.style.js +56 -0
  46. package/src/components/list-item/list-item.changelog.md +24 -0
  47. package/src/components/list-item/list-item.define.js +3 -0
  48. package/src/components/list-item/list-item.js +128 -0
  49. package/src/components/list-item/list-item.readme.md +126 -0
  50. package/src/components/list-item/list-item.style.js +234 -0
  51. package/src/components/menu/menu.changelog.md +27 -0
  52. package/src/components/menu/menu.define.js +3 -0
  53. package/src/components/menu/menu.events.js +5 -0
  54. package/src/components/menu/menu.js +570 -0
  55. package/src/components/menu/menu.readme.md +272 -0
  56. package/src/components/menu/menu.style.js +55 -0
  57. package/src/components/menu-group/menu-group.changelog.md +20 -0
  58. package/src/components/menu-group/menu-group.define.js +3 -0
  59. package/src/components/menu-group/menu-group.js +44 -0
  60. package/src/components/menu-group/menu-group.readme.md +74 -0
  61. package/src/components/menu-group/menu-group.style.js +38 -0
  62. package/src/components/menu-item/menu-item.changelog.md +24 -0
  63. package/src/components/menu-item/menu-item.define.js +3 -0
  64. package/src/components/menu-item/menu-item.js +130 -0
  65. package/src/components/menu-item/menu-item.readme.md +94 -0
  66. package/src/components/menu-item/menu-item.style.js +87 -0
  67. package/src/components/nav/nav.changelog.md +35 -0
  68. package/src/components/nav/nav.define.js +3 -0
  69. package/src/components/nav/nav.js +212 -0
  70. package/src/components/nav/nav.readme.md +248 -0
  71. package/src/components/nav/nav.style.js +269 -0
  72. package/src/components/nav-item/nav-item.changelog.md +25 -0
  73. package/src/components/nav-item/nav-item.define.js +3 -0
  74. package/src/components/nav-item/nav-item.js +75 -0
  75. package/src/components/nav-item/nav-item.readme.md +111 -0
  76. package/src/components/nav-item/nav-item.style.js +159 -0
  77. package/src/components/pagination/pagination.changelog.md +8 -0
  78. package/src/components/pagination/pagination.js +123 -49
  79. package/src/components/pagination/pagination.readme.md +24 -6
  80. package/src/components/pagination/pagination.style.js +11 -1
  81. package/src/components/scroll-to-top/scroll-to-top.changelog.md +7 -5
  82. package/src/components/scroll-to-top/scroll-to-top.js +16 -12
  83. package/src/components/scroll-to-top/scroll-to-top.readme.md +2 -0
  84. package/src/components/segmented-field/segmented-field.changelog.md +27 -0
  85. package/src/components/segmented-field/segmented-field.define.js +3 -0
  86. package/src/components/segmented-field/segmented-field.js +175 -0
  87. package/src/components/segmented-field/segmented-field.readme.md +140 -0
  88. package/src/components/segmented-field/segmented-field.style.js +193 -0
  89. package/src/components/splitter/splitter.changelog.md +24 -0
  90. package/src/components/splitter/splitter.define.js +3 -0
  91. package/src/components/splitter/splitter.events.js +4 -0
  92. package/src/components/splitter/splitter.js +237 -0
  93. package/src/components/splitter/splitter.readme.md +164 -0
  94. package/src/components/splitter/splitter.style.js +100 -0
  95. package/src/components/status-bar/status-bar.changelog.md +25 -0
  96. package/src/components/status-bar/status-bar.define.js +3 -0
  97. package/src/components/status-bar/status-bar.js +74 -0
  98. package/src/components/status-bar/status-bar.readme.md +139 -0
  99. package/src/components/status-bar/status-bar.style.js +122 -0
  100. package/src/components/switch-field/switch-field.changelog.md +6 -0
  101. package/src/components/switch-field/switch-field.js +7 -1
  102. package/src/components/tab-group/tab-group.changelog.md +7 -0
  103. package/src/components/tab-group/tab-group.js +30 -9
  104. package/src/components/tab-group/tab-group.readme.md +14 -0
  105. package/src/components/toast/toast.changelog.md +6 -0
  106. package/src/components/toast/toast.readme.md +5 -3
  107. package/src/components/toast/toast.style.js +22 -6
  108. package/src/components/toolbar/toolbar.changelog.md +24 -0
  109. package/src/components/toolbar/toolbar.define.js +3 -0
  110. package/src/components/toolbar/toolbar.js +233 -0
  111. package/src/components/toolbar/toolbar.readme.md +156 -0
  112. package/src/components/toolbar/toolbar.style.js +49 -0
  113. package/src/components/tooltip/tooltip.changelog.md +11 -0
  114. package/src/components/tooltip/tooltip.js +51 -4
  115. package/src/components/tooltip/tooltip.readme.md +26 -1
  116. package/src/components/tree/tree.changelog.md +23 -0
  117. package/src/components/tree/tree.define.js +3 -0
  118. package/src/components/tree/tree.js +138 -0
  119. package/src/components/tree/tree.readme.md +119 -0
  120. package/src/components/tree/tree.style.js +16 -0
  121. package/src/components/tree-item/tree-item.changelog.md +23 -0
  122. package/src/components/tree-item/tree-item.define.js +3 -0
  123. package/src/components/tree-item/tree-item.events.js +3 -0
  124. package/src/components/tree-item/tree-item.js +246 -0
  125. package/src/components/tree-item/tree-item.readme.md +128 -0
  126. package/src/components/tree-item/tree-item.style.js +226 -0
  127. package/src/styles/appearance.style.js +47 -0
  128. package/src/styles/choice-group.style.js +1 -1
  129. package/src/styles/modal.style.js +14 -1
  130. package/src/styles/size.style.js +41 -0
  131. package/src/utils/focus.js +69 -0
  132. package/src/utils/scroll.js +24 -0
  133. package/types/all.d.ts +16 -0
  134. package/types/src/components/accordion/accordion.d.ts +3 -1
  135. package/types/src/components/app-bar/app-bar.d.ts +43 -0
  136. package/types/src/components/app-bar/app-bar.define.d.ts +1 -0
  137. package/types/src/components/app-bar/app-bar.style.d.ts +2 -0
  138. package/types/src/components/app-frame/app-frame.d.ts +491 -0
  139. package/types/src/components/app-frame/app-frame.define.d.ts +1 -0
  140. package/types/src/components/app-frame/app-frame.events.d.ts +7 -0
  141. package/types/src/components/app-frame/app-frame.style.d.ts +8 -0
  142. package/types/src/components/button/button.d.ts +97 -7
  143. package/types/src/components/button/button.events.d.ts +4 -0
  144. package/types/src/components/description-list/description-list.d.ts +29 -0
  145. package/types/src/components/description-list/description-list.define.d.ts +1 -0
  146. package/types/src/components/description-list/description-list.style.d.ts +2 -0
  147. package/types/src/components/list/list.d.ts +39 -0
  148. package/types/src/components/list/list.define.d.ts +1 -0
  149. package/types/src/components/list/list.style.d.ts +2 -0
  150. package/types/src/components/list-item/list-item.d.ts +62 -0
  151. package/types/src/components/list-item/list-item.define.d.ts +1 -0
  152. package/types/src/components/list-item/list-item.style.d.ts +2 -0
  153. package/types/src/components/menu/menu.d.ts +266 -0
  154. package/types/src/components/menu/menu.define.d.ts +1 -0
  155. package/types/src/components/menu/menu.events.d.ts +6 -0
  156. package/types/src/components/menu/menu.style.d.ts +2 -0
  157. package/types/src/components/menu-group/menu-group.d.ts +24 -0
  158. package/types/src/components/menu-group/menu-group.define.d.ts +1 -0
  159. package/types/src/components/menu-group/menu-group.style.d.ts +2 -0
  160. package/types/src/components/menu-item/menu-item.d.ts +59 -0
  161. package/types/src/components/menu-item/menu-item.define.d.ts +1 -0
  162. package/types/src/components/menu-item/menu-item.style.d.ts +2 -0
  163. package/types/src/components/nav/nav.d.ts +103 -0
  164. package/types/src/components/nav/nav.define.d.ts +1 -0
  165. package/types/src/components/nav/nav.style.d.ts +2 -0
  166. package/types/src/components/nav-item/nav-item.d.ts +39 -0
  167. package/types/src/components/nav-item/nav-item.define.d.ts +1 -0
  168. package/types/src/components/nav-item/nav-item.style.d.ts +2 -0
  169. package/types/src/components/pagination/pagination.d.ts +31 -2
  170. package/types/src/components/scroll-to-top/scroll-to-top.d.ts +6 -5
  171. package/types/src/components/segmented-field/segmented-field.d.ts +85 -0
  172. package/types/src/components/segmented-field/segmented-field.define.d.ts +1 -0
  173. package/types/src/components/segmented-field/segmented-field.style.d.ts +2 -0
  174. package/types/src/components/splitter/splitter.d.ts +127 -0
  175. package/types/src/components/splitter/splitter.define.d.ts +1 -0
  176. package/types/src/components/splitter/splitter.events.d.ts +5 -0
  177. package/types/src/components/splitter/splitter.style.d.ts +2 -0
  178. package/types/src/components/status-bar/status-bar.d.ts +44 -0
  179. package/types/src/components/status-bar/status-bar.define.d.ts +1 -0
  180. package/types/src/components/status-bar/status-bar.style.d.ts +2 -0
  181. package/types/src/components/tab-group/tab-group.d.ts +17 -0
  182. package/types/src/components/toolbar/toolbar.d.ts +96 -0
  183. package/types/src/components/toolbar/toolbar.define.d.ts +1 -0
  184. package/types/src/components/toolbar/toolbar.style.d.ts +2 -0
  185. package/types/src/components/tooltip/tooltip.d.ts +26 -0
  186. package/types/src/components/tree/tree.d.ts +62 -0
  187. package/types/src/components/tree/tree.define.d.ts +1 -0
  188. package/types/src/components/tree/tree.style.d.ts +2 -0
  189. package/types/src/components/tree-item/tree-item.d.ts +106 -0
  190. package/types/src/components/tree-item/tree-item.define.d.ts +1 -0
  191. package/types/src/components/tree-item/tree-item.events.d.ts +4 -0
  192. package/types/src/components/tree-item/tree-item.style.d.ts +2 -0
  193. package/types/src/styles/appearance.style.d.ts +31 -0
  194. package/types/src/styles/choice-group.style.d.ts +1 -1
  195. package/types/src/styles/modal.style.d.ts +5 -0
  196. package/types/src/styles/size.style.d.ts +24 -0
  197. package/types/src/utils/focus.d.ts +25 -0
  198. package/types/src/utils/scroll.d.ts +11 -0
  199. package/web-types.json +2530 -393
@@ -0,0 +1,233 @@
1
+ import { TemplateElement, defineElement, html, spreadAttributes } from '@webtides/element-js';
2
+ import { define as defineTooltip } from '../tooltip/tooltip.js';
3
+ import { activeElement, focusableElements } from '../../utils/focus.js';
4
+ import { hasSlotted } from '../../utils/slots.js';
5
+ import style from './toolbar.style.js';
6
+
7
+ /** A control that takes text: there the left and right arrow keys, Home and End move the caret. */
8
+ const TEXT_ENTRY =
9
+ 'textarea, select, [contenteditable=""], [contenteditable="true"], input:not([type="radio"], [type="checkbox"], [type="button"], [type="submit"], [type="reset"], [type="range"], [type="color"], [type="file"], [type="image"])';
10
+
11
+ /**
12
+ * A toolbar: the row of controls over a list or a view. It gives them one size and one
13
+ * appearance, lays them out with a gap, in lines where they do not fit into one, and with a group
14
+ * at the end, and makes them one stop of the Tab key: the arrow keys move between them.
15
+ *
16
+ * The controls are what the page writes into it: `el-button` (also as a toggle, and with an icon
17
+ * alone), `el-button-group`, `el-segmented-field`, and `el-divider` between two groups.
18
+ *
19
+ * The look is the stylesheet alone, so a server-rendered toolbar does not change when the element
20
+ * takes over. The script adds the keyboard, and the tooltips of the buttons with an icon alone.
21
+ *
22
+ * @element el-toolbar
23
+ *
24
+ * @slot - The controls of the toolbar, and `el-divider` elements between two groups of them.
25
+ * @slot end - The controls at the end of the toolbar.
26
+ *
27
+ * @csspart base - The toolbar (`role="toolbar"`): the row of the controls.
28
+ * @csspart end - The group at the end.
29
+ * @csspart tooltip - The tooltip of a button with an icon alone: an `el-tooltip`.
30
+ *
31
+ * @property {string} label - The name of the toolbar for assistive technology, "Formatting".
32
+ * Unset, the toolbar has none.
33
+ * @property {'small'|'medium'|'large'} size - The size of the controls that have none of their
34
+ * own. Default `'medium'`. Reflected to the `size` attribute.
35
+ * @property {'filled'|'outlined'|'plain'} appearance - The appearance of the buttons that have
36
+ * none of their own. Default `'plain'`. Reflected to the `appearance` attribute.
37
+ */
38
+ export default class Toolbar extends TemplateElement {
39
+ /**
40
+ * The control that had the focus last: where the Tab key comes back to.
41
+ * @private
42
+ * @type {HTMLElement | undefined}
43
+ */
44
+ _current = undefined;
45
+
46
+ /**
47
+ * Whether the toolbar has started in a browser, see `connected()`.
48
+ * @private
49
+ */
50
+ _started = false;
51
+
52
+ constructor() {
53
+ super({
54
+ styles: [style],
55
+ shadowRender: true,
56
+ // The tooltips are made for the buttons with a name of their own: one that comes or
57
+ // goes, also inside of a group, and a name that changes, ask for a new render.
58
+ // The filter names the attributes of the toolbar itself as well: element-js hears of
59
+ // them through the same observer.
60
+ mutationObserverOptions: {
61
+ childList: true,
62
+ subtree: true,
63
+ attributeFilter: ['aria-label', 'label', 'size', 'appearance'],
64
+ },
65
+ // The stylesheet selects the host by these attributes.
66
+ propertyOptions: {
67
+ size: { reflect: true },
68
+ appearance: { reflect: true },
69
+ },
70
+ });
71
+ }
72
+
73
+ properties() {
74
+ return {
75
+ label: '',
76
+ size: 'medium',
77
+ appearance: 'plain',
78
+ };
79
+ }
80
+
81
+ connected() {
82
+ // The tooltips come with the script: a server renders none, and the first render in the
83
+ // browser is the markup of the server.
84
+ this._started = true;
85
+ this.requestUpdate();
86
+ }
87
+
88
+ events() {
89
+ return {
90
+ this: {
91
+ keydown: (event) => this._onKeydown(event),
92
+ focusin: (event) => this._onFocusIn(event),
93
+ },
94
+ // A template element does not render again when a child comes, goes or changes its
95
+ // `slot` attribute. The slot tells of all three, and the event bubbles to the base.
96
+ "[part~='base']": {
97
+ slotchange: () => this.requestUpdate(),
98
+ },
99
+ };
100
+ }
101
+
102
+ /**
103
+ * The controls of the toolbar that the user can move the focus to, in their order: the ones
104
+ * at the end last, as they are shown.
105
+ * @private
106
+ * @returns {HTMLElement[]}
107
+ */
108
+ _controls() {
109
+ const controls = focusableElements(this);
110
+ const atEnd = (control) => {
111
+ let element = control;
112
+ // Out of the shadow root of a component, up to the child of the toolbar.
113
+ while (element && element.parentNode !== this) element = element.parentNode?.host ?? element.parentNode;
114
+ return element?.getAttribute?.('slot') === 'end';
115
+ };
116
+ return [...controls.filter((control) => !atEnd(control)), ...controls.filter(atEnd)];
117
+ }
118
+
119
+ /**
120
+ * The arrow keys move the focus from control to control and around the ends, Home and End go
121
+ * to the first and the last one. The Tab key leaves the toolbar.
122
+ * @private
123
+ * @param {KeyboardEvent} event
124
+ */
125
+ _onKeydown(event) {
126
+ if (event.altKey || event.ctrlKey || event.metaKey || event.isComposing) return;
127
+
128
+ const controls = this._controls();
129
+ const current = activeElement();
130
+ const index = controls.indexOf(current);
131
+ if (index === -1) return;
132
+
133
+ if (event.key === 'Tab') {
134
+ this._letTabLeave(controls, current);
135
+ return;
136
+ }
137
+
138
+ // In a control that takes text the keys move the caret.
139
+ if (current.matches(TEXT_ENTRY)) return;
140
+
141
+ const backwards = getComputedStyle(this).direction === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
142
+ const forwards = backwards === 'ArrowLeft' ? 'ArrowRight' : 'ArrowLeft';
143
+ const targets = {
144
+ [backwards]: () => controls[(index - 1 + controls.length) % controls.length],
145
+ [forwards]: () => controls[(index + 1) % controls.length],
146
+ Home: () => controls[0],
147
+ End: () => controls[controls.length - 1],
148
+ };
149
+ if (!Object.hasOwn(targets, event.key)) return;
150
+
151
+ // The keys would scroll the page, and move the choice of a group of radios: in a toolbar
152
+ // they move the focus, and Space chooses.
153
+ event.preventDefault();
154
+ targets[event.key]().focus();
155
+ }
156
+
157
+ /**
158
+ * Lets the Tab key leave the toolbar: the browser takes the key once every listener has had
159
+ * it, and goes to the next stop. Until then the other controls of the toolbar are none.
160
+ * @private
161
+ * @param {HTMLElement[]} controls
162
+ * @param {Element} current
163
+ */
164
+ _letTabLeave(controls, current) {
165
+ const others = controls.filter((control) => control !== current && !control.inert);
166
+ for (const control of others) control.inert = true;
167
+ setTimeout(() => {
168
+ for (const control of others) control.inert = false;
169
+ });
170
+ }
171
+
172
+ /**
173
+ * The Tab key comes into the toolbar at the control that had the focus last, and at the first
174
+ * one before any had it. A pointer puts the focus where it is pressed.
175
+ * @private
176
+ * @param {FocusEvent} event
177
+ */
178
+ _onFocusIn(event) {
179
+ const entered = activeElement();
180
+ const controls = this._controls();
181
+ if (!controls.includes(entered)) return;
182
+
183
+ const cameFromOutside = !event.relatedTarget || !this.contains(event.relatedTarget);
184
+ const remembered = controls.includes(this._current) ? this._current : controls[0];
185
+ if (cameFromOutside && entered !== remembered && entered.matches(':focus-visible')) {
186
+ remembered.focus();
187
+ return;
188
+ }
189
+ this._current = entered;
190
+ }
191
+
192
+ /**
193
+ * The buttons that show an icon alone: they have a name of their own for assistive technology
194
+ * (`aria-label`), which their content does not show. None before the toolbar has started: on
195
+ * a server there is no pointer to show a tooltip to.
196
+ * @private
197
+ * @returns {Element[]}
198
+ */
199
+ _namedButtons() {
200
+ if (!this._started) return [];
201
+ return [...this.querySelectorAll('el-button[aria-label]')].filter((button) =>
202
+ button.getAttribute('aria-label'),
203
+ );
204
+ }
205
+
206
+ template() {
207
+ // The role is inside of the shadow root, not on the element: it is part of the
208
+ // server-rendered markup that way, and needs no script.
209
+ return html`
210
+ <div
211
+ part="base"
212
+ class="toolbar"
213
+ role="toolbar"
214
+ ${spreadAttributes({ 'aria-label': this.label || undefined })}
215
+ >
216
+ <slot></slot>
217
+ <div part="end" class="end" ?hidden="${!hasSlotted(this, 'end')}"><slot name="end"></slot></div>
218
+ </div>
219
+ ${this._namedButtons().map(
220
+ (button) =>
221
+ html`<el-tooltip part="tooltip" type="label" placement="bottom" .anchor="${button}"
222
+ >${button.getAttribute('aria-label')}</el-tooltip
223
+ >`,
224
+ )}
225
+ `;
226
+ }
227
+ }
228
+
229
+ export function define() {
230
+ // The tooltips of the buttons with an icon alone.
231
+ defineTooltip();
232
+ defineElement('el-toolbar', Toolbar);
233
+ }
@@ -0,0 +1,156 @@
1
+ # Toolbar
2
+
3
+ `toolbar` is the row of controls over a list or a view: reply, archive, a toggle, a choice of the layout. It gives its controls one size and one appearance, lays them out with a gap and a group at the end, and makes them one stop of the Tab key, with the arrow keys between 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/toolbar/define';
17
+ import '@webtides/element-library/button/define';
18
+ import '@webtides/element-library/divider/define';
19
+ ```
20
+
21
+ ```html
22
+ <el-toolbar label="Message" size="small">
23
+ <el-button circle="true" aria-label="Reply"><svg aria-hidden="true">…</svg></el-button>
24
+ <el-button circle="true" aria-label="Forward"><svg aria-hidden="true">…</svg></el-button>
25
+ <el-divider orientation="vertical"></el-divider>
26
+ <el-button toggle="true" circle="true" aria-label="Starred"><svg aria-hidden="true">…</svg></el-button>
27
+ <el-segmented-field
28
+ name="view"
29
+ label="View"
30
+ label-screen-reader-only="true"
31
+ value="list"
32
+ options='[{"value":"list","label":"List"},{"value":"board","label":"Board"}]'
33
+ ></el-segmented-field>
34
+ <el-button slot="end" variant="brand" appearance="filled">Send</el-button>
35
+ </el-toolbar>
36
+ ```
37
+
38
+ > Boolean attributes are passed as strings (`circle="true"`), matching the rest of the library.
39
+
40
+ ## API
41
+
42
+ #### Properties/Attributes
43
+
44
+ | Name | Type | Default | Description |
45
+ | --- | --- | --- | --- |
46
+ | `label` | `string` | `''` | The name of the toolbar for assistive technology. Unset, the toolbar has none. |
47
+ | `size` | `'small' \| 'medium' \| 'large'` | `'medium'` | The size of the controls that have none of their own. Reflected to the `size` attribute. |
48
+ | `appearance` | `'filled' \| 'outlined' \| 'plain'` | `'plain'` | The appearance of the buttons that have none of their own. Reflected to the `appearance` attribute. |
49
+
50
+ #### Methods
51
+
52
+ _None._
53
+
54
+ #### Events
55
+
56
+ _None._
57
+
58
+ #### Slots
59
+
60
+ | Name | Description |
61
+ | --------- | -------------------------------------------------------------------------- |
62
+ | (default) | The controls of the toolbar, and `el-divider` elements between two groups. |
63
+ | `end` | The controls at the end of the toolbar. |
64
+
65
+ #### CSS Parts
66
+
67
+ | Name | Description |
68
+ | --------- | ------------------------------------------------------------ |
69
+ | `base` | The toolbar (`role="toolbar"`): the row of the controls. |
70
+ | `end` | The group at the end. |
71
+ | `tooltip` | The tooltip of a button with an icon alone: an `el-tooltip`. |
72
+
73
+ #### CSS Custom Properties
74
+
75
+ Reads `--el-space-2` for the gap between two controls (`0.5rem` without a theme). The controls read the tokens they read anywhere.
76
+
77
+ ## One size and one appearance
78
+
79
+ `size` and `appearance` of the toolbar are the size and the appearance of its controls: of every `el-button` in it, also inside of an `el-button-group` or as the anchor of an `el-popover`, and `size` of an `el-segmented-field` as well. A toolbar without the attributes has controls of the medium size and plain buttons.
80
+
81
+ A control that names its own keeps it. That goes for the defaults as well: `appearance="filled"` on a button keeps the button filled in a plain toolbar, and `size="medium"` keeps it medium in a small one.
82
+
83
+ ```html
84
+ <el-toolbar label="Message" size="small">
85
+ <el-button>Reply</el-button>
86
+ <!-- small, plain -->
87
+ <el-button variant="brand" appearance="filled">Send</el-button>
88
+ <!-- small, filled -->
89
+ </el-toolbar>
90
+ ```
91
+
92
+ How it works, and what follows from it:
93
+
94
+ - The toolbar does not write to its controls. It says its size and its appearance in CSS properties that are inherited, and a control reads them in its own stylesheet. The `size` and the `appearance` attribute of a button in a toolbar still say `medium` and `filled`, the defaults: a selector like `el-button[appearance='plain']` does not match it.
95
+ - A control counts as having its own when the page wrote the attribute, when a script set the property before the control was connected, or when either changes later. Setting a property to the value it already has changes nothing: to keep a default after the control is connected, write the attribute.
96
+ - A plain button of a toolbar answers to the pointer with a tint of its text colour, as an outlined button does. A button with `appearance="plain"` of its own is underlined under the pointer, as outside of a toolbar.
97
+ - Other controls of the library keep their own size in a toolbar.
98
+
99
+ ## Groups
100
+
101
+ - An `el-divider` with `orientation="vertical"` stands between two groups of controls. It is a separator to assistive technology, and the arrow keys pass it.
102
+ - An [`el-button-group`](../button-group/button-group.readme.md) is a group of buttons that touch, with a name of its own.
103
+ - What is slotted into `end` stands at the end of the toolbar: all the room that is left is in front of it.
104
+
105
+ Start and end follow the reading direction: in a text that runs from right to left the first control is at the right, and the group at the end at the left.
106
+
107
+ ## A button with an icon alone
108
+
109
+ Such a button is an `el-button` with `circle="true"`, which makes it as wide as it is high, and an `aria-label`, which is its name.
110
+
111
+ ```html
112
+ <el-button circle="true" aria-label="Archive"><svg aria-hidden="true">…</svg></el-button>
113
+ ```
114
+
115
+ The toolbar shows that name as a tooltip, for the pointer and for the focus of the keyboard: every `el-button` with an `aria-label` in the toolbar gets one, below the button. The tooltip is for the eye. A screen reader has the name already and does not read it twice.
116
+
117
+ The tooltips come with the script of the toolbar. They are `el-tooltip` elements in its shadow root (`::part(tooltip)`), so nothing is added to what the page wrote into the toolbar. The toolbar imports the tooltip, and with it `@floating-ui/dom`.
118
+
119
+ ## More controls than the width takes
120
+
121
+ The toolbar breaks into a second line where its controls do not fit into one. Every control stays in reach of the pointer and of the arrow keys, and the toolbar is never wider than its place. The group at the end still ends the toolbar, in a line of its own if it has to.
122
+
123
+ ## Keyboard
124
+
125
+ The toolbar is one stop of the Tab key, as the WAI-ARIA toolbar pattern says.
126
+
127
+ | Key | What it does |
128
+ | --- | --- |
129
+ | Tab | Moves the focus into the toolbar: to the control that had it last, or to the first one. From inside, it leaves the toolbar. |
130
+ | Right arrow, left arrow | Moves the focus to the next and the previous control, and around the ends. The other way round in a text that runs from right to left. |
131
+ | Home, End | Moves the focus to the first and the last control. |
132
+
133
+ - Disabled controls are passed.
134
+ - The options of an `el-segmented-field` are controls of the toolbar: the left and right arrow keys go through them without choosing. Space chooses the option with the focus, and the up and down arrow keys move the choice, as in a group of radios outside of a toolbar.
135
+ - In a control that takes text (an input, a select) the arrow keys, Home and End belong to that control. The Tab key leaves the toolbar from there as well.
136
+ - A click puts the focus where the pointer is.
137
+
138
+ Before the script has run, every control is a stop of the Tab key.
139
+
140
+ ## Accessibility
141
+
142
+ - The toolbar has `role="toolbar"`. Give it a `label`: a screen reader reads it when its user enters the toolbar, and a page with two toolbars needs it to tell them apart.
143
+ - Use a toolbar for three controls or more. Two buttons beside each other need none.
144
+ - On a touch screen (`@media (any-pointer: coarse)`) every `el-button` and every option of an `el-segmented-field` is at least `--el-touch-target` high and wide, in a small toolbar as well.
145
+ - An `el-segmented-field` in a toolbar needs a `label` as every field does. `label-screen-reader-only="true"` keeps it as the name of the group and does not show it.
146
+
147
+ ## Server-side rendering
148
+
149
+ The toolbar, its name and its layout are part of the server-rendered markup (Declarative Shadow DOM), and the size and the appearance of the controls are their stylesheets reading the toolbar. A server-rendered toolbar looks the same before and after the elements take over. The script adds the keyboard and the tooltips.
150
+
151
+ The `hidden` attribute hides the toolbar.
152
+
153
+ ## What it is not
154
+
155
+ - No toolbar the user arranges, and no formatting toolbar of an editor for rich text.
156
+ - No menu for the controls that do not fit: they go into a second line.
@@ -0,0 +1,49 @@
1
+ import hostStyle from '../../styles/host.style.js';
2
+ import { sizeContextStyle } from '../../styles/size.style.js';
3
+ import { appearanceContextStyle } from '../../styles/appearance.style.js';
4
+
5
+ const css = String.raw;
6
+
7
+ const style = css`
8
+ :host {
9
+ display: block;
10
+ }
11
+
12
+ /* A row with a gap, which breaks into a second line where its controls do not fit: every
13
+ control stays in reach, and the toolbar is never wider than its place. The gaps follow the
14
+ reading direction, as the order of the controls does. */
15
+ .toolbar {
16
+ display: flex;
17
+ flex-wrap: wrap;
18
+ align-items: center;
19
+ gap: var(--el-space-2, 0.5rem);
20
+ min-width: 0;
21
+ }
22
+
23
+ /* The group at the end: all the room that is left is in front of it. In a line of its own it
24
+ still stands at the end. */
25
+ .end {
26
+ display: flex;
27
+ flex-wrap: wrap;
28
+ align-items: center;
29
+ gap: var(--el-space-2, 0.5rem);
30
+ margin-inline-start: auto;
31
+ }
32
+
33
+ /* The tooltips of the buttons with an icon alone take no room. A tooltip hides itself while
34
+ it is closed, but with a stylesheet it only has once it has rendered: for a frame its text
35
+ would be a line under the toolbar. */
36
+ el-tooltip:not(:popover-open) {
37
+ display: none;
38
+ }
39
+
40
+ /* A divider between two groups is as high as a control, not as the whole row of a toolbar
41
+ that has broken into lines. */
42
+ ::slotted(el-divider) {
43
+ align-self: center;
44
+ height: 1.5em;
45
+ }
46
+ `;
47
+
48
+ // Plain is the appearance of a toolbar that names none.
49
+ export default [hostStyle(), sizeContextStyle(), appearanceContextStyle(':host', 'plain'), style].join('\n');
@@ -12,6 +12,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
12
12
 
13
13
  ## Unreleased
14
14
 
15
+ ## [0.4.0] - 2026-11-27
16
+
17
+ ### Added
18
+
19
+ - `anchor`: the anchor as an element, for one that an id cannot name: an element in another tree than the tooltip, the light DOM of a component whose shadow root the tooltip is in. A property only, and it comes before `for`. ([#194](https://github.com/webtides/element-library/issues/194))
20
+ - `type` (`'description'` by default, or `'label'`): a tooltip of the type `label` shows the name its anchor already has, of a button with an icon alone for example. It does not describe the anchor (`aria-describedby` is not written) and is hidden from assistive technology, which would read the name twice. ([#194](https://github.com/webtides/element-library/issues/194))
21
+
22
+ ### Fixed
23
+
24
+ - In Safari a tooltip could stay shown after its anchor had lost the pointer or the focus: `open` was `false`, and the tooltip was still there. The tooltip read its own state back (`states.has('open')`) to know whether there was something to close, and WebKit forgets what was added to the states of an element a moment later, while `:state(open)` still matches. The tooltip keeps a field of its own now.
25
+
15
26
  ## [0.3.0] - 2026-11-17
16
27
 
17
28
  ### Added
@@ -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();