@webtides/element-library 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/CHANGELOG.md +300 -0
  2. package/README.md +72 -56
  3. package/all.js +16 -0
  4. package/catalog.js +17 -1
  5. package/custom-elements.json +15912 -10065
  6. package/package.json +1 -1
  7. package/src/components/accordion/accordion.changelog.md +11 -0
  8. package/src/components/accordion/accordion.js +15 -3
  9. package/src/components/accordion/accordion.readme.md +27 -1
  10. package/src/components/accordion/accordion.style.js +19 -0
  11. package/src/components/app-bar/app-bar.changelog.md +24 -0
  12. package/src/components/app-bar/app-bar.define.js +3 -0
  13. package/src/components/app-bar/app-bar.js +91 -0
  14. package/src/components/app-bar/app-bar.readme.md +130 -0
  15. package/src/components/app-bar/app-bar.style.js +103 -0
  16. package/src/components/app-frame/app-frame.changelog.md +59 -0
  17. package/src/components/app-frame/app-frame.define.js +3 -0
  18. package/src/components/app-frame/app-frame.events.js +6 -0
  19. package/src/components/app-frame/app-frame.js +1085 -0
  20. package/src/components/app-frame/app-frame.readme.md +425 -0
  21. package/src/components/app-frame/app-frame.style.js +534 -0
  22. package/src/components/button/button.changelog.md +21 -0
  23. package/src/components/button/button.events.js +3 -0
  24. package/src/components/button/button.js +145 -3
  25. package/src/components/button/button.readme.md +72 -4
  26. package/src/components/button/button.style.js +167 -8
  27. package/src/components/button-group/button-group.changelog.md +10 -0
  28. package/src/components/button-group/button-group.readme.md +2 -0
  29. package/src/components/button-group/button-group.style.js +6 -2
  30. package/src/components/checkbox-group-field/checkbox-group-field.changelog.md +6 -0
  31. package/src/components/checkbox-group-field/checkbox-group-field.js +7 -2
  32. package/src/components/checkbox-group-field/checkbox-group-field.readme.md +23 -1
  33. package/src/components/combobox-field/combobox-field.changelog.md +6 -0
  34. package/src/components/combobox-field/combobox-field.readme.md +8 -0
  35. package/src/components/combobox-field/combobox-field.style.js +2 -0
  36. package/src/components/date-field/date-field.changelog.md +6 -0
  37. package/src/components/date-field/date-field.readme.md +10 -0
  38. package/src/components/date-field/date-field.style.js +8 -3
  39. package/src/components/description-list/description-list.changelog.md +42 -0
  40. package/src/components/description-list/description-list.define.js +3 -0
  41. package/src/components/description-list/description-list.js +49 -0
  42. package/src/components/description-list/description-list.readme.md +161 -0
  43. package/src/components/description-list/description-list.style.js +169 -0
  44. package/src/components/dialog/dialog.changelog.md +7 -0
  45. package/src/components/dialog/dialog.readme.md +5 -0
  46. package/src/components/dialog/dialog.style.js +17 -2
  47. package/src/components/divider/divider.changelog.md +6 -0
  48. package/src/components/divider/divider.readme.md +1 -1
  49. package/src/components/divider/divider.style.js +6 -0
  50. package/src/components/drawer/drawer.changelog.md +7 -0
  51. package/src/components/drawer/drawer.readme.md +7 -6
  52. package/src/components/drawer/drawer.style.js +35 -2
  53. package/src/components/dropdown/dropdown.readme.md +6 -1
  54. package/src/components/file-field/file-field.changelog.md +8 -0
  55. package/src/components/file-field/file-field.js +135 -5
  56. package/src/components/file-field/file-field.readme.md +35 -6
  57. package/src/components/file-field/file-field.style.js +71 -0
  58. package/src/components/form-field/form-field.js +1 -1
  59. package/src/components/input-field/input-field.changelog.md +10 -0
  60. package/src/components/input-field/input-field.js +192 -14
  61. package/src/components/input-field/input-field.readme.md +88 -2
  62. package/src/components/input-field/input-field.style.js +2 -0
  63. package/src/components/list/list.changelog.md +30 -0
  64. package/src/components/list/list.define.js +3 -0
  65. package/src/components/list/list.js +68 -0
  66. package/src/components/list/list.readme.md +123 -0
  67. package/src/components/list/list.style.js +56 -0
  68. package/src/components/list-item/list-item.changelog.md +40 -0
  69. package/src/components/list-item/list-item.define.js +3 -0
  70. package/src/components/list-item/list-item.js +130 -0
  71. package/src/components/list-item/list-item.readme.md +144 -0
  72. package/src/components/list-item/list-item.style.js +246 -0
  73. package/src/components/menu/menu.changelog.md +44 -0
  74. package/src/components/menu/menu.define.js +3 -0
  75. package/src/components/menu/menu.events.js +5 -0
  76. package/src/components/menu/menu.js +793 -0
  77. package/src/components/menu/menu.readme.md +313 -0
  78. package/src/components/menu/menu.style.js +59 -0
  79. package/src/components/menu-group/menu-group.changelog.md +20 -0
  80. package/src/components/menu-group/menu-group.define.js +3 -0
  81. package/src/components/menu-group/menu-group.js +44 -0
  82. package/src/components/menu-group/menu-group.readme.md +74 -0
  83. package/src/components/menu-group/menu-group.style.js +38 -0
  84. package/src/components/menu-item/menu-item.changelog.md +32 -0
  85. package/src/components/menu-item/menu-item.define.js +3 -0
  86. package/src/components/menu-item/menu-item.js +168 -0
  87. package/src/components/menu-item/menu-item.readme.md +132 -0
  88. package/src/components/menu-item/menu-item.style.js +117 -0
  89. package/src/components/nav/nav.changelog.md +35 -0
  90. package/src/components/nav/nav.define.js +3 -0
  91. package/src/components/nav/nav.js +212 -0
  92. package/src/components/nav/nav.readme.md +248 -0
  93. package/src/components/nav/nav.style.js +269 -0
  94. package/src/components/nav-item/nav-item.changelog.md +25 -0
  95. package/src/components/nav-item/nav-item.define.js +3 -0
  96. package/src/components/nav-item/nav-item.js +75 -0
  97. package/src/components/nav-item/nav-item.readme.md +111 -0
  98. package/src/components/nav-item/nav-item.style.js +159 -0
  99. package/src/components/otp-field/otp-field.changelog.md +6 -0
  100. package/src/components/otp-field/otp-field.readme.md +8 -0
  101. package/src/components/otp-field/otp-field.style.js +8 -3
  102. package/src/components/pagination/pagination.changelog.md +8 -0
  103. package/src/components/pagination/pagination.js +123 -49
  104. package/src/components/pagination/pagination.readme.md +24 -6
  105. package/src/components/pagination/pagination.style.js +11 -1
  106. package/src/components/password-field/password-field.changelog.md +7 -0
  107. package/src/components/password-field/password-field.readme.md +11 -1
  108. package/src/components/password-field/password-field.style.js +2 -0
  109. package/src/components/popover/popover.changelog.md +6 -0
  110. package/src/components/popover/popover.style.js +1 -0
  111. package/src/components/radio-field/radio-field.changelog.md +6 -0
  112. package/src/components/radio-field/radio-field.js +7 -2
  113. package/src/components/radio-field/radio-field.readme.md +23 -1
  114. package/src/components/scroll-to-top/scroll-to-top.changelog.md +7 -5
  115. package/src/components/scroll-to-top/scroll-to-top.js +16 -12
  116. package/src/components/scroll-to-top/scroll-to-top.readme.md +2 -0
  117. package/src/components/segmented-field/segmented-field.changelog.md +27 -0
  118. package/src/components/segmented-field/segmented-field.define.js +3 -0
  119. package/src/components/segmented-field/segmented-field.js +175 -0
  120. package/src/components/segmented-field/segmented-field.readme.md +140 -0
  121. package/src/components/segmented-field/segmented-field.style.js +193 -0
  122. package/src/components/splitter/splitter.changelog.md +24 -0
  123. package/src/components/splitter/splitter.define.js +3 -0
  124. package/src/components/splitter/splitter.events.js +4 -0
  125. package/src/components/splitter/splitter.js +237 -0
  126. package/src/components/splitter/splitter.readme.md +164 -0
  127. package/src/components/splitter/splitter.style.js +100 -0
  128. package/src/components/status-bar/status-bar.changelog.md +25 -0
  129. package/src/components/status-bar/status-bar.define.js +3 -0
  130. package/src/components/status-bar/status-bar.js +74 -0
  131. package/src/components/status-bar/status-bar.readme.md +139 -0
  132. package/src/components/status-bar/status-bar.style.js +122 -0
  133. package/src/components/tab-group/tab-group.changelog.md +7 -0
  134. package/src/components/tab-group/tab-group.js +30 -9
  135. package/src/components/tab-group/tab-group.readme.md +14 -0
  136. package/src/components/textarea-field/textarea-field.changelog.md +6 -0
  137. package/src/components/textarea-field/textarea-field.js +14 -1
  138. package/src/components/textarea-field/textarea-field.readme.md +23 -1
  139. package/src/components/toast/toast.changelog.md +6 -0
  140. package/src/components/toast/toast.readme.md +5 -3
  141. package/src/components/toast/toast.style.js +22 -6
  142. package/src/components/toolbar/toolbar.changelog.md +24 -0
  143. package/src/components/toolbar/toolbar.define.js +3 -0
  144. package/src/components/toolbar/toolbar.js +233 -0
  145. package/src/components/toolbar/toolbar.readme.md +156 -0
  146. package/src/components/toolbar/toolbar.style.js +49 -0
  147. package/src/components/tooltip/tooltip.changelog.md +11 -0
  148. package/src/components/tooltip/tooltip.js +51 -4
  149. package/src/components/tooltip/tooltip.readme.md +26 -1
  150. package/src/components/tree/tree.changelog.md +23 -0
  151. package/src/components/tree/tree.define.js +3 -0
  152. package/src/components/tree/tree.js +138 -0
  153. package/src/components/tree/tree.readme.md +119 -0
  154. package/src/components/tree/tree.style.js +16 -0
  155. package/src/components/tree-item/tree-item.changelog.md +23 -0
  156. package/src/components/tree-item/tree-item.define.js +3 -0
  157. package/src/components/tree-item/tree-item.events.js +3 -0
  158. package/src/components/tree-item/tree-item.js +246 -0
  159. package/src/components/tree-item/tree-item.readme.md +128 -0
  160. package/src/components/tree-item/tree-item.style.js +226 -0
  161. package/src/styles/appearance.style.js +47 -0
  162. package/src/styles/choice-group.style.js +27 -1
  163. package/src/styles/input-control.style.js +87 -0
  164. package/src/styles/modal.style.js +14 -1
  165. package/src/styles/native.css +100 -0
  166. package/src/styles/size.style.js +41 -0
  167. package/src/utils/floating.js +15 -1
  168. package/src/utils/focus.js +69 -0
  169. package/src/utils/options.js +35 -0
  170. package/src/utils/scroll.js +24 -0
  171. package/src/utils/text-entry-attributes.js +13 -0
  172. package/types/all.d.ts +16 -0
  173. package/types/src/components/accordion/accordion.d.ts +3 -1
  174. package/types/src/components/app-bar/app-bar.d.ts +43 -0
  175. package/types/src/components/app-bar/app-bar.define.d.ts +1 -0
  176. package/types/src/components/app-bar/app-bar.style.d.ts +2 -0
  177. package/types/src/components/app-frame/app-frame.d.ts +497 -0
  178. package/types/src/components/app-frame/app-frame.define.d.ts +1 -0
  179. package/types/src/components/app-frame/app-frame.events.d.ts +7 -0
  180. package/types/src/components/app-frame/app-frame.style.d.ts +8 -0
  181. package/types/src/components/button/button.d.ts +61 -0
  182. package/types/src/components/button/button.events.d.ts +4 -0
  183. package/types/src/components/checkbox-group-field/checkbox-group-field.d.ts +5 -2
  184. package/types/src/components/combobox-field/combobox-field.d.ts +10 -0
  185. package/types/src/components/date-field/date-field.d.ts +10 -0
  186. package/types/src/components/description-list/description-list.d.ts +34 -0
  187. package/types/src/components/description-list/description-list.define.d.ts +1 -0
  188. package/types/src/components/description-list/description-list.style.d.ts +2 -0
  189. package/types/src/components/file-field/file-field.d.ts +68 -3
  190. package/types/src/components/form-field/form-field.d.ts +1 -1
  191. package/types/src/components/input-field/input-field.d.ts +99 -0
  192. package/types/src/components/list/list.d.ts +41 -0
  193. package/types/src/components/list/list.define.d.ts +1 -0
  194. package/types/src/components/list/list.style.d.ts +2 -0
  195. package/types/src/components/list-item/list-item.d.ts +64 -0
  196. package/types/src/components/list-item/list-item.define.d.ts +1 -0
  197. package/types/src/components/list-item/list-item.style.d.ts +2 -0
  198. package/types/src/components/menu/menu.d.ts +362 -0
  199. package/types/src/components/menu/menu.define.d.ts +1 -0
  200. package/types/src/components/menu/menu.events.d.ts +6 -0
  201. package/types/src/components/menu/menu.style.d.ts +2 -0
  202. package/types/src/components/menu-group/menu-group.d.ts +24 -0
  203. package/types/src/components/menu-group/menu-group.define.d.ts +1 -0
  204. package/types/src/components/menu-group/menu-group.style.d.ts +2 -0
  205. package/types/src/components/menu-item/menu-item.d.ts +80 -0
  206. package/types/src/components/menu-item/menu-item.define.d.ts +1 -0
  207. package/types/src/components/menu-item/menu-item.style.d.ts +2 -0
  208. package/types/src/components/nav/nav.d.ts +103 -0
  209. package/types/src/components/nav/nav.define.d.ts +1 -0
  210. package/types/src/components/nav/nav.style.d.ts +2 -0
  211. package/types/src/components/nav-item/nav-item.d.ts +39 -0
  212. package/types/src/components/nav-item/nav-item.define.d.ts +1 -0
  213. package/types/src/components/nav-item/nav-item.style.d.ts +2 -0
  214. package/types/src/components/otp-field/otp-field.d.ts +10 -0
  215. package/types/src/components/pagination/pagination.d.ts +31 -2
  216. package/types/src/components/password-field/password-field.d.ts +10 -0
  217. package/types/src/components/radio-field/radio-field.d.ts +5 -2
  218. package/types/src/components/scroll-to-top/scroll-to-top.d.ts +6 -5
  219. package/types/src/components/segmented-field/segmented-field.d.ts +85 -0
  220. package/types/src/components/segmented-field/segmented-field.define.d.ts +1 -0
  221. package/types/src/components/segmented-field/segmented-field.style.d.ts +2 -0
  222. package/types/src/components/splitter/splitter.d.ts +127 -0
  223. package/types/src/components/splitter/splitter.define.d.ts +1 -0
  224. package/types/src/components/splitter/splitter.events.d.ts +5 -0
  225. package/types/src/components/splitter/splitter.style.d.ts +2 -0
  226. package/types/src/components/status-bar/status-bar.d.ts +44 -0
  227. package/types/src/components/status-bar/status-bar.define.d.ts +1 -0
  228. package/types/src/components/status-bar/status-bar.style.d.ts +2 -0
  229. package/types/src/components/tab-group/tab-group.d.ts +17 -0
  230. package/types/src/components/textarea-field/textarea-field.d.ts +7 -0
  231. package/types/src/components/toolbar/toolbar.d.ts +96 -0
  232. package/types/src/components/toolbar/toolbar.define.d.ts +1 -0
  233. package/types/src/components/toolbar/toolbar.style.d.ts +2 -0
  234. package/types/src/components/tooltip/tooltip.d.ts +26 -0
  235. package/types/src/components/tree/tree.d.ts +62 -0
  236. package/types/src/components/tree/tree.define.d.ts +1 -0
  237. package/types/src/components/tree/tree.style.d.ts +2 -0
  238. package/types/src/components/tree-item/tree-item.d.ts +106 -0
  239. package/types/src/components/tree-item/tree-item.define.d.ts +1 -0
  240. package/types/src/components/tree-item/tree-item.events.d.ts +4 -0
  241. package/types/src/components/tree-item/tree-item.style.d.ts +2 -0
  242. package/types/src/styles/appearance.style.d.ts +31 -0
  243. package/types/src/styles/choice-group.style.d.ts +1 -1
  244. package/types/src/styles/input-control.style.d.ts +15 -0
  245. package/types/src/styles/modal.style.d.ts +5 -0
  246. package/types/src/styles/size.style.d.ts +24 -0
  247. package/types/src/utils/floating.d.ts +11 -0
  248. package/types/src/utils/focus.d.ts +25 -0
  249. package/types/src/utils/options.d.ts +17 -0
  250. package/types/src/utils/scroll.d.ts +11 -0
  251. package/types/src/utils/text-entry-attributes.d.ts +10 -0
  252. package/web-types.json +2935 -308
@@ -1,18 +1,38 @@
1
1
  import { html, defineElement, classMap, when, optionalAttribute, spreadAttributes } from '@webtides/element-js';
2
2
  import FormField from '../form-field/form-field.js';
3
- import { shadowNativeTextEntryProperties, textEntryAttributes } from '../../utils/text-entry-attributes.js';
3
+ import {
4
+ lengthAttribute,
5
+ shadowNativeTextEntryProperties,
6
+ textEntryAttributes,
7
+ } from '../../utils/text-entry-attributes.js';
4
8
  import style from './input-field.style.js';
5
9
 
10
+ /** What is a control of its own in the content of the page: it has a name and a stop of the Tab key. */
11
+ const CONTROL = 'a[href], button, input, select, textarea, [tabindex], el-button, el-copy-button';
12
+
13
+ /** What takes the focus of a click itself. Asked of everything a click has passed, shadow roots included. */
14
+ const FOCUSABLE = 'a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]';
15
+
6
16
  /**
7
17
  * Native `<input>` wrapper with label, help text, validation feedback (visual checkmark /
8
18
  * cross indicators) and ARIA wiring. Extends `FormField` and inherits its label / help /
9
19
  * error / required surface.
10
20
  *
21
+ * The page can put content at the start and at the end of the control: an element with
22
+ * `slot="start"` or `slot="end"` among the children of the field. The field has no shadow root,
23
+ * so these are no slots of the platform: the field takes the elements into its control when it
24
+ * renders. And `clearable` adds a button that empties the field.
25
+ *
11
26
  * @element el-input-field
12
27
  *
13
28
  * @fires {CustomEvent<string>} input-change - Fired when the input's value changes.
14
29
  * `detail` is the new value. Bubbles.
15
30
  *
31
+ * @slot start - Content at the start of the control, in front of the text: an icon, a text, a
32
+ * button. An element of the page with `slot="start"`.
33
+ * @slot end - Content at the end of the control, after the text: a unit, a button. An element of
34
+ * the page with `slot="end"`.
35
+ *
16
36
  * @property {string} type - Native `type` attribute of the underlying `<input>` (e.g.
17
37
  * `'text'`, `'email'`, `'password'`, `'tel'`, `'url'`).
18
38
  * @property {'small'|'medium'|'large'} size - Size of the control: its height, its padding and its
@@ -22,6 +42,15 @@ import style from './input-field.style.js';
22
42
  * @property {string | false} pattern - Regular expression used as the input's `pattern`
23
43
  * attribute. When `false` (the default), the `pattern` attribute is omitted entirely, so
24
44
  * the field applies no pattern constraint.
45
+ * @property {boolean} clearable - Whether the control has a button that empties it. The button
46
+ * shows while the field has a value and is not disabled. Default `false`.
47
+ * @property {string} clearLabel - The name of that button for assistive technology. Default
48
+ * `'Clear'`.
49
+ * @property {number | null} maxlength - Passed on to the control as `maxlength`: the browser takes
50
+ * no more characters than this while the user types. `null` (the default) leaves the attribute
51
+ * out.
52
+ * @property {number | null} minlength - Passed on as `minlength`: a text the user has typed that is
53
+ * shorter makes the field invalid. `null` (the default) leaves the attribute out.
25
54
  * @property {string | null} autocomplete - Passed on to the control as its `autocomplete`
26
55
  * attribute (e.g. `'email'`, `'current-password'`, `'one-time-code'`). `null` (the default)
27
56
  * leaves the attribute out. The same holds for the five properties below.
@@ -53,6 +82,10 @@ export default class InputField extends FormField {
53
82
  size: 'medium',
54
83
  placeholder: '',
55
84
  pattern: false,
85
+ clearable: false,
86
+ clearLabel: 'Clear',
87
+ maxlength: null,
88
+ minlength: null,
56
89
  autocomplete: null,
57
90
  inputmode: null,
58
91
  enterkeyhint: null,
@@ -62,6 +95,13 @@ export default class InputField extends FormField {
62
95
  };
63
96
  }
64
97
 
98
+ connectedCallback() {
99
+ // A server renders the template without the lifecycle: from here on the field is in a
100
+ // browser, and what the page has put into it are nodes the template takes in.
101
+ this._started = true;
102
+ super.connectedCallback();
103
+ }
104
+
65
105
  watch() {
66
106
  const watchers = super.watch();
67
107
  return {
@@ -75,6 +115,97 @@ export default class InputField extends FormField {
75
115
  };
76
116
  }
77
117
 
118
+ events() {
119
+ const events = super.events();
120
+ return {
121
+ ...events,
122
+ '.control': {
123
+ click: (event) => this._onControlClick(event),
124
+ },
125
+ '[data-clear]': {
126
+ click: () => this.clearInput(),
127
+ },
128
+ };
129
+ }
130
+
131
+ /**
132
+ * The elements the page has put into the field for the start or the end of its control:
133
+ * `<span slot="end">€</span>`. They are children of the field until it renders, and in
134
+ * their place in the control from then on, also in server-rendered markup. An element that
135
+ * comes later is taken in with the next render.
136
+ * @private
137
+ * @param {'start'|'end'} name
138
+ * @returns {Element[]}
139
+ */
140
+ _slotted(name) {
141
+ const placed = this._started ? this.querySelector(`:scope > .field > .control > .control-${name}`) : null;
142
+ return [
143
+ ...(placed ? placed.children : []),
144
+ ...[...this.children].filter((child) => child.getAttribute('slot') === name),
145
+ ];
146
+ }
147
+
148
+ /**
149
+ * The content for a place in the control. In a browser the elements of the page themselves:
150
+ * they are moved, not copied, and stay where they are with every render. On a server their
151
+ * markup, written as it is.
152
+ *
153
+ * That is what `unsafeHTML()` gives on a server. It is written out here because the directive
154
+ * gives nodes wherever there is a DOM, and a template that is turned into a string in a
155
+ * browser, as the tests of the server-rendered markup do, would lose them.
156
+ * @private
157
+ * @param {Element[]} elements
158
+ * @returns {Element[] | { __unsafeHTML: true, string: string }}
159
+ */
160
+ _content(elements) {
161
+ if (this._started) return elements;
162
+ return { __unsafeHTML: true, string: elements.map((element) => element.outerHTML).join('') };
163
+ }
164
+
165
+ /**
166
+ * Whether what the page has put at a place describes the value: a unit, a currency, the start
167
+ * of an address. A screen reader reads it with the input then. A control there, a button or
168
+ * a link, has a name and a stop of the Tab key itself, and is no description. An icon is none
169
+ * either: it has no text, and is hidden from assistive technology (`aria-hidden`).
170
+ * @private
171
+ * @param {Element[]} elements
172
+ * @returns {boolean}
173
+ */
174
+ _describes(elements) {
175
+ return (
176
+ elements.some((element) => element.textContent.trim() !== '') &&
177
+ !elements.some((element) => element.matches(CONTROL) || element.querySelector(CONTROL))
178
+ );
179
+ }
180
+
181
+ /**
182
+ * The description of the control: what the page has put at its start and at its end, then the
183
+ * messages of the field.
184
+ * @private
185
+ * @returns {string}
186
+ */
187
+ _describedBy() {
188
+ const { start = [], end = [] } = this._controlContent ?? {};
189
+ const ids = [];
190
+ if (this._describes(start)) ids.push(this._idOf('control-start'));
191
+ if (this._describes(end)) ids.push(this._idOf('control-end'));
192
+ return [...ids, super._describedBy()].join(' ');
193
+ }
194
+
195
+ /**
196
+ * A click on the control beside its input, on a text or an icon of the page, puts the focus
197
+ * into the input: to the eye all of it is the control. A control in the content, the button
198
+ * that clears the field and the input itself keep their click.
199
+ * @private
200
+ * @param {MouseEvent} event
201
+ */
202
+ _onControlClick(event) {
203
+ const path = event.composedPath();
204
+ const inside = path.slice(0, path.indexOf(event.currentTarget));
205
+ if (inside.some((node) => node instanceof Element && node.matches(FOCUSABLE))) return;
206
+ this.$refs.input.focus();
207
+ }
208
+
78
209
  /**
79
210
  * The pattern of the control. A field that extends this one can have a pattern of its own
80
211
  * where the page gives none (`OtpField`).
@@ -105,8 +236,13 @@ export default class InputField extends FormField {
105
236
  fieldTemplate() {
106
237
  const pattern = this._pattern();
107
238
  const { list = null, min = null, max = null, step = null } = this._controlAttributes();
239
+ const start = this._slotted('start');
240
+ const end = this._slotted('end');
241
+ const clearable = this.clearable === true || this.clearable === 'true' || this.clearable === '';
242
+ // The description of the input names the content, so it is found before the input.
243
+ this._controlContent = { start, end };
108
244
 
109
- return html`
245
+ const input = html`
110
246
  <input
111
247
  ref="input"
112
248
  id="${this._idOf('input')}"
@@ -121,23 +257,65 @@ export default class InputField extends FormField {
121
257
  min="${min}"
122
258
  max="${max}"
123
259
  step="${step}"
260
+ maxlength="${lengthAttribute(this.maxlength)}"
261
+ minlength="${lengthAttribute(this.minlength)}"
124
262
  ${spreadAttributes(textEntryAttributes(this))}
125
263
  aria-describedby="${this._describedBy()}"
126
264
  aria-invalid="${this.valid ? 'false' : 'true'}"
127
265
  aria-errormessage="${this._idOf('error-message')}"
128
266
  />
129
- ${when(
130
- this.touched,
131
- html`
132
- <div class="validity ${classMap({ 'is-valid': !!this.valid, 'is-invalid': !this.valid })}">
133
- ${when(
134
- this.valid,
135
- html` <span class="valid h-4 w-4">&checkmark;</span> `,
136
- html` <span class="invalid h-4 w-4" data-clear-input>&cross;</span> `,
137
- )}
138
- </div>
139
- `,
140
- )}
267
+ `;
268
+ const validity = when(
269
+ this.touched,
270
+ html`
271
+ <div class="validity ${classMap({ 'is-valid': !!this.valid, 'is-invalid': !this.valid })}">
272
+ ${when(
273
+ this.valid,
274
+ html` <span class="valid h-4 w-4">&checkmark;</span> `,
275
+ html` <span class="invalid h-4 w-4" data-clear-input>&cross;</span> `,
276
+ )}
277
+ </div>
278
+ `,
279
+ );
280
+
281
+ // A field without any of it is its input, as it was.
282
+ if (!start.length && !end.length && !clearable) return html`${input} ${validity}`;
283
+
284
+ // The button shows while there is something to clear, and has its place in the markup
285
+ // all the time. The mark of the validity stays beside the control.
286
+ const clears = clearable && String(this.value ?? '') !== '' && !this.disabled;
287
+ return html`
288
+ <div class="control">
289
+ <span
290
+ id="${this._idOf('control-start')}"
291
+ class="control-content control-start"
292
+ ?hidden="${!start.length}"
293
+ >${this._content(start)}</span
294
+ >
295
+ ${input}
296
+ <button
297
+ type="button"
298
+ class="control-clear"
299
+ data-clear
300
+ aria-label="${this.clearLabel}"
301
+ ?hidden="${!clears}"
302
+ >
303
+ <svg
304
+ viewBox="0 0 24 24"
305
+ fill="none"
306
+ stroke="currentColor"
307
+ stroke-width="2"
308
+ stroke-linecap="round"
309
+ aria-hidden="true"
310
+ >
311
+ <path d="M6 6l12 12M18 6L6 18"></path>
312
+ </svg>
313
+ </button>
314
+ <span id="${this._idOf('control-end')}" class="control-content control-end" ?hidden="${!end.length}"
315
+ >${this._content(end)}</span
316
+ >
317
+ </div>
318
+ ${validity}
141
319
  `;
142
320
  }
143
321
  }
@@ -40,6 +40,10 @@ import '@webtides/element-library/input-field/define';
40
40
  | `size` | `string` | `'medium'` | `small`, `medium` or `large`: the height, the padding and the font size of the control. Reflected. Shows once `styles/native.css` decorates the control. |
41
41
  | `placeholder` | `string` | `''` | Placeholder text displayed when the input is empty |
42
42
  | `pattern` | `string\|boolean` | `false` | Regular expression pattern for input validation. If false, allows any input |
43
+ | `clearable` | `boolean` | `false` | Whether the control has a button that empties it. The button shows while the field has a value and is not disabled |
44
+ | `clearLabel` | `string` | `'Clear'` | The name of that button for assistive technology |
45
+ | `maxlength` | `number` | `null` | Passed on to the control as `maxlength`: the browser takes no more characters than this while the user types |
46
+ | `minlength` | `number` | `null` | Passed on as `minlength`: a text the user has typed that is shorter makes the field invalid |
43
47
  | `autocomplete` | `string` | `null` | Passed on to the control as `autocomplete` (e.g. `email`, `current-password`, `one-time-code`) |
44
48
  | `inputmode` | `string` | `null` | Passed on as `inputmode`: the on-screen keyboard to show (e.g. `numeric`, `email`) |
45
49
  | `enterkeyhint` | `string` | `null` | Passed on as `enterkeyhint`: the label of the enter key on an on-screen keyboard (e.g. `next`, `send`) |
@@ -82,7 +86,65 @@ On a touch screen (`@media (any-pointer: coarse)`) the input is at least `--el-t
82
86
 
83
87
  #### Slots
84
88
 
85
- _None_ - The component generates its own input element internally
89
+ The field has no shadow root, so these are no slots of the platform: an element of the page with the `slot` attribute, among the children of the field, is taken into the control when the field renders. See [Content in the control](#content-in-the-control).
90
+
91
+ | Name | Description |
92
+ | ------- | ------------------------------------------------------------------------------------- |
93
+ | `start` | Content at the start of the control, in front of the text: an icon, a text, a button. |
94
+ | `end` | Content at the end of the control, after the text: a unit, a button. |
95
+
96
+ ## Content in the control
97
+
98
+ A search field with a magnifying glass, a price with its currency, an address that starts with `https://`, a key with a button that copies it: the page puts an element with `slot="start"` or `slot="end"` into the field, and the field takes it into its control.
99
+
100
+ ```html
101
+ <el-input-field name="q" label="Search" clearable="true">
102
+ <svg slot="start" aria-hidden="true">…</svg>
103
+ </el-input-field>
104
+
105
+ <el-input-field name="price" label="Price" inputmode="decimal">
106
+ <span slot="end">Euro</span>
107
+ </el-input-field>
108
+
109
+ <el-input-field name="site" label="Your site">
110
+ <span slot="start">https://</span>
111
+ </el-input-field>
112
+
113
+ <el-input-field name="key" label="Key" value="4f2a-91c7">
114
+ <el-copy-button slot="end" value="4f2a-91c7"></el-copy-button>
115
+ </el-input-field>
116
+ ```
117
+
118
+ - **In the control.** The content stands in a row with the input, the start in front of it and the end after it, and the text of the input does not run under it: the input is as wide as what is left. In a right-to-left page the start is at the right.
119
+ - **The elements of the page themselves.** The field moves them, it does not copy them: a listener of the page stays on its button, and the element is the same after every render. An element that comes later is taken in with the next render (`field.requestUpdate()`). A text needs an element around it (`<span slot="end">kg</span>`).
120
+ - **A click on a text or on an icon** puts the focus into the input: to the eye all of it is the control. **A button or a link** there keeps its click and is a stop of the Tab key of its own, after the input for one at the end.
121
+ - **A text is read with the input.** A unit or a currency is part of what the value means, so the input names the content as a part of its description (`aria-describedby`), in front of the help message: "Price, edit text, Euro". Write a text a screen reader can say, "Euro" before "€". **An icon is not**: give it `aria-hidden="true"`. Content with a control in it is no description either: the button has a name of its own.
122
+ - **The mark of a field that was touched** (✓ or ✗) keeps its place beside the control, and does not lie on the content at the end.
123
+ - **Server-rendered**, the content is in its place in the markup, and the element takes it over where it is.
124
+
125
+ #### With and without `styles/native.css`
126
+
127
+ The border of a native input cannot have anything inside of it. So the field renders a row around the input (`.control`), only while there is content for it or the field is `clearable`, and [`styles/native.css`](../../styles/native.css) makes that row the control: it has the border, the surface and the radius of an input, and the input inside of it has none. The focus ring is around all of it while the input has the focus, and not for a button in it, which has its own. The border of a field that is not valid is around all of it, and a disabled field fades as a whole. The row is as high as an input of its `size` alone.
128
+
129
+ Without that file the input keeps the border of the browser, as every control does, and the content stands beside it in the row.
130
+
131
+ #### The button that clears the field
132
+
133
+ `clearable="true"` adds a button at the end of the control, in front of the content at the end. It shows while the field has a value and is not disabled.
134
+
135
+ ```html
136
+ <el-input-field name="city" label="City" clearable="true" clear-label="Clear the city"></el-input-field>
137
+ ```
138
+
139
+ - It empties the value, `input-change` reports the empty value, and the focus is in the input after.
140
+ - It is a button with a name (`clear-label`, `Clear` by default: set it for other languages), and a stop of the Tab key after the input.
141
+ - On a touch screen it is at least `--el-touch-target` wide and high.
142
+
143
+ The fields that extend this one have both: [`el-combobox-field`](../combobox-field/combobox-field.readme.md), [`el-date-field`](../date-field/date-field.readme.md), [`el-otp-field`](../otp-field/otp-field.readme.md) and [`el-password-field`](../password-field/password-field.readme.md), which keeps its own button beside the control.
144
+
145
+ #### Not in this element
146
+
147
+ Two controls joined into one row: a select for the country code in front of a phone number, a button outside of the field that touches it. A select or a textarea with content in it.
86
148
 
87
149
  ## Keyboard and autofill hints
88
150
 
@@ -100,9 +162,33 @@ _None_ - The component generates its own input element internally
100
162
 
101
163
  Removing one of these attributes later leaves it empty (`autocomplete=""`) on the element and on the control, if it was there when the element started: element-js writes a removed attribute back empty. An empty value has the meaning of the default: on for `spellcheck` and `autocorrect`, the browser's own choice for the other four.
102
164
 
165
+ ## The length of the text
166
+
167
+ `maxlength` and `minlength` are passed on to the control, in server-rendered markup as well, and one that is not set is not rendered. The browser does the rest:
168
+
169
+ ```html
170
+ <el-input-field
171
+ name="name"
172
+ label="Name"
173
+ maxlength="100"
174
+ minlength="2"
175
+ error-message="At least 2 characters"
176
+ ></el-input-field>
177
+ ```
178
+
179
+ - **`maxlength`**: the control takes no more characters while the user types or pastes. Nothing is invalid for it: the text is never longer.
180
+ - **`minlength`**: a text the user has typed that is shorter makes the field invalid, the way `required` and `pattern` do: `valid` is `false`, the field shows its `error-message` once it was touched, and the form is not submitted.
181
+ - **Only what the user has typed is measured.** A browser does not hold a value against these limits that the page or the server has put into the control. A value from the server that is too long or too short is valid until the user changes it: the server checks what it gets.
182
+ - **An empty field is not too short.** `minlength` is for a text that is there. Add `required` for a field that has to be filled.
183
+ - **Say the limit.** The field shows no counter and no limit of its own: name it in `help-message`, and in `error-message` for the least length.
184
+
185
+ The fields that extend this one take both as well (`el-password-field`, `el-combobox-field`). An `el-otp-field` has `length` for its code, and a date has no length.
186
+
103
187
  ## Accessibility
104
188
 
105
189
  - Includes proper ARIA attributes (`aria-describedby`, `aria-invalid`, `aria-errormessage`)
190
+ - A text at the start or at the end of the control is part of the description of the input, an icon is not, and a button there is a control of its own
191
+ - The button that clears the field has a name (`clear-label`)
106
192
  - Links labels to inputs via `for` attribute
107
193
  - Supports screen reader only labels
108
194
  - Visual validity indicators (✓ for valid, × for invalid)
@@ -115,5 +201,5 @@ The component provides real-time validation feedback:
115
201
  - Validation state updates on focus, blur, and change events
116
202
  - Visual indicators appear after the field is touched
117
203
  - Error messages only display when field is touched and invalid
118
- - Supports HTML5 validation attributes (required, pattern, type)
204
+ - Supports HTML5 validation attributes (required, pattern, minlength, type)
119
205
  - Clicking the invalid indicator (×) clears the input
@@ -1,6 +1,7 @@
1
1
  import hostStyle from '../../styles/host.style.js';
2
2
  import formControlStyle from '../../styles/form-control.style.js';
3
3
  import sizeStyle from '../../styles/size.style.js';
4
+ import inputControlStyle from '../../styles/input-control.style.js';
4
5
 
5
6
  const css = String.raw;
6
7
 
@@ -48,5 +49,6 @@ export default [
48
49
  hostStyle('el-input-field'),
49
50
  formControlStyle('el-input-field'),
50
51
  sizeStyle('el-input-field'),
52
+ inputControlStyle('el-input-field'),
51
53
  style,
52
54
  ].join('\n');
@@ -0,0 +1,30 @@
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.5.0] - 2026-11-27
16
+
17
+ ### Added
18
+
19
+ - `--el-list-gap` sets the gap between the start, the texts, the end and the control of a row. The rows read it, so it can be set on the list or for the page. ([#206](https://github.com/webtides/element-library/issues/206))
20
+
21
+ ## [0.4.0] - 2026-11-27
22
+
23
+ ### Added
24
+
25
+ - Initial `el-list`: a list of rows, for messages, articles, files or the entries of a settings page. It is the list for assistive technology (`role="list"`, named by `label`), and every `el-list-item` slotted into it is an item of that list. ([#192](https://github.com/webtides/element-library/issues/192))
26
+ - The texts of all rows begin on one line, after the widest start of the list: the list has a column for the start and one for the rest, and a row takes them over (`subgrid`). A list without a start in any row has no first column.
27
+ - `density` (`'default'` or `'compact'`): `--el-space-3` or `--el-space-2` above and below the texts of a row.
28
+ - `appearance`: `'plain'` (the default) has no surface and reaches from edge to edge of its place; `'outlined'` and `'filled'` are the surfaces of `el-card`. Between two rows is a line in `--el-color-border`. Without a theme the list paints nothing.
29
+ - `--el-list-padding-inline` is the padding of a row at its start and its end, `--el-space-4` unset. With `0` a list in the body of an `el-card` has its rows on the line of the other content.
30
+ - The list runs no script: a server-rendered list is complete without JavaScript, and looks the same before and after the element takes over.
@@ -0,0 +1,3 @@
1
+ import { define } from './list.js';
2
+
3
+ define();
@@ -0,0 +1,68 @@
1
+ import { TemplateElement, defineElement, html, spreadAttributes } from '@webtides/element-js';
2
+ import style from './list.style.js';
3
+
4
+ /**
5
+ * A list of rows: messages, articles, files, the entries of a settings page. The list is the
6
+ * surface and the list for assistive technology; every `el-list-item` slotted into it is one row.
7
+ * It gives its rows one density, one line between two of them and one place where their texts
8
+ * begin, whatever stands at the start of a row.
9
+ *
10
+ * Pure presentation: the list runs no script of its own, so a server-rendered list is complete
11
+ * before the element takes over.
12
+ *
13
+ * @element el-list
14
+ *
15
+ * @slot - The rows: `el-list-item` elements.
16
+ *
17
+ * @csspart base - The list (`role="list"`) and its surface.
18
+ *
19
+ * @cssproperty --el-list-padding-inline - The padding of a row at its start and its end. Unset, it
20
+ * is `--el-space-4`, and `1rem` without a theme. Read by the rows, so it can be set on the list
21
+ * or for the page.
22
+ * @cssproperty --el-list-gap - The gap between the start, the texts, the end and the control of a
23
+ * row. Unset, it is `--el-space-3`, and `0.75rem` without a theme. Read by the rows as well.
24
+ *
25
+ * @property {string} label - The name of the list for assistive technology. Unset, the list has
26
+ * none.
27
+ * @property {'default'|'compact'} density - How much room a row has above and below its texts.
28
+ * Default `'default'`. Reflected to the `density` attribute.
29
+ * @property {'plain'|'outlined'|'filled'} appearance - How the surface is painted: not at all, so
30
+ * the list reaches from edge to edge of its place, or as a card with the background of the page
31
+ * or a muted fill, a border and round corners. Default `'plain'`. Reflected to the `appearance`
32
+ * attribute.
33
+ */
34
+ export default class List extends TemplateElement {
35
+ constructor() {
36
+ super({
37
+ styles: [style],
38
+ shadowRender: true,
39
+ // The stylesheet selects the host by these attributes.
40
+ propertyOptions: {
41
+ density: { reflect: true },
42
+ appearance: { reflect: true },
43
+ },
44
+ });
45
+ }
46
+
47
+ properties() {
48
+ return {
49
+ label: '',
50
+ density: 'default',
51
+ appearance: 'plain',
52
+ };
53
+ }
54
+
55
+ template() {
56
+ // The role is inside of the shadow root, not on the element: it is part of the
57
+ // server-rendered markup that way, and needs no script.
58
+ return html`
59
+ <div part="base" class="list" role="list" ${spreadAttributes({ 'aria-label': this.label || undefined })}>
60
+ <slot></slot>
61
+ </div>
62
+ `;
63
+ }
64
+ }
65
+
66
+ export function define() {
67
+ defineElement('el-list', List);
68
+ }
@@ -0,0 +1,123 @@
1
+ # List
2
+
3
+ `list` is a list of rows: messages, articles, files, the entries of a settings page. The list is the surface and the list for assistive technology; every [`el-list-item`](../list-item/list-item.readme.md) in it is one row. It gives its rows one density, one line between two of them, and one place where their texts begin.
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/list/define';
17
+ import '@webtides/element-library/list-item/define';
18
+ ```
19
+
20
+ ```html
21
+ <el-list label="Messages">
22
+ <el-list-item href="/messages/1" mark="Unread">
23
+ <el-avatar slot="start" initials="AL" label="Ada Lovelace"></el-avatar>
24
+ Ada Lovelace
25
+ <span slot="description">The notes on the engine are ready for you.</span>
26
+ <time slot="end" datetime="09:12">09:12</time>
27
+ </el-list-item>
28
+ <el-list-item href="/messages/2" current="true">
29
+ <el-avatar slot="start" initials="GH" label="Grace Hopper"></el-avatar>
30
+ Grace Hopper
31
+ <span slot="description">Found it. A moth, in relay 70.</span>
32
+ <time slot="end" datetime="08:40">08:40</time>
33
+ </el-list-item>
34
+ </el-list>
35
+ ```
36
+
37
+ > Boolean attributes are passed as strings (`current="true"`), matching the rest of the library.
38
+
39
+ ## API
40
+
41
+ #### Properties/Attributes
42
+
43
+ | Name | Type | Default | Description |
44
+ | --- | --- | --- | --- |
45
+ | `label` | `string` | `''` | The name of the list for assistive technology. Unset, the list has none. |
46
+ | `density` | `'default' \| 'compact'` | `'default'` | How much room a row has above and below its texts. Reflected to the `density` attribute. |
47
+ | `appearance` | `'plain' \| 'outlined' \| 'filled'` | `'plain'` | How the surface is painted: not at all, or as a card with the background of the page or a muted fill. Reflected to the `appearance` attribute. |
48
+
49
+ #### Methods
50
+
51
+ _None._
52
+
53
+ #### Events
54
+
55
+ _None._
56
+
57
+ #### Slots
58
+
59
+ | Name | Description |
60
+ | --------- | ---------------------------------- |
61
+ | (default) | The rows: `el-list-item` elements. |
62
+
63
+ #### CSS Parts
64
+
65
+ | Name | Description |
66
+ | ------ | ----------------------------------------- |
67
+ | `base` | The list (`role="list"`) and its surface. |
68
+
69
+ #### CSS Custom Properties
70
+
71
+ | Name | Default | Description |
72
+ | --- | --- | --- |
73
+ | `--el-list-padding-inline` | `--el-space-4` | The padding of a row at its start and its end. Read by the rows, so it can be set on the list or for the page. Without a theme it is `1rem`. |
74
+ | `--el-list-gap` | `--el-space-3` | The gap between the start, the texts, the end and the control of a row. Read by the rows as well. Without a theme it is `0.75rem`. See [the gaps of a row](../list-item/list-item.readme.md#the-gaps-of-a-row). |
75
+
76
+ ## Where the texts begin
77
+
78
+ What stands at the start of a row differs: an avatar in one row, a small icon in the next, nothing in a third. The texts of all rows of a list begin on one line all the same, after the widest start of the list. The list has two columns, the start and the rest, and every row takes them over (`subgrid`). A list in which no row has a start has no first column: its texts begin at the padding of the row.
79
+
80
+ A `mark` of a row (an unread message) is a dot in that padding. It moves nothing.
81
+
82
+ ## Density
83
+
84
+ `density="compact"` gives a row less room above and below its texts: `--el-space-2` in the place of `--el-space-3`, `0.5rem` in the place of `0.75rem` without a theme. Nothing else changes: the texts, the gap and the padding at the sides are the same.
85
+
86
+ On a touch screen (`@media (any-pointer: coarse)`) a row that is a link is at least `--el-touch-target` high in either density. A row that is no target stays as compact as it is.
87
+
88
+ ## From edge to edge, and as a card
89
+
90
+ - `appearance="plain"`, the default: no surface. The list is as wide as its place, and a line reaches from one edge of it to the other. That is the list of a phone screen, or of a column that is one.
91
+ - `appearance="outlined"`: the surface of an `el-card`, with the background of the page, a border, round corners and the shadow of the theme.
92
+ - `appearance="filled"`: the same with the muted fill.
93
+
94
+ Between two rows is a line in `--el-color-border`, `--el-border-width` wide. Without a theme the list is headless: no line, no border, no fill.
95
+
96
+ A list in the body of an `el-card` has the padding of the card around it. `--el-list-padding-inline: 0` puts its rows on the line of the other content of the card:
97
+
98
+ ```html
99
+ <el-card>
100
+ <strong slot="header">Folders</strong>
101
+ <el-list label="Folders" style="--el-list-padding-inline: 0">
102
+ <el-list-item href="/inbox">Inbox <span slot="end">12</span></el-list-item>
103
+ <el-list-item href="/drafts">Drafts <span slot="end">2</span></el-list-item>
104
+ </el-list>
105
+ </el-card>
106
+ ```
107
+
108
+ The `hidden` attribute hides the list, and a row.
109
+
110
+ ## Accessibility
111
+
112
+ - The list has `role="list"`, and every row is an item of it: a screen reader says how many rows the list has and where its user is in it.
113
+ - `label` names the list. A screen reader reads the name when its user enters the list; without it the list has none. A list of links that is the navigation of a page belongs into a `<nav>` of the page.
114
+ - The list has no keyboard model of its own. The Tab key goes from one link or control to the next, in the order of the rows.
115
+
116
+ ## Server-side rendering
117
+
118
+ The list, its name and the rows are part of the server-rendered markup (Declarative Shadow DOM), with their links. The list runs no script: it looks the same before and after its JavaScript has loaded, its links work before that, and without JavaScript.
119
+
120
+ ## What it is not
121
+
122
+ - No choice of several rows, no reordering by dragging, no swipe actions and no virtual scrolling.
123
+ - No groups with headings. Write a heading and a list after it for each group.