@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
@@ -1,17 +1,19 @@
1
1
  import { StyledElement, defineElement } from '@webtides/element-js';
2
+ import { scrollContainer } from '../../utils/scroll.js';
2
3
  import style from './scroll-to-top.style.js';
3
4
 
4
5
  /**
5
- * Wraps any click-emitting child (`<a>`, `<button>`, …) and smoothly scrolls the window
6
- * to the top when the child is clicked.
6
+ * Wraps any click-emitting child (`<a>`, `<button>`, …) and smoothly scrolls to the top when the
7
+ * child is clicked: the window, or the element around it that scrolls, the content of an
8
+ * `el-app-frame` for example.
7
9
  *
8
10
  * @element el-scroll-to-top
9
11
  *
10
12
  * @slot - Default slot. Any child that emits a `click` event will trigger the scroll.
11
13
  *
12
14
  * @property {number} duration - Duration of the easing animation in milliseconds. Ignored
13
- * when the page's `html` element has `scroll-behavior: smooth` (the browser drives the
14
- * scroll in that case).
15
+ * when what scrolls has `scroll-behavior: smooth`, the `html` element for the window (the
16
+ * browser drives the scroll in that case).
15
17
  * @property {boolean} preventDefault - When `true`, the captured click's default action is
16
18
  * suppressed.
17
19
  */
@@ -45,19 +47,21 @@ export default class ScrollToTop extends StyledElement {
45
47
  }
46
48
 
47
49
  /**
48
- * Scroll the window to the top.
50
+ * Scroll to the top: the element around this one that scrolls, or the window.
49
51
  * @returns {void}
50
52
  */
51
53
  scrollToTop() {
52
- const htmlScroll = window
53
- .getComputedStyle(document.querySelectorAll('html')[0], null)
54
- .getPropertyValue('scroll-behavior');
54
+ const container = scrollContainer(this);
55
+ const target = container ?? window;
56
+ const behavior = getComputedStyle(container ?? document.documentElement).getPropertyValue('scroll-behavior');
55
57
 
56
- if (htmlScroll === 'smooth') {
57
- window.scrollTo(0, 0);
58
+ if (behavior === 'smooth') {
59
+ target.scrollTo(0, 0);
58
60
  } else {
59
61
  const duration = this.duration;
60
- const difference = document.documentElement.scrollTop || document.body.scrollTop;
62
+ const difference = container
63
+ ? container.scrollTop
64
+ : document.documentElement.scrollTop || document.body.scrollTop;
61
65
  const startTime = performance.now();
62
66
 
63
67
  // noinspection JSAnnotator
@@ -65,7 +69,7 @@ export default class ScrollToTop extends StyledElement {
65
69
  let normalizedTime = (timeStamp - startTime) / duration;
66
70
  if (normalizedTime > 1) normalizedTime = 1;
67
71
 
68
- window.scrollTo(0, difference * Math.cos(normalizedTime * Math.PI));
72
+ target.scrollTo(0, difference * Math.cos(normalizedTime * Math.PI));
69
73
  if (normalizedTime < 1) window.requestAnimationFrame(step);
70
74
  }
71
75
  window.requestAnimationFrame(step);
@@ -2,6 +2,8 @@
2
2
 
3
3
  `scroll-to-top` is a wrapper that smoothly scrolls the page to the top. Place any `click`-emitting child element inside (e.g. `<a>` or `<button>`); when it fires a `click`, `scroll-to-top` captures it and scrolls to the top.
4
4
 
5
+ It scrolls what scrolls it: the element around it that has more content than height and an overflow that scrolls, the content of an [`el-app-frame`](../app-frame/app-frame.readme.md) for example. Where there is none, it scrolls the window.
6
+
5
7
  ## How to use
6
8
 
7
9
  #### Install
@@ -0,0 +1,27 @@
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-segmented-field`: one choice of a few options as a row of joined buttons, which behaves like a group of radios. It extends `el-radio-field`: a native `<fieldset>`/`<legend>` with an `<input type="radio">` per option, so the one tab stop, the arrow keys, the value in the form, its reset and `required` are native, and the label, the help message and the error message are the ones of every field. `input-change` reports the value. ([#166](https://github.com/webtides/element-library/issues/166))
20
+ - `options` as `el-radio-field` has them: plain strings, or objects with a `value`, a `label` and `disabled`. The whole field can be disabled as well.
21
+ - An option with `icon`, the address of an SVG symbol (`#grid`, `/icons.svg#grid`), shows that icon in the place of its label. The label is then its name for assistive technology and its tooltip.
22
+ - The row looks like an `el-button-group`: two neighbours share one line, only the corners at the two ends are round (at the other ends in a text that runs from right to left), and the option with the keyboard focus lies over its neighbours. The row is never wider than its place: the options share the width then, and a label breaks into lines.
23
+ - The chosen option has a tint of its text colour and a ring inside of its edge, as a pressed `el-button`. The ring is a border, so it stays where the user forces colours.
24
+ - `size` (`small`, `medium`, `large`): an option is as high as an `el-button` of that size. On a touch screen it is at least `--el-touch-target` high and wide.
25
+ - The look is the stylesheet reading the native radios. A server-rendered field does not change when the element takes over, and it submits its value before the script has run.
26
+ - `label-screen-reader-only` hides the label from the eye and keeps it as the name of the group. The field hides it with its own stylesheet, so it works on a page without an `sr-only` class.
27
+ - In a container that gives its controls a size, an `el-toolbar`, the field takes it from there, while the page has not set `size` on the field itself. ([#194](https://github.com/webtides/element-library/issues/194))
@@ -0,0 +1,3 @@
1
+ import { define } from './segmented-field.js';
2
+
3
+ define();
@@ -0,0 +1,175 @@
1
+ import { html, defineElement } from '@webtides/element-js';
2
+ import RadioField from '../radio-field/radio-field.js';
3
+ import style from './segmented-field.style.js';
4
+
5
+ /**
6
+ * One choice of a few options, shown as a row of joined buttons: "List | Grid",
7
+ * "Day | Week | Month". It looks like an `el-button-group` and behaves like a group of radios,
8
+ * because it is one: a native `<fieldset>`/`<legend>` with an `<input type="radio">` per option
9
+ * (it extends `el-radio-field`). So the one tab stop, the arrow keys, the value in the form, its
10
+ * reset and `required` are native, and the label, the help message and the error message are the
11
+ * ones of every field.
12
+ *
13
+ * In a container that gives its controls a size, an `el-toolbar`, the field takes it from there,
14
+ * while the page has not set `size` on the field itself.
15
+ *
16
+ * @element el-segmented-field
17
+ *
18
+ * @fires {CustomEvent<string>} input-change - Fired when the chosen option changes. `detail` is
19
+ * its value. Bubbles.
20
+ *
21
+ * @cssstate touched - Set once the user has left the group, or the browser has refused a submit
22
+ * because of it. Inherits `valid` and `invalid` from `FormField`.
23
+ *
24
+ * @property {string | null} value - The value of the chosen option.
25
+ * @property {Array<string | { value: string, label?: string, icon?: string, disabled?: boolean }>} options -
26
+ * The options. Plain strings (`['Day', 'Week']`) are value and label at once; an object has a
27
+ * `value`, a `label`, and can be `disabled`. With `icon`, the address of an SVG symbol
28
+ * (`'#grid'`, `'/icons.svg#grid'`), the option shows that icon in the place of its label: the
29
+ * label is then its name for assistive technology and its tooltip.
30
+ * @property {'small'|'medium'|'large'} size - The size of the options: their height, their padding
31
+ * and their font size. Default `'medium'`. Reflected to the `size` attribute.
32
+ */
33
+ export default class SegmentedField extends RadioField {
34
+ constructor(options) {
35
+ super({
36
+ styles: [style],
37
+ ...options,
38
+ // The size module selects the host by this attribute.
39
+ propertyOptions: { size: { reflect: true }, ...options?.propertyOptions },
40
+ });
41
+ }
42
+
43
+ /**
44
+ * Whether the page has given the field a size of its own, see `_hasOwnSize()`.
45
+ * @private
46
+ * @type {boolean | undefined}
47
+ */
48
+ _ownSize = undefined;
49
+
50
+ properties() {
51
+ return {
52
+ ...super.properties(),
53
+ size: 'medium',
54
+ };
55
+ }
56
+
57
+ static observedAttributes = ['size'];
58
+
59
+ /**
60
+ * Whether the field is writing a property to its attribute right now, see `reflectProperty()`.
61
+ * @private
62
+ */
63
+ _reflecting = false;
64
+
65
+ connectedCallback() {
66
+ // Before element-js writes the default onto the element: after that, every field has a
67
+ // `size` attribute, and nothing says who wrote it.
68
+ this._ownSize ??= this.hasAttribute('size') || Object.hasOwn(this, 'size');
69
+ super.connectedCallback();
70
+ }
71
+
72
+ /**
73
+ * The page has written the `size` attribute, after the field was connected: the size is the
74
+ * field's own from now on, also when it is the default. The field writes the attribute itself
75
+ * as well, which says nothing.
76
+ */
77
+ attributeChangedCallback(name, oldValue, newValue) {
78
+ if (name !== 'size' || this._ownSize !== false || this._reflecting || newValue === null) return;
79
+ this._ownSize = true;
80
+ this.requestUpdate();
81
+ }
82
+
83
+ reflectProperty(options) {
84
+ // `attributeChangedCallback()` runs before `setAttribute()` returns.
85
+ this._reflecting = true;
86
+ try {
87
+ super.reflectProperty(options);
88
+ } finally {
89
+ this._reflecting = false;
90
+ }
91
+ }
92
+
93
+ watch() {
94
+ return {
95
+ ...super.watch(),
96
+ // A size that is set later, as an attribute or from a script, is the field's own.
97
+ size: () => {
98
+ this._ownSize = true;
99
+ },
100
+ };
101
+ }
102
+
103
+ /**
104
+ * Whether the page has given the field a size of its own. A field without one takes the size
105
+ * of a container that gives one to its controls, a toolbar. The template marks the row with
106
+ * the answer, and the stylesheet reads the mark. On the server no attribute has been written
107
+ * by the element: one that is there is the one of the page.
108
+ * @private
109
+ * @returns {boolean}
110
+ */
111
+ _hasOwnSize() {
112
+ if (this._ownSize === undefined) return !!this.hasAttribute?.('size');
113
+ // A size that is not the default was set by someone: the watcher has not run yet when the
114
+ // field renders with a size it has just got from a script.
115
+ return this._ownSize || this.size !== 'medium';
116
+ }
117
+
118
+ template() {
119
+ return html`
120
+ <fieldset
121
+ class="field ${this.classes().field}"
122
+ aria-describedby="${this._describedBy()}"
123
+ aria-errormessage="${this._idOf('error-message')}"
124
+ aria-invalid="${this.valid ? 'false' : 'true'}"
125
+ >
126
+ ${this.legendTemplate()} ${this.helpTemplate()}
127
+ <div class="options ${this._hasOwnSize() ? '' : 'options--inherit-size'}">${this.fieldTemplate()}</div>
128
+ ${this.errorTemplate()}
129
+ </fieldset>
130
+ `;
131
+ }
132
+
133
+ /** @private */
134
+ fieldTemplate() {
135
+ return this.options.map((option, index) => {
136
+ const value = option.value ?? option;
137
+ const label = option.label ?? value;
138
+ const optionDisabled = this.disabled || !!option.disabled;
139
+ const checked = this.value != null && String(this.value) === String(value);
140
+ const id = `segment-${this.uuid}-${index}`;
141
+
142
+ // The radio is hidden from the eye, and the segment after it is what is drawn in its
143
+ // place: it shows whether the radio is checked, has the focus or is disabled, by the
144
+ // stylesheet alone.
145
+ return html`
146
+ <label class="option" for="${id}" title="${option.icon ? label : null}">
147
+ <input
148
+ type="radio"
149
+ id="${id}"
150
+ name="${this.name}"
151
+ value="${value}"
152
+ ?checked="${checked}"
153
+ ?disabled="${optionDisabled}"
154
+ ?required="${this.required}"
155
+ aria-describedby="${this._describedBy()}"
156
+ />
157
+ <span class="segment">
158
+ ${
159
+ option.icon
160
+ ? html`<svg class="segment-icon" aria-hidden="true" focusable="false">
161
+ <use href="${option.icon}"></use>
162
+ </svg>
163
+ <span class="segment-name">${label}</span>`
164
+ : html`<span class="option-label">${label}</span>`
165
+ }
166
+ </span>
167
+ </label>
168
+ `;
169
+ });
170
+ }
171
+ }
172
+
173
+ export function define() {
174
+ defineElement('el-segmented-field', SegmentedField);
175
+ }
@@ -0,0 +1,140 @@
1
+ # SegmentedField
2
+
3
+ `segmented-field` is one choice of a few options, shown as a row of joined buttons: "List | Grid", "Day | Week | Month", the alignment of a text. It looks like an [`el-button-group`](../button-group/button-group.readme.md) and behaves like a group of radios, because it is one: it extends [`el-radio-field`](../radio-field/radio-field.readme.md) and renders a native `<fieldset>`/`<legend>` with an `<input type="radio">` per option. The one tab stop, the arrow keys, the value in the form, its reset and `required` are native.
4
+
5
+ It is headless by default: without a theme the options have a border and a text in the text colour of 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/segmented-field/define';
19
+ ```
20
+
21
+ ```html
22
+ <el-segmented-field
23
+ name="view"
24
+ label="Calendar"
25
+ value="week"
26
+ options='[{"value":"day","label":"Day"},{"value":"week","label":"Week"},{"value":"month","label":"Month"}]'
27
+ ></el-segmented-field>
28
+
29
+ <el-segmented-field name="plan" label="Plan" required="true" options='["Free","Team","Company"]'></el-segmented-field>
30
+ ```
31
+
32
+ The radios are one group by their `name`, as native radios are: give the field a name, and a name of its own on a page with several of them outside of a form.
33
+
34
+ #### The value
35
+
36
+ `value` is the value of the chosen option, which is what the form submits, and `null` while nothing is chosen. A choice cannot be taken back to none by the user: a radio group has no way to choose nothing. A script can, with `value = null`, and so can `form.reset()` for a field that was rendered without a choice.
37
+
38
+ ## API
39
+
40
+ #### Properties/Attributes
41
+
42
+ Inherits all of `form-field`'s properties (`name`, `value`, `required`, `disabled`, `label`, `labelScreenReaderOnly`, `errorMessage`, `helpMessage`, `valid`, `touched`) and adds:
43
+
44
+ | Name | Type | Default | Description |
45
+ | --- | --- | --- | --- |
46
+ | `value` | `string` | `null` | The value of the chosen option. |
47
+ | `options` | `Array<string \| { value, label?, icon?, disabled? }>` | `[]` | The options, as `el-radio-field` has them: plain strings, or objects with a `value`, a `label` and `disabled`. `icon` shows an icon in the place of the label, see [Icons](#icons). |
48
+ | `size` | `'small' \| 'medium' \| 'large'` | `'medium'` | The size of the options: their height, their padding and their font size. Reflected to the `size` attribute. |
49
+
50
+ #### Events
51
+
52
+ | Name | Detail | Description |
53
+ | -------------- | -------------------- | ------------------------------------- |
54
+ | `input-change` | `string` (the value) | Fired when the chosen option changes. |
55
+
56
+ #### CSS States
57
+
58
+ | Name | Description |
59
+ | --------- | ----------------------------------------------------------------------------------------- |
60
+ | `touched` | Set once the user has left the group. Moving from one option to the next does not set it. |
61
+ | `valid` | Set while the field passes validation. |
62
+ | `invalid` | Set while the field fails validation (`required` with nothing chosen). |
63
+
64
+ #### CSS Custom Properties
65
+
66
+ Reads the design tokens of the library: `--el-color-border` for the border of an option, `--el-color-fg` for its text, `--el-radius-md` for the corners at the two ends of the row, `--el-control-height`, `--el-space-*` and `--el-font-size-*` for the size, `--el-color-accent` and `--el-focus-ring-width` for the focus ring.
67
+
68
+ ## The row
69
+
70
+ The options are joined: two neighbours share one line, and only the corners at the two ends of the row are round. In a text that runs from right to left the row starts at the right, with its round corners there.
71
+
72
+ The row is as wide as its options. It is never wider than its place: the options share the width then, and a label that does not fit breaks into lines, with all options as high as the highest. A segmented field is for a few short options; for more of them, or longer ones, an `el-radio-field` or an `el-select-field` is the better field.
73
+
74
+ An option is as high as an `el-button` of the same `size`.
75
+
76
+ ## The chosen option
77
+
78
+ The chosen option has a tint of its text colour and a ring inside of its edge, as a pressed `el-button` has. The ring is a shape and a border: it tells the option apart without a colour, and where the user forces colours it stays, a little wider.
79
+
80
+ All of it is the stylesheet reading the native radio (`:checked`): nothing is set from a script.
81
+
82
+ ## Icons
83
+
84
+ An option with `icon` shows that icon in the place of its label. `icon` is the address of an SVG symbol: one of the page (`#grid`) or of a file (`/icons.svg#grid`). The label is then not shown. It is the name of the option for assistive technology, and its tooltip for the pointer.
85
+
86
+ ```html
87
+ <svg width="0" height="0" style="position:absolute" aria-hidden="true">
88
+ <symbol id="icon-list" viewBox="0 0 24 24">…</symbol>
89
+ <symbol id="icon-grid" viewBox="0 0 24 24">…</symbol>
90
+ </svg>
91
+
92
+ <el-segmented-field
93
+ name="layout"
94
+ label="Layout"
95
+ value="list"
96
+ options='[{"value":"list","label":"List","icon":"#icon-list"},{"value":"grid","label":"Grid","icon":"#icon-grid"}]'
97
+ ></el-segmented-field>
98
+ ```
99
+
100
+ The icon has the colour of the text (`currentColor`) and is 1.25em wide and high. Every option needs a `label`, with an icon as well.
101
+
102
+ ## In a toolbar
103
+
104
+ In an [`el-toolbar`](../toolbar/toolbar.readme.md) the field takes the size of the toolbar, while the page has not set `size` on the field itself. Give it `label-screen-reader-only="true"`: the label stays the name of the group and is not shown.
105
+
106
+ ```html
107
+ <el-toolbar label="Tasks" size="small">
108
+ <el-segmented-field
109
+ name="view"
110
+ label="View"
111
+ label-screen-reader-only="true"
112
+ value="List"
113
+ options='["List","Board"]'
114
+ ></el-segmented-field>
115
+ </el-toolbar>
116
+ ```
117
+
118
+ The arrow keys of a toolbar move the focus from control to control, and the options of the field are controls of the toolbar. So there the left and right arrow keys go through the options without choosing: Space chooses the option with the focus, and the up and down arrow keys move the choice.
119
+
120
+ ## Disabled
121
+
122
+ `disabled="true"` disables the whole field: nothing can be chosen, and the form leaves it out. An option with `disabled: true` cannot be chosen, and the arrow keys skip it. A disabled option is faded.
123
+
124
+ ## Accessibility
125
+
126
+ - The field is a group (`<fieldset>`) named by its `label` (`<legend>`), and its options are native radios: a screen reader announces "radio button, 2 of 3" with the name of the option.
127
+ - It is one stop of the Tab key: the chosen option, or the first one while nothing is chosen. The arrow keys move the choice, around the ends, and Space chooses the option with the focus.
128
+ - The keyboard focus shows as a ring around the option, which lies over its neighbours while it has the focus.
129
+ - On a touch screen (`@media (any-pointer: coarse)`) an option is at least `--el-touch-target` high and wide.
130
+ - `label-screen-reader-only="true"` hides the label from the eye and keeps it as the name of the group, for a field in a toolbar. The field hides it with its own stylesheet; it needs no `sr-only` class of the page.
131
+
132
+ ## Server-side rendering
133
+
134
+ The field renders into the page, with native radios. Server-rendered, it looks the same before and after the element takes over: the row, the sizes and the chosen option are its stylesheet. Before the script has run, a click and the arrow keys choose, the form submits the value, and `required` holds. The script adds the events, the messages of the field and the reset to what was rendered.
135
+
136
+ ## What it is not
137
+
138
+ - **Not several options at once.** That is an [`el-checkbox-group-field`](../checkbox-group-field/checkbox-group-field.readme.md).
139
+ - **Not a row of buttons that each do something**, as in a toolbar. That is an [`el-button-group`](../button-group/button-group.readme.md).
140
+ - **Not a single button that stays pressed.** That is an `el-button` with [`toggle`](../button/button.readme.md#a-toggle-button).
@@ -0,0 +1,193 @@
1
+ import hostStyle from '../../styles/host.style.js';
2
+ import sizeStyle from '../../styles/size.style.js';
3
+ import formControlStyle from '../../styles/form-control.style.js';
4
+ import choiceGroupStyle from '../../styles/choice-group.style.js';
5
+
6
+ const css = String.raw;
7
+
8
+ /**
9
+ * The fieldset as the column of the field, the option as the hit area of its radio and the hidden
10
+ * native radio are the shared module `choice-group`. Here: the options as a row of joined buttons,
11
+ * and the segment that is drawn in the place of a radio.
12
+ */
13
+ const style = css`
14
+ el-segmented-field {
15
+ /* A row as wide as its options, and never wider than its place: the options share the
16
+ width then, and a label that does not fit breaks into lines. */
17
+ .options {
18
+ display: flex;
19
+ align-self: flex-start;
20
+ max-width: 100%;
21
+
22
+ /* The size of the options: the one of the field, from the size module. */
23
+ --_el-segment-height: var(--_el-size-height);
24
+ --_el-segment-padding-block: var(--_el-size-padding-block);
25
+ --_el-segment-padding-inline: var(--_el-size-padding-inline);
26
+ --_el-segment-font-size: var(--_el-size-font-size);
27
+ }
28
+
29
+ /* A container that gives its controls one size, a toolbar, says so in properties that are
30
+ inherited (see sizeContextStyle()). The field reads them while the page has not set a
31
+ size on the field itself: the template marks the row then. Outside of such a container
32
+ they are not set, and the size is the one of the field. */
33
+ .options--inherit-size {
34
+ --_el-segment-height: var(--_el-context-size-height, var(--_el-size-height));
35
+ --_el-segment-padding-block: var(--_el-context-size-padding-block, var(--_el-size-padding-block));
36
+ --_el-segment-padding-inline: var(--_el-context-size-padding-inline, var(--_el-size-padding-inline));
37
+ --_el-segment-font-size: var(--_el-context-size-font-size, var(--_el-size-font-size));
38
+ }
39
+
40
+ /* The label is the hit area. It has no gap and no room of its own: the segment fills it,
41
+ on a touch screen up to the least size of a target as well. */
42
+ .option {
43
+ position: relative;
44
+ flex: 0 1 auto;
45
+ align-items: stretch;
46
+ gap: 0;
47
+ min-width: 0;
48
+ }
49
+
50
+ /* Touch screens: an option may share the width of a narrow row, and still is no narrower
51
+ than a target. The shared module says the same for every option of a field; the rule
52
+ above, for the row, would take it back. */
53
+ @media (any-pointer: coarse) {
54
+ .option {
55
+ min-width: var(--el-touch-target, 0px);
56
+ }
57
+ }
58
+
59
+ /* ── Segment ──────────────────────────────────────────────────────── */
60
+
61
+ /* An outlined button of the size of the field. The fallbacks render a usable control
62
+ without a theme: a border in the text colour of the page. */
63
+ .segment {
64
+ --_el-segment-radius: var(--el-radius-md, 4px);
65
+
66
+ position: relative;
67
+ display: flex;
68
+ flex: 1 1 auto;
69
+ align-items: center;
70
+ justify-content: center;
71
+ gap: var(--el-space-2, 0.5em);
72
+ /* The height of the size counts from the border, as on el-button. The field renders
73
+ into the page, where nothing has said so. */
74
+ box-sizing: border-box;
75
+ min-width: 0;
76
+ min-height: var(--_el-segment-height);
77
+ padding: var(--_el-segment-padding-block) var(--_el-segment-padding-inline);
78
+ border: var(--el-border-width, 1px) solid var(--el-color-border, currentColor);
79
+ color: var(--el-color-fg, inherit);
80
+ font-family: var(--el-font-family, inherit);
81
+ font-size: var(--_el-segment-font-size);
82
+ font-weight: 600;
83
+ line-height: var(--el-line-height, 1.5);
84
+ text-align: center;
85
+ overflow-wrap: anywhere;
86
+ user-select: none;
87
+ transition: background var(--el-duration-md, 0s) var(--el-ease, linear);
88
+ }
89
+
90
+ /* Only the outer corners of the row are round. The properties follow the reading
91
+ direction, so the start of the row is at the right in a text that runs from right to
92
+ left. */
93
+ .option:first-child .segment {
94
+ border-start-start-radius: var(--_el-segment-radius);
95
+ border-end-start-radius: var(--_el-segment-radius);
96
+ }
97
+
98
+ .option:last-child .segment {
99
+ border-start-end-radius: var(--_el-segment-radius);
100
+ border-end-end-radius: var(--_el-segment-radius);
101
+ }
102
+
103
+ /* With a neighbour in front: the border at the start lies on the border at the end of
104
+ that neighbour, so the two share one line. */
105
+ .option:not(:first-child) {
106
+ margin-inline-start: calc(-1 * var(--el-border-width, 1px));
107
+ }
108
+
109
+ /* The option with the focus lies over its neighbours, which would cover a part of its
110
+ focus ring otherwise. */
111
+ .option:has(input:focus-visible) {
112
+ z-index: 1;
113
+ }
114
+
115
+ /* ── States ───────────────────────────────────────────────────────── */
116
+
117
+ /* A tint of the text colour, which shows on every background. Hover only where the
118
+ pointer can hover: a touch screen leaves :hover on the option that was tapped last. */
119
+ @media (hover: hover) {
120
+ .option:hover input:not(:disabled):not(:checked) + .segment {
121
+ background: color-mix(in srgb, currentColor 12%, transparent);
122
+ }
123
+ }
124
+
125
+ .option:active input:not(:disabled):not(:checked) + .segment {
126
+ background: color-mix(in srgb, currentColor 24%, transparent);
127
+ }
128
+
129
+ /* The chosen option, as a pressed el-button: a tint of the text colour and a ring inside
130
+ of the edge. The ring is a shape and a border, so it tells the option apart without a
131
+ colour, and forced colours keep it. It has the corners of its segment. */
132
+ input:checked + .segment {
133
+ background: color-mix(in srgb, currentColor 16%, transparent);
134
+ }
135
+
136
+ input:checked + .segment::before {
137
+ content: '';
138
+ position: absolute;
139
+ inset: 0;
140
+ border: 0.125rem solid currentColor;
141
+ border-radius: inherit;
142
+ pointer-events: none;
143
+ }
144
+
145
+ /* Forced colours leave the ring as the only mark: it is wider there. */
146
+ @media (forced-colors: active) {
147
+ input:checked + .segment::before {
148
+ border-width: 0.1875rem;
149
+ }
150
+ }
151
+
152
+ /* ── A label that is not shown ────────────────────────────────────── */
153
+
154
+ /* label-screen-reader-only gives the legend the class sr-only. The field hides it itself,
155
+ so a field in a toolbar has a name and no label, on a page without such a class too. */
156
+ legend.sr-only {
157
+ position: absolute;
158
+ width: 1px;
159
+ height: 1px;
160
+ margin: 0;
161
+ overflow: hidden;
162
+ clip-path: inset(50%);
163
+ white-space: nowrap;
164
+ }
165
+
166
+ /* ── Icon ─────────────────────────────────────────────────────────── */
167
+
168
+ .segment-icon {
169
+ flex: none;
170
+ width: 1.25em;
171
+ height: 1.25em;
172
+ fill: currentColor;
173
+ }
174
+
175
+ /* The name of an option that shows an icon: for assistive technology alone. */
176
+ .segment-name {
177
+ position: absolute;
178
+ width: 1px;
179
+ height: 1px;
180
+ overflow: hidden;
181
+ clip-path: inset(50%);
182
+ white-space: nowrap;
183
+ }
184
+ }
185
+ `;
186
+
187
+ export default [
188
+ hostStyle('el-segmented-field'),
189
+ sizeStyle('el-segmented-field'),
190
+ formControlStyle('el-segmented-field'),
191
+ choiceGroupStyle('el-segmented-field'),
192
+ style,
193
+ ].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-splitter`: the edge between two panes that are beside each other, which the user drags to set the width of one of them. It is the control and sizes nothing itself, as a range does: `value` is the width in pixels, between `min` and `max`, and the layout around it takes it from the events. ([#182](https://github.com/webtides/element-library/issues/182))
20
+ - Dragged with a mouse, a finger and a pen. While it is dragged no text is selected, a finger does not scroll the page, and the edge keeps following the pointer over an `iframe`: it captures the pointer and covers the viewport for that time. `:state(dragging)` matches while it is dragged.
21
+ - A stop of the Tab key: the arrow keys move the edge by `step` pixels (`16` by default), `Home` and `End` take it to the least and to the greatest width. To assistive technology it is a separator with a value (`role="separator"`, `aria-valuenow`, `aria-valuemin`, `aria-valuemax`) and with the name of what it sizes (`label`).
22
+ - `splitter-resize` tells of every width while the user changes it, `splitter-resize-end` of the one that stays: when the pointer lets go, and with every key. A width the page sets tells of nothing.
23
+ - `placement` is the edge of its pane the splitter is: `end` (the default, the pane is in front of it) or `start` (the pane is after it). The direction of the drag and of the arrow keys follows it, and the reading direction.
24
+ - The edge is thin, a line from `--el-color-border` and `--el-border-width` (`--el-splitter-line-width` sets another width), and takes the pointer in a wider area around it: `--el-space-2` wide, and at least `--el-touch-target` on a touch screen. Under the pointer, while it is dragged and with the keyboard focus the line is a mark in `--el-color-accent`, and the focus has a ring. The line is a border, which stays where the user forces colours and is there without a theme then.
@@ -0,0 +1,3 @@
1
+ import { define } from './splitter.js';
2
+
3
+ define();
@@ -0,0 +1,4 @@
1
+ export default {
2
+ RESIZE: 'splitter-resize',
3
+ RESIZE_END: 'splitter-resize-end',
4
+ };