@webtides/element-library 0.3.1 → 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 (195) hide show
  1. package/CHANGELOG.md +193 -0
  2. package/README.md +72 -56
  3. package/all.js +16 -0
  4. package/catalog.js +17 -1
  5. package/custom-elements.json +14723 -10220
  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 +15 -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 +161 -7
  27. package/src/components/description-list/description-list.changelog.md +25 -0
  28. package/src/components/description-list/description-list.define.js +3 -0
  29. package/src/components/description-list/description-list.js +44 -0
  30. package/src/components/description-list/description-list.readme.md +135 -0
  31. package/src/components/description-list/description-list.style.js +140 -0
  32. package/src/components/dialog/dialog.changelog.md +7 -0
  33. package/src/components/dialog/dialog.readme.md +5 -0
  34. package/src/components/dialog/dialog.style.js +17 -2
  35. package/src/components/drawer/drawer.changelog.md +7 -0
  36. package/src/components/drawer/drawer.readme.md +7 -6
  37. package/src/components/drawer/drawer.style.js +35 -2
  38. package/src/components/dropdown/dropdown.readme.md +6 -1
  39. package/src/components/list/list.changelog.md +24 -0
  40. package/src/components/list/list.define.js +3 -0
  41. package/src/components/list/list.js +66 -0
  42. package/src/components/list/list.readme.md +122 -0
  43. package/src/components/list/list.style.js +56 -0
  44. package/src/components/list-item/list-item.changelog.md +24 -0
  45. package/src/components/list-item/list-item.define.js +3 -0
  46. package/src/components/list-item/list-item.js +128 -0
  47. package/src/components/list-item/list-item.readme.md +126 -0
  48. package/src/components/list-item/list-item.style.js +234 -0
  49. package/src/components/menu/menu.changelog.md +27 -0
  50. package/src/components/menu/menu.define.js +3 -0
  51. package/src/components/menu/menu.events.js +5 -0
  52. package/src/components/menu/menu.js +570 -0
  53. package/src/components/menu/menu.readme.md +272 -0
  54. package/src/components/menu/menu.style.js +55 -0
  55. package/src/components/menu-group/menu-group.changelog.md +20 -0
  56. package/src/components/menu-group/menu-group.define.js +3 -0
  57. package/src/components/menu-group/menu-group.js +44 -0
  58. package/src/components/menu-group/menu-group.readme.md +74 -0
  59. package/src/components/menu-group/menu-group.style.js +38 -0
  60. package/src/components/menu-item/menu-item.changelog.md +24 -0
  61. package/src/components/menu-item/menu-item.define.js +3 -0
  62. package/src/components/menu-item/menu-item.js +130 -0
  63. package/src/components/menu-item/menu-item.readme.md +94 -0
  64. package/src/components/menu-item/menu-item.style.js +87 -0
  65. package/src/components/nav/nav.changelog.md +35 -0
  66. package/src/components/nav/nav.define.js +3 -0
  67. package/src/components/nav/nav.js +212 -0
  68. package/src/components/nav/nav.readme.md +248 -0
  69. package/src/components/nav/nav.style.js +269 -0
  70. package/src/components/nav-item/nav-item.changelog.md +25 -0
  71. package/src/components/nav-item/nav-item.define.js +3 -0
  72. package/src/components/nav-item/nav-item.js +75 -0
  73. package/src/components/nav-item/nav-item.readme.md +111 -0
  74. package/src/components/nav-item/nav-item.style.js +159 -0
  75. package/src/components/pagination/pagination.changelog.md +8 -0
  76. package/src/components/pagination/pagination.js +123 -49
  77. package/src/components/pagination/pagination.readme.md +24 -6
  78. package/src/components/pagination/pagination.style.js +11 -1
  79. package/src/components/scroll-to-top/scroll-to-top.changelog.md +7 -5
  80. package/src/components/scroll-to-top/scroll-to-top.js +16 -12
  81. package/src/components/scroll-to-top/scroll-to-top.readme.md +2 -0
  82. package/src/components/segmented-field/segmented-field.changelog.md +27 -0
  83. package/src/components/segmented-field/segmented-field.define.js +3 -0
  84. package/src/components/segmented-field/segmented-field.js +175 -0
  85. package/src/components/segmented-field/segmented-field.readme.md +140 -0
  86. package/src/components/segmented-field/segmented-field.style.js +193 -0
  87. package/src/components/splitter/splitter.changelog.md +24 -0
  88. package/src/components/splitter/splitter.define.js +3 -0
  89. package/src/components/splitter/splitter.events.js +4 -0
  90. package/src/components/splitter/splitter.js +237 -0
  91. package/src/components/splitter/splitter.readme.md +164 -0
  92. package/src/components/splitter/splitter.style.js +100 -0
  93. package/src/components/status-bar/status-bar.changelog.md +25 -0
  94. package/src/components/status-bar/status-bar.define.js +3 -0
  95. package/src/components/status-bar/status-bar.js +74 -0
  96. package/src/components/status-bar/status-bar.readme.md +139 -0
  97. package/src/components/status-bar/status-bar.style.js +122 -0
  98. package/src/components/tab-group/tab-group.changelog.md +7 -0
  99. package/src/components/tab-group/tab-group.js +30 -9
  100. package/src/components/tab-group/tab-group.readme.md +14 -0
  101. package/src/components/toast/toast.changelog.md +6 -0
  102. package/src/components/toast/toast.readme.md +5 -3
  103. package/src/components/toast/toast.style.js +22 -6
  104. package/src/components/toolbar/toolbar.changelog.md +24 -0
  105. package/src/components/toolbar/toolbar.define.js +3 -0
  106. package/src/components/toolbar/toolbar.js +233 -0
  107. package/src/components/toolbar/toolbar.readme.md +156 -0
  108. package/src/components/toolbar/toolbar.style.js +49 -0
  109. package/src/components/tooltip/tooltip.changelog.md +11 -0
  110. package/src/components/tooltip/tooltip.js +51 -4
  111. package/src/components/tooltip/tooltip.readme.md +26 -1
  112. package/src/components/tree/tree.changelog.md +23 -0
  113. package/src/components/tree/tree.define.js +3 -0
  114. package/src/components/tree/tree.js +138 -0
  115. package/src/components/tree/tree.readme.md +119 -0
  116. package/src/components/tree/tree.style.js +16 -0
  117. package/src/components/tree-item/tree-item.changelog.md +23 -0
  118. package/src/components/tree-item/tree-item.define.js +3 -0
  119. package/src/components/tree-item/tree-item.events.js +3 -0
  120. package/src/components/tree-item/tree-item.js +246 -0
  121. package/src/components/tree-item/tree-item.readme.md +128 -0
  122. package/src/components/tree-item/tree-item.style.js +226 -0
  123. package/src/styles/appearance.style.js +47 -0
  124. package/src/styles/choice-group.style.js +1 -1
  125. package/src/styles/modal.style.js +14 -1
  126. package/src/styles/size.style.js +41 -0
  127. package/src/utils/focus.js +69 -0
  128. package/src/utils/scroll.js +24 -0
  129. package/types/all.d.ts +16 -0
  130. package/types/src/components/accordion/accordion.d.ts +3 -1
  131. package/types/src/components/app-bar/app-bar.d.ts +43 -0
  132. package/types/src/components/app-bar/app-bar.define.d.ts +1 -0
  133. package/types/src/components/app-bar/app-bar.style.d.ts +2 -0
  134. package/types/src/components/app-frame/app-frame.d.ts +491 -0
  135. package/types/src/components/app-frame/app-frame.define.d.ts +1 -0
  136. package/types/src/components/app-frame/app-frame.events.d.ts +7 -0
  137. package/types/src/components/app-frame/app-frame.style.d.ts +8 -0
  138. package/types/src/components/button/button.d.ts +61 -0
  139. package/types/src/components/button/button.events.d.ts +4 -0
  140. package/types/src/components/description-list/description-list.d.ts +29 -0
  141. package/types/src/components/description-list/description-list.define.d.ts +1 -0
  142. package/types/src/components/description-list/description-list.style.d.ts +2 -0
  143. package/types/src/components/list/list.d.ts +39 -0
  144. package/types/src/components/list/list.define.d.ts +1 -0
  145. package/types/src/components/list/list.style.d.ts +2 -0
  146. package/types/src/components/list-item/list-item.d.ts +62 -0
  147. package/types/src/components/list-item/list-item.define.d.ts +1 -0
  148. package/types/src/components/list-item/list-item.style.d.ts +2 -0
  149. package/types/src/components/menu/menu.d.ts +266 -0
  150. package/types/src/components/menu/menu.define.d.ts +1 -0
  151. package/types/src/components/menu/menu.events.d.ts +6 -0
  152. package/types/src/components/menu/menu.style.d.ts +2 -0
  153. package/types/src/components/menu-group/menu-group.d.ts +24 -0
  154. package/types/src/components/menu-group/menu-group.define.d.ts +1 -0
  155. package/types/src/components/menu-group/menu-group.style.d.ts +2 -0
  156. package/types/src/components/menu-item/menu-item.d.ts +59 -0
  157. package/types/src/components/menu-item/menu-item.define.d.ts +1 -0
  158. package/types/src/components/menu-item/menu-item.style.d.ts +2 -0
  159. package/types/src/components/nav/nav.d.ts +103 -0
  160. package/types/src/components/nav/nav.define.d.ts +1 -0
  161. package/types/src/components/nav/nav.style.d.ts +2 -0
  162. package/types/src/components/nav-item/nav-item.d.ts +39 -0
  163. package/types/src/components/nav-item/nav-item.define.d.ts +1 -0
  164. package/types/src/components/nav-item/nav-item.style.d.ts +2 -0
  165. package/types/src/components/pagination/pagination.d.ts +31 -2
  166. package/types/src/components/scroll-to-top/scroll-to-top.d.ts +6 -5
  167. package/types/src/components/segmented-field/segmented-field.d.ts +85 -0
  168. package/types/src/components/segmented-field/segmented-field.define.d.ts +1 -0
  169. package/types/src/components/segmented-field/segmented-field.style.d.ts +2 -0
  170. package/types/src/components/splitter/splitter.d.ts +127 -0
  171. package/types/src/components/splitter/splitter.define.d.ts +1 -0
  172. package/types/src/components/splitter/splitter.events.d.ts +5 -0
  173. package/types/src/components/splitter/splitter.style.d.ts +2 -0
  174. package/types/src/components/status-bar/status-bar.d.ts +44 -0
  175. package/types/src/components/status-bar/status-bar.define.d.ts +1 -0
  176. package/types/src/components/status-bar/status-bar.style.d.ts +2 -0
  177. package/types/src/components/tab-group/tab-group.d.ts +17 -0
  178. package/types/src/components/toolbar/toolbar.d.ts +96 -0
  179. package/types/src/components/toolbar/toolbar.define.d.ts +1 -0
  180. package/types/src/components/toolbar/toolbar.style.d.ts +2 -0
  181. package/types/src/components/tooltip/tooltip.d.ts +26 -0
  182. package/types/src/components/tree/tree.d.ts +62 -0
  183. package/types/src/components/tree/tree.define.d.ts +1 -0
  184. package/types/src/components/tree/tree.style.d.ts +2 -0
  185. package/types/src/components/tree-item/tree-item.d.ts +106 -0
  186. package/types/src/components/tree-item/tree-item.define.d.ts +1 -0
  187. package/types/src/components/tree-item/tree-item.events.d.ts +4 -0
  188. package/types/src/components/tree-item/tree-item.style.d.ts +2 -0
  189. package/types/src/styles/appearance.style.d.ts +31 -0
  190. package/types/src/styles/choice-group.style.d.ts +1 -1
  191. package/types/src/styles/modal.style.d.ts +5 -0
  192. package/types/src/styles/size.style.d.ts +24 -0
  193. package/types/src/utils/focus.d.ts +25 -0
  194. package/types/src/utils/scroll.d.ts +11 -0
  195. package/web-types.json +2530 -393
@@ -0,0 +1,272 @@
1
+ # Menu
2
+
3
+ `menu` is a menu button: a button that opens a list of actions. "Edit, Duplicate, Delete" for a row of a table, the account in a header, "More" at the end of a toolbar. The button is what the page puts into the `trigger` slot, and the actions are [`el-menu-item`](../menu-item/menu-item.readme.md) elements.
4
+
5
+ A screen reader announces it as a menu, the keyboard moves through its entries, and its panel floats: it is in the top layer of the browser, so nothing clips it and it moves nothing on the page.
6
+
7
+ ## How to use
8
+
9
+ #### Install
10
+
11
+ ```sh
12
+ npm i --save @webtides/element-library
13
+ ```
14
+
15
+ #### Use
16
+
17
+ ```js
18
+ import '@webtides/element-library/menu/define';
19
+ import '@webtides/element-library/menu-item/define';
20
+ ```
21
+
22
+ ```html
23
+ <el-menu>
24
+ <el-button slot="trigger" caret="true">More</el-button>
25
+ <el-menu-item value="edit">Edit</el-menu-item>
26
+ <el-menu-item value="duplicate">Duplicate</el-menu-item>
27
+ <el-menu-item value="delete" variant="danger">Delete</el-menu-item>
28
+ </el-menu>
29
+ ```
30
+
31
+ ```js
32
+ document.querySelector('el-menu').addEventListener('menu-select', (event) => {
33
+ console.log(event.detail.value); // 'edit'
34
+ });
35
+ ```
36
+
37
+ > Boolean attributes are passed as strings (`open="true"`), matching the rest of the library.
38
+
39
+ ## API
40
+
41
+ #### Properties/Attributes
42
+
43
+ | Name | Type | Default | Description |
44
+ | --- | --- | --- | --- |
45
+ | `open` | `boolean` | `false` | Whether the menu is shown. Reflected to the `open` attribute. |
46
+ | `label` | `string` | `''` | The name of the menu for assistive technology. Without one the menu has the name of its button. |
47
+ | `placement` | `string` | `'bottom-start'` | The side of the button the menu is placed at: `top`, `bottom`, `left` or `right`, each also with `-start` or `-end`. |
48
+ | `distance` | `number` | `4` | The gap between the button and the menu, in pixels. |
49
+
50
+ #### Methods
51
+
52
+ | Name | Description |
53
+ | --- | --- |
54
+ | `show()` | Opens the menu, with the focus on its first entry. |
55
+ | `hide()` | Closes the menu. |
56
+ | `toggle()` | Opens the menu when it is closed, and closes it when open. |
57
+ | `showAt(place, opener?)` | Opens the menu somewhere else than at its own button: at an element of the page, or at a point `{ x, y }` of the viewport. `opener` is what it is opened for. |
58
+
59
+ #### Read-only properties
60
+
61
+ | Name | Type | Description |
62
+ | --- | --- | --- |
63
+ | `opener` | `Element \| undefined` | What the menu is open for: the row or the button of `showAt()`, or its own button. Nothing while it is closed. |
64
+
65
+ #### Events
66
+
67
+ | Name | Detail | Description |
68
+ | --- | --- | --- |
69
+ | `menu-select` | `{ item: HTMLElement, value: string, opener: Element }` | Fired when the user has chosen an entry: the `el-menu-item`, its `value`, and what the menu was opened for. The menu closes after it. |
70
+ | `menu-show` | | Fired when the menu has opened. |
71
+ | `menu-hide` | | Fired when the menu has closed. |
72
+
73
+ #### Slots
74
+
75
+ | Name | Description |
76
+ | --- | --- |
77
+ | (default) | The entries: `el-menu-item` elements, in `el-menu-group` elements where they are divided into groups. An `el-divider` is a line between two of them. |
78
+ | `trigger` | The button that opens the menu. A menu that is opened with `showAt()` alone needs none. |
79
+
80
+ #### CSS Parts
81
+
82
+ | Name | Description |
83
+ | --------- | ------------------------------------------------------------------------------------ |
84
+ | `trigger` | Forwarded onto the `trigger` slot. |
85
+ | `panel` | The floating panel, which is the menu: background, border, radius, elevation, width. |
86
+
87
+ #### CSS States
88
+
89
+ | Name | Description |
90
+ | ------ | -------------------------------------------------------------- |
91
+ | `open` | Set while the menu is shown. Style with `el-menu:state(open)`. |
92
+
93
+ #### CSS Custom Properties
94
+
95
+ | Name | Default | Description |
96
+ | --------------------- | ------- | ------------------------------- |
97
+ | `--el-menu-min-width` | `10rem` | The least width of the menu. |
98
+ | `--el-menu-max-width` | `20rem` | The greatest width of the menu. |
99
+
100
+ Reads `--el-color-bg` and `--el-color-fg` for its surface and its text (the colours of the system without a theme: a floating surface has to be readable over the page), `--el-color-border` and `--el-border-width` for its border, `--el-radius-lg`, `--el-shadow-lg`, `--el-space-1` for its padding and `--el-font-size-sm` for its text.
101
+
102
+ ## The button
103
+
104
+ Any button goes into the `trigger` slot: an `el-button`, or a native `<button>`. The menu writes two attributes onto it, which say to assistive technology what it does:
105
+
106
+ - `aria-haspopup="menu"`: it opens a menu.
107
+ - `aria-expanded`: whether the menu is open.
108
+
109
+ An `el-button` passes both on to the control inside of it. A button that shows an icon alone needs a name (`aria-label`), which is the name of the menu as well:
110
+
111
+ ```html
112
+ <el-menu>
113
+ <el-button slot="trigger" circle="true" aria-label="Actions for the invoice">
114
+ <svg aria-hidden="true">…</svg>
115
+ </el-button>
116
+ …
117
+ </el-menu>
118
+ ```
119
+
120
+ ## Keyboard
121
+
122
+ | Key | On the button | In the menu |
123
+ | ---------------- | ---------------------------------------- | ------------------------------------------------ |
124
+ | `Enter`, `Space` | Opens the menu, focus on the first entry | Chooses the entry |
125
+ | `ArrowDown` | Opens the menu, focus on the first entry | The next entry, from the last one to the first |
126
+ | `ArrowUp` | Opens the menu, focus on the last entry | The entry before, from the first one to the last |
127
+ | `Home`, `End` | | The first entry, the last entry |
128
+ | A letter | | The next entry that starts with it |
129
+ | `Escape` | | Closes the menu, focus back on the button |
130
+ | `Tab` | Moves on | Closes the menu, and the focus moves on |
131
+
132
+ The entries are no stops of the Tab key: the menu is one, through its button, and moves the focus itself. An entry that is disabled is reached by the arrow keys, so a screen reader finds it, and cannot be chosen.
133
+
134
+ ## Choosing an entry
135
+
136
+ Choosing is a click on an entry, with the pointer, `Enter` or `Space`. The menu fires `menu-select` and closes, and the focus is on the button again.
137
+
138
+ - `detail.item` is the `el-menu-item`, `detail.value` its `value`.
139
+ - The click is a click on the entry as well, for a listener there.
140
+ - An entry with `href` is a link: the browser follows it, and the menu closes.
141
+ - A click beside the menu closes it and chooses nothing.
142
+
143
+ ## Groups
144
+
145
+ Entries that belong together go into an [`el-menu-group`](../menu-group/menu-group.readme.md), which has a line over it and a heading where it has a `label`. An [`el-divider`](../divider/divider.readme.md) is a line alone.
146
+
147
+ ```html
148
+ <el-menu>
149
+ <el-button slot="trigger">File</el-button>
150
+ <el-menu-item value="open">Open</el-menu-item>
151
+ <el-menu-group label="Share">
152
+ <el-menu-item value="mail">Mail</el-menu-item>
153
+ <el-menu-item value="link">Copy link</el-menu-item>
154
+ </el-menu-group>
155
+ <el-menu-group>
156
+ <el-menu-item value="delete" variant="danger">Delete</el-menu-item>
157
+ </el-menu-group>
158
+ </el-menu>
159
+ ```
160
+
161
+ ## The panel
162
+
163
+ - **In the top layer.** The panel is a native popover: an element around the menu that clips (`overflow: hidden`) does not cut it off, and no `z-index` is needed. It takes no room on the page.
164
+ - **At its button.** `placement` names the side, `bottom-start` by default: below the button and in line with the start of it, which is the right edge in a right-to-left page. Without room at that side the menu goes to the opposite one, and it is pushed back along the edge of the viewport where it would leave it. It follows the button when the page scrolls.
165
+ - **As wide as its entries**, between `--el-menu-min-width` and `--el-menu-max-width`. A text that is longer wraps.
166
+ - **A long menu scrolls** in what the browser shows.
167
+ - **One at a time.** A menu that opens closes another one that is open.
168
+ - **A press beside it closes it**, when the pointer goes down. The panel is a popover the menu opens and closes itself (`popover="manual"`): one the platform closes would be gone when the finger of a long press is lifted.
169
+
170
+ Its place comes from [Floating UI](https://floating-ui.com), which the element imports (`@floating-ui/dom`).
171
+
172
+ ## One menu for many rows
173
+
174
+ A dense list has the same actions for every row: mark as read, rename, move, delete. One `el-menu` serves all of them. It has no button of its own, and the page opens it where it is needed with `showAt()`:
175
+
176
+ ```html
177
+ <ul id="notes">
178
+ <li data-id="12" tabindex="0">
179
+ Release notes
180
+ <el-button circle="true" appearance="plain" aria-haspopup="menu" aria-label="Actions for Release notes">
181
+ <svg aria-hidden="true">…</svg>
182
+ </el-button>
183
+ </li>
184
+ …
185
+ </ul>
186
+
187
+ <el-menu id="actions" label="Actions">
188
+ <el-menu-item value="read">Mark as read</el-menu-item>
189
+ <el-menu-item value="rename">Rename</el-menu-item>
190
+ <el-menu-item value="delete" variant="danger">Delete</el-menu-item>
191
+ </el-menu>
192
+ ```
193
+
194
+ ```js
195
+ const list = document.querySelector('#notes');
196
+ const menu = document.querySelector('#actions');
197
+
198
+ // A right click on a row: the menu opens where the pointer is.
199
+ list.addEventListener('contextmenu', (event) => {
200
+ const row = event.target.closest('li');
201
+ if (!row) return;
202
+ event.preventDefault();
203
+ menu.showAt({ x: event.clientX, y: event.clientY }, row);
204
+ });
205
+
206
+ // The button of a row: the same menu, at the button.
207
+ list.addEventListener('click', (event) => {
208
+ const button = event.target.closest('[aria-haspopup="menu"]');
209
+ if (button) menu.showAt(button);
210
+ });
211
+
212
+ menu.addEventListener('menu-select', (event) => {
213
+ const row = event.detail.opener.closest('li');
214
+ act(event.detail.value, row.dataset.id);
215
+ });
216
+ ```
217
+
218
+ - **`showAt({ x, y }, opener)`** opens the menu at a point of the viewport, the `clientX` and `clientY` of an event. The corner of the menu is at the point, as the menu of the system is, and the menu stays inside of the viewport.
219
+ - **`showAt(element)`** opens it at an element, placed as at its own button (`placement`, `distance`).
220
+ - **The opener** is what the menu is opened for: the second argument, or the element it is placed at. It is `menu.opener` while the menu is open and `detail.opener` of `menu-select`, and it gets the focus back when the menu closes after a choice or `Escape`. A row that should get the focus back has to be able to take it (`tabindex`).
221
+ - **An open menu moves** when `showAt()` is called again, for a right click on another row. It tells of both: `menu-hide` for the row it has left, `menu-show` for the one it is open for.
222
+ - **The roles and the keys** are the ones of the menu: the focus is on the first entry, the arrow keys move through the entries, `Escape` closes.
223
+ - **Nothing in the menu of the right click alone.** A right click and a long press are found by a user who knows them. The button of the row offers the same entries to everybody else, and to the keyboard.
224
+ - **The button of a row** says that it opens a menu: write `aria-haspopup="menu"` onto it. The menu tells such a button whether it is open for it (`aria-expanded`), and takes its name while it has no `label` of its own. A row is no control, and nothing is written onto it.
225
+ - **A menu with a button of its own** can be opened with `showAt()` as well. Its button does not say that the menu is open while it is open elsewhere.
226
+
227
+ #### A long press
228
+
229
+ A browser on Android fires `contextmenu` for a long press, and the listener above is all it takes. Safari on iOS does not: there the page finds the long press itself, a finger that stays down for half a second without moving, and calls `showAt()` while the finger is still down. The menu stays open when the finger is lifted.
230
+
231
+ ```js
232
+ let timer;
233
+ list.addEventListener('pointerdown', (event) => {
234
+ if (event.pointerType !== 'touch') return;
235
+ const row = event.target.closest('li');
236
+ timer = setTimeout(() => menu.showAt({ x: event.clientX, y: event.clientY }, row), 500);
237
+ });
238
+ for (const type of ['pointerup', 'pointercancel', 'pointermove']) {
239
+ list.addEventListener(type, () => clearTimeout(timer));
240
+ }
241
+ ```
242
+
243
+ A long press on a text selects it in Safari, and the selection takes the finger away from the page. Keep the text of a row from being selected for that:
244
+
245
+ ```css
246
+ #notes li {
247
+ -webkit-user-select: none;
248
+ user-select: none;
249
+ -webkit-touch-callout: none;
250
+ }
251
+ ```
252
+
253
+ ## Not in this element
254
+
255
+ - A menu in a menu (a submenu).
256
+ - Entries that are checked (`menuitemcheckbox`, `menuitemradio`).
257
+ - A menu bar.
258
+
259
+ For a panel in the flow of the page there is [`el-dropdown`](../dropdown/dropdown.readme.md), and for a floating panel with any content [`el-popover`](../popover/popover.readme.md).
260
+
261
+ ## Server-side rendering
262
+
263
+ The menu and its entries render on a server with `@webtides/element-js-ssr-renderer`. Before the script has run the menu is its button: the panel is a popover that is closed, and takes no room. A menu without a button, for the rows of a list, takes no room at all. The roles of the menu and of its entries, the links and the entries that are disabled are in the markup. The script adds what the button says (`aria-haspopup`, `aria-expanded`), the opening and the keyboard. A button does nothing before that.
264
+
265
+ ## Accessibility
266
+
267
+ - The panel has `role="menu"`, with the name of `label` or the one of its button. The entries have `role="menuitem"`, the groups `role="group"` with their heading as their name.
268
+ - The button says that it opens a menu and whether the menu is open.
269
+ - The focus is on an entry while the menu is open, and goes back to the button, or to what the menu was opened for, when the menu closes after a choice or `Escape`.
270
+ - The entry that has the focus of the keyboard has a ring inside of it, which shows where the user forces colours.
271
+ - On a touch screen every entry is at least `--el-touch-target` high.
272
+ - Without a theme the menu has the colours of the system, and reads in a light and in a dark scheme.
@@ -0,0 +1,55 @@
1
+ import hostStyle from '../../styles/host.style.js';
2
+
3
+ const css = String.raw;
4
+
5
+ const style = css`
6
+ :host {
7
+ display: inline-block;
8
+ }
9
+
10
+ [part~='panel'] {
11
+ /* The platform centres a popover in the viewport and gives it a look of its own. The panel
12
+ is placed at the button instead: the script sets left and top, in the coordinates of the
13
+ viewport. Whether it is shown stays with the platform, so there is no display here. */
14
+ position: fixed;
15
+ inset: auto;
16
+ top: 0;
17
+ left: 0;
18
+ margin: 0;
19
+ box-sizing: border-box;
20
+ inline-size: max-content;
21
+ min-inline-size: var(--el-menu-min-width, 10rem);
22
+ max-inline-size: min(var(--el-menu-max-width, 20rem), calc(100vw - 1rem));
23
+ /* A long menu scrolls in what the browser shows, and is never higher. */
24
+ max-block-size: calc(100vh - 1rem);
25
+ max-block-size: calc(100dvh - 1rem);
26
+ overflow-y: auto;
27
+ overscroll-behavior: contain;
28
+ padding: var(--el-space-1, 0.25rem);
29
+ /* System colours as the headless fallback: a floating surface has to be readable over the
30
+ page, so transparent is no option here. */
31
+ background: var(--el-color-bg, Canvas);
32
+ color: var(--el-color-fg, CanvasText);
33
+ border: var(--el-border-width, 1px) solid var(--el-color-border, currentColor);
34
+ border-radius: var(--el-radius-lg, 0);
35
+ box-shadow: var(--el-shadow-lg, none);
36
+ /* The text of the page around the button is not the text of a menu: a menu in a heading
37
+ is no heading. */
38
+ font-size: var(--el-font-size-sm, 0.875rem);
39
+ font-weight: var(--el-font-weight-normal, 400);
40
+ line-height: 1.25;
41
+ text-align: start;
42
+ /* A menu can stand in a row of joined buttons (el-button-group), which joins its button
43
+ with properties that inherit. What is in the panel is not part of that row. */
44
+ --_el-group-radius-start: initial;
45
+ --_el-group-radius-end: initial;
46
+ --_el-group-divider: initial;
47
+ }
48
+
49
+ /* A line between two entries, which the page puts there. */
50
+ ::slotted(el-divider) {
51
+ margin-block: var(--el-space-1, 0.25rem);
52
+ }
53
+ `;
54
+
55
+ export default [hostStyle(), style].join('\n');
@@ -0,0 +1,20 @@
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-menu-group`: a group of entries in an `el-menu`. A group to assistive technology (`role="group"`), with `label` as its heading and its name. The heading the eye sees is not read a second time. ([#167](https://github.com/webtides/element-library/issues/167))
20
+ - A line divides a group from what is before it in the menu. A group that is the first thing in its menu has none. Where the user forces colours the line is there without a theme as well.
@@ -0,0 +1,3 @@
1
+ import { define } from './menu-group.js';
2
+
3
+ define();
@@ -0,0 +1,44 @@
1
+ import { TemplateElement, defineElement, html } from '@webtides/element-js';
2
+ import style from './menu-group.style.js';
3
+
4
+ /**
5
+ * A group of entries in an `el-menu`, with a heading where it has a `label`. A group to assistive
6
+ * technology (`role="group"`), which has the heading as its name. A line divides it from what is
7
+ * before it in the menu.
8
+ *
9
+ * @element el-menu-group
10
+ *
11
+ * @slot - The entries of the group: `el-menu-item` elements.
12
+ *
13
+ * @csspart base - The group, with the line over it.
14
+ * @csspart label - The heading of the group.
15
+ *
16
+ * @property {string} label - The heading of the group, and its name for assistive technology.
17
+ * Default `''`.
18
+ */
19
+ export default class MenuGroup extends TemplateElement {
20
+ constructor() {
21
+ super({ styles: [style], shadowRender: true });
22
+ }
23
+
24
+ properties() {
25
+ return {
26
+ label: '',
27
+ };
28
+ }
29
+
30
+ template() {
31
+ // The group has the text as its name, so the heading the eye sees is not read a second
32
+ // time. A plain binding leaves the name out while there is none.
33
+ return html`
34
+ <div part="base" class="group" role="group" aria-label="${this.label || null}">
35
+ <div part="label" class="label" aria-hidden="true" ?hidden="${!this.label}">${this.label}</div>
36
+ <slot></slot>
37
+ </div>
38
+ `;
39
+ }
40
+ }
41
+
42
+ export function define() {
43
+ defineElement('el-menu-group', MenuGroup);
44
+ }
@@ -0,0 +1,74 @@
1
+ # Menu Group
2
+
3
+ `menu-group` is a group of entries in an [`el-menu`](../menu/menu.readme.md): the entries that belong together, under a heading where the group has one.
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/menu/define';
17
+ import '@webtides/element-library/menu-group/define';
18
+ import '@webtides/element-library/menu-item/define';
19
+ ```
20
+
21
+ ```html
22
+ <el-menu>
23
+ <el-button slot="trigger">File</el-button>
24
+ <el-menu-item value="open">Open</el-menu-item>
25
+ <el-menu-group label="Share">
26
+ <el-menu-item value="mail">Mail</el-menu-item>
27
+ <el-menu-item value="link">Copy link</el-menu-item>
28
+ </el-menu-group>
29
+ </el-menu>
30
+ ```
31
+
32
+ ## API
33
+
34
+ #### Properties/Attributes
35
+
36
+ | Name | Type | Default | Description |
37
+ | ------- | -------- | ------- | ---------------------------------------------------------------- |
38
+ | `label` | `string` | `''` | The heading of the group, and its name for assistive technology. |
39
+
40
+ #### Methods
41
+
42
+ _None._
43
+
44
+ #### Events
45
+
46
+ _None._
47
+
48
+ #### Slots
49
+
50
+ | Name | Description |
51
+ | --------- | -------------------------------------------------- |
52
+ | (default) | The entries of the group: `el-menu-item` elements. |
53
+
54
+ #### CSS Parts
55
+
56
+ | Name | Description |
57
+ | ------- | --------------------------------- |
58
+ | `base` | The group, with the line over it. |
59
+ | `label` | The heading of the group. |
60
+
61
+ #### CSS Custom Properties
62
+
63
+ Reads `--el-color-border` and `--el-border-width` for the line, `--el-space-1`, `--el-space-2` and `--el-space-3` for the room around it and the heading, and `--el-color-fg-muted` and `--el-font-size-xs` for the heading.
64
+
65
+ ## The line
66
+
67
+ A group has a line over it, which divides it from what is before it in the menu. A group that is the first thing in its menu has none. Entries that follow a group without a group of their own have no line over them: put them into a group, or an [`el-divider`](../divider/divider.readme.md) between.
68
+
69
+ ## Accessibility
70
+
71
+ - A group (`role="group"`) with `label` as its name. A screen reader says the name when the focus enters the group.
72
+ - The heading the eye sees is hidden from assistive technology, so it is not read a second time.
73
+ - The arrow keys move through the entries of all groups as through one row.
74
+ - Where the user forces colours the line is there without a theme as well.
@@ -0,0 +1,38 @@
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
+ /* Where the user forces colours the line is there without a theme as well: nothing else
9
+ tells two groups apart. */
10
+ --_el-menu-group-line-width: var(--el-border-width, 1px);
11
+ }
12
+
13
+ @media (forced-colors: active) {
14
+ :host {
15
+ --_el-menu-group-line-width: max(var(--el-border-width, 0px), 1px);
16
+ }
17
+ }
18
+
19
+ /* A line over the group, with a little room on both sides of it. Not over a group that is
20
+ the first thing in its menu: the button of the menu is a child of it as well, in a slot of
21
+ its own, and is not counted. */
22
+ :host(:not(:nth-child(1 of :not([slot])))) .group {
23
+ margin-block-start: var(--el-space-1, 0.25rem);
24
+ padding-block-start: var(--el-space-1, 0.25rem);
25
+ border-block-start: var(--_el-menu-group-line-width) solid var(--el-color-border, currentColor);
26
+ }
27
+
28
+ /* The heading starts where the entries start. */
29
+ .label {
30
+ padding: var(--el-space-2, 0.5rem) var(--el-space-3, 0.75rem) var(--el-space-1, 0.25rem);
31
+ color: var(--el-color-fg-muted, inherit);
32
+ font-size: var(--el-font-size-xs, 0.75rem);
33
+ font-weight: var(--el-font-weight-semibold, 600);
34
+ line-height: 1.2;
35
+ }
36
+ `;
37
+
38
+ export default [hostStyle(), style].join('\n');
@@ -0,0 +1,24 @@
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-menu-item`: one entry of an `el-menu`. A `<button>` with `role="menuitem"`, or a link with `href`, `target` and `rel`. It is out of the order of the Tab key: the menu moves the focus to it. ([#167](https://github.com/webtides/element-library/issues/167))
20
+ - `value` is what the entry stands for, for the listener of `menu-select`. Choosing an entry is a click on it, which the page can hear on the entry as well.
21
+ - `disabled`: the entry cannot be chosen. It says so (`aria-disabled`), fires no click, and the keyboard still gets to it. A link that is disabled has no address.
22
+ - The `icon` slot takes an icon in front of the text, and takes no room while it is empty.
23
+ - `variant` (reflected): `danger` shows an entry for something that cannot be undone in the colour of a danger, from the shared variants.
24
+ - The entry under the pointer and the one with the focus of the keyboard have a tint of the text colour, and the focus a ring inside of the entry, which is what shows where the user forces colours. On a touch screen an entry is at least `--el-touch-target` high.
@@ -0,0 +1,3 @@
1
+ import { define } from './menu-item.js';
2
+
3
+ define();
@@ -0,0 +1,130 @@
1
+ import { TemplateElement, defineElement, html, classMap } from '@webtides/element-js';
2
+ import { hasSlotted } from '../../utils/slots.js';
3
+ import style from './menu-item.style.js';
4
+
5
+ /**
6
+ * One entry of an `el-menu`: an action, or a link with an address. A menu item to assistive
7
+ * technology (`role="menuitem"`). The menu moves the focus of the keyboard to it, so it is no stop
8
+ * of the Tab key itself.
9
+ *
10
+ * Choosing an entry is a click on it: listen for `click` on the entry, or for `menu-select` on the
11
+ * menu, which names the entry and its `value`.
12
+ *
13
+ * @element el-menu-item
14
+ *
15
+ * @slot - The text of the entry.
16
+ * @slot icon - An icon in front of the text: a decoration, the text is the name.
17
+ *
18
+ * @csspart base - The entry: a `<button>`, or an `<a>` with `href`.
19
+ * @csspart icon - The place of the icon.
20
+ * @csspart label - The text of the entry.
21
+ *
22
+ * @property {string} href - The address the entry leads to. With one it is a link.
23
+ * @property {string} target - Where to open the address.
24
+ * @property {string} rel - `rel` attribute for the link, written when `target` is set. Default
25
+ * `'noreferrer noopener'`.
26
+ * @property {string} value - What the entry stands for, for the listener of `menu-select`:
27
+ * `'delete'`. Default `''`.
28
+ * @property {boolean} disabled - Whether the entry cannot be chosen. The keyboard still gets to
29
+ * it. Default `false`.
30
+ * @property {'neutral'|'brand'|'success'|'warning'|'danger'} variant - The variant of the entry:
31
+ * `danger` for something that cannot be undone. Default `'neutral'`. Reflected to the `variant`
32
+ * attribute.
33
+ */
34
+ export default class MenuItem extends TemplateElement {
35
+ constructor() {
36
+ super({
37
+ styles: [style],
38
+ shadowRender: true,
39
+ // The shared variants module selects the host by this attribute.
40
+ propertyOptions: { variant: { reflect: true } },
41
+ });
42
+ }
43
+
44
+ properties() {
45
+ return {
46
+ href: '',
47
+ target: '',
48
+ rel: 'noreferrer noopener',
49
+ value: '',
50
+ disabled: false,
51
+ variant: 'neutral',
52
+ };
53
+ }
54
+
55
+ events() {
56
+ return {
57
+ "[part~='base']": {
58
+ // A template element does not render again when a child comes, goes or changes
59
+ // its `slot` attribute. The slot tells of all three.
60
+ slotchange: () => this.requestUpdate(),
61
+ // An entry that is disabled keeps its click to itself: the page hears nothing.
62
+ click: (event) => {
63
+ if (!this._disabled()) return;
64
+ event.preventDefault();
65
+ event.stopPropagation();
66
+ },
67
+ },
68
+ };
69
+ }
70
+
71
+ /**
72
+ * Puts the focus on the entry: on the control inside of it.
73
+ * @param {FocusOptions} [options]
74
+ */
75
+ focus(options) {
76
+ this.shadowRoot?.querySelector("[part~='base']")?.focus(options);
77
+ }
78
+
79
+ /**
80
+ * @private
81
+ * @returns {boolean}
82
+ */
83
+ _disabled() {
84
+ return this.disabled === true || this.disabled === 'true' || this.disabled === '';
85
+ }
86
+
87
+ template() {
88
+ const disabled = this._disabled();
89
+ const classes = classMap({ item: true, 'item--disabled': disabled });
90
+ const content = html`
91
+ <span part="icon" class="icon" ?hidden="${!hasSlotted(this, 'icon')}"><slot name="icon"></slot></span>
92
+ <span part="label" class="label"><slot></slot></span>
93
+ `;
94
+
95
+ // The role and the place in the order of the Tab key are inside of the shadow root: they
96
+ // are part of the server-rendered markup that way. A link that is disabled has no address
97
+ // to follow, so it is the button.
98
+ if (this.href && !disabled) {
99
+ return html`
100
+ <a
101
+ part="base"
102
+ class="${classes}"
103
+ role="menuitem"
104
+ tabindex="-1"
105
+ href="${this.href}"
106
+ target="${this.target || null}"
107
+ rel="${this.target ? this.rel : null}"
108
+ >${content}</a
109
+ >
110
+ `;
111
+ }
112
+
113
+ return html`
114
+ <button
115
+ part="base"
116
+ class="${classes}"
117
+ type="button"
118
+ role="menuitem"
119
+ tabindex="-1"
120
+ aria-disabled="${disabled ? 'true' : null}"
121
+ >
122
+ ${content}
123
+ </button>
124
+ `;
125
+ }
126
+ }
127
+
128
+ export function define() {
129
+ defineElement('el-menu-item', MenuItem);
130
+ }