@webtides/element-library 0.4.0 → 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 (93) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/custom-elements.json +1543 -199
  3. package/package.json +1 -1
  4. package/src/components/app-frame/app-frame.changelog.md +14 -0
  5. package/src/components/app-frame/app-frame.js +14 -2
  6. package/src/components/app-frame/app-frame.readme.md +12 -3
  7. package/src/components/app-frame/app-frame.style.js +7 -0
  8. package/src/components/button/button.changelog.md +6 -0
  9. package/src/components/button/button.style.js +6 -1
  10. package/src/components/button-group/button-group.changelog.md +10 -0
  11. package/src/components/button-group/button-group.readme.md +2 -0
  12. package/src/components/button-group/button-group.style.js +6 -2
  13. package/src/components/checkbox-group-field/checkbox-group-field.changelog.md +6 -0
  14. package/src/components/checkbox-group-field/checkbox-group-field.js +7 -2
  15. package/src/components/checkbox-group-field/checkbox-group-field.readme.md +23 -1
  16. package/src/components/combobox-field/combobox-field.changelog.md +6 -0
  17. package/src/components/combobox-field/combobox-field.readme.md +8 -0
  18. package/src/components/combobox-field/combobox-field.style.js +2 -0
  19. package/src/components/date-field/date-field.changelog.md +6 -0
  20. package/src/components/date-field/date-field.readme.md +10 -0
  21. package/src/components/date-field/date-field.style.js +8 -3
  22. package/src/components/description-list/description-list.changelog.md +17 -0
  23. package/src/components/description-list/description-list.js +7 -2
  24. package/src/components/description-list/description-list.readme.md +30 -4
  25. package/src/components/description-list/description-list.style.js +57 -28
  26. package/src/components/divider/divider.changelog.md +6 -0
  27. package/src/components/divider/divider.readme.md +1 -1
  28. package/src/components/divider/divider.style.js +6 -0
  29. package/src/components/file-field/file-field.changelog.md +8 -0
  30. package/src/components/file-field/file-field.js +135 -5
  31. package/src/components/file-field/file-field.readme.md +35 -6
  32. package/src/components/file-field/file-field.style.js +71 -0
  33. package/src/components/form-field/form-field.js +1 -1
  34. package/src/components/input-field/input-field.changelog.md +10 -0
  35. package/src/components/input-field/input-field.js +192 -14
  36. package/src/components/input-field/input-field.readme.md +88 -2
  37. package/src/components/input-field/input-field.style.js +2 -0
  38. package/src/components/list/list.changelog.md +6 -0
  39. package/src/components/list/list.js +2 -0
  40. package/src/components/list/list.readme.md +1 -0
  41. package/src/components/list-item/list-item.changelog.md +16 -0
  42. package/src/components/list-item/list-item.js +2 -0
  43. package/src/components/list-item/list-item.readme.md +19 -1
  44. package/src/components/list-item/list-item.style.js +23 -11
  45. package/src/components/menu/menu.changelog.md +17 -0
  46. package/src/components/menu/menu.js +293 -70
  47. package/src/components/menu/menu.readme.md +47 -6
  48. package/src/components/menu/menu.style.js +6 -2
  49. package/src/components/menu-item/menu-item.changelog.md +8 -0
  50. package/src/components/menu-item/menu-item.js +41 -3
  51. package/src/components/menu-item/menu-item.readme.md +45 -7
  52. package/src/components/menu-item/menu-item.style.js +30 -0
  53. package/src/components/otp-field/otp-field.changelog.md +6 -0
  54. package/src/components/otp-field/otp-field.readme.md +8 -0
  55. package/src/components/otp-field/otp-field.style.js +8 -3
  56. package/src/components/password-field/password-field.changelog.md +7 -0
  57. package/src/components/password-field/password-field.readme.md +11 -1
  58. package/src/components/password-field/password-field.style.js +2 -0
  59. package/src/components/popover/popover.changelog.md +6 -0
  60. package/src/components/popover/popover.style.js +1 -0
  61. package/src/components/radio-field/radio-field.changelog.md +6 -0
  62. package/src/components/radio-field/radio-field.js +7 -2
  63. package/src/components/radio-field/radio-field.readme.md +23 -1
  64. package/src/components/textarea-field/textarea-field.changelog.md +6 -0
  65. package/src/components/textarea-field/textarea-field.js +14 -1
  66. package/src/components/textarea-field/textarea-field.readme.md +23 -1
  67. package/src/styles/choice-group.style.js +26 -0
  68. package/src/styles/input-control.style.js +87 -0
  69. package/src/styles/native.css +100 -0
  70. package/src/utils/floating.js +15 -1
  71. package/src/utils/options.js +35 -0
  72. package/src/utils/text-entry-attributes.js +13 -0
  73. package/types/src/components/app-frame/app-frame.d.ts +7 -1
  74. package/types/src/components/checkbox-group-field/checkbox-group-field.d.ts +5 -2
  75. package/types/src/components/combobox-field/combobox-field.d.ts +10 -0
  76. package/types/src/components/date-field/date-field.d.ts +10 -0
  77. package/types/src/components/description-list/description-list.d.ts +7 -2
  78. package/types/src/components/file-field/file-field.d.ts +68 -3
  79. package/types/src/components/form-field/form-field.d.ts +1 -1
  80. package/types/src/components/input-field/input-field.d.ts +99 -0
  81. package/types/src/components/list/list.d.ts +2 -0
  82. package/types/src/components/list-item/list-item.d.ts +2 -0
  83. package/types/src/components/menu/menu.d.ts +105 -9
  84. package/types/src/components/menu-item/menu-item.d.ts +21 -0
  85. package/types/src/components/otp-field/otp-field.d.ts +10 -0
  86. package/types/src/components/password-field/password-field.d.ts +10 -0
  87. package/types/src/components/radio-field/radio-field.d.ts +5 -2
  88. package/types/src/components/textarea-field/textarea-field.d.ts +7 -0
  89. package/types/src/styles/input-control.style.d.ts +15 -0
  90. package/types/src/utils/floating.d.ts +11 -0
  91. package/types/src/utils/options.d.ts +17 -0
  92. package/types/src/utils/text-entry-attributes.d.ts +10 -0
  93. package/web-types.json +514 -24
@@ -4,9 +4,16 @@ const css = String.raw;
4
4
 
5
5
  /*
6
6
  * The names and the values are elements of the page, slotted into the list. A rule for them here
7
- * (::slotted) loses against every rule of the page for the same property, a reset included. So
8
- * the rules below set what a reset leaves alone: the place in the grid, the padding, the text.
9
- * The line between two rows is not a border for that reason.
7
+ * (::slotted) loses against every rule of the page for the same property, whatever its
8
+ * specificity and its cascade layer, and a reset has such a rule for every element and for what an
9
+ * element generates: `*, ::before, ::after { margin: 0; padding: 0; border: 0 solid; }`.
10
+ *
11
+ * So the list takes nothing from the margin, the padding or the border of a name or a value. The
12
+ * room of a row is the gap between the rows of the grid, and the padding of the list above its
13
+ * first and below its last row. The gap between a name and its value is a column of the grid. The
14
+ * line between two rows is a box with a height, placed without a margin. What the rules below do
15
+ * set on the elements of the page is what such a reset leaves alone: the place in the grid, the
16
+ * text, a position.
10
17
  */
11
18
  const style = css`
12
19
  /* The list measures its own width: the layout follows the place the list has, not the
@@ -17,32 +24,45 @@ const style = css`
17
24
  }
18
25
 
19
26
  .list {
20
- --_el-description-list-padding: var(--el-space-3, 0.75rem);
21
- --_el-description-list-gap: var(--el-space-4, 1rem);
27
+ --_el-description-list-padding: var(--el-description-list-padding-block, var(--el-space-3, 0.75rem));
28
+ --_el-description-list-gap: var(--el-description-list-gap, var(--el-space-4, 1rem));
22
29
 
23
30
  display: grid;
24
31
  /* A name above its value. The second column is the one of the actions; without an action
25
32
  it has no width. */
26
33
  grid-template-columns: minmax(0, 1fr) auto;
27
34
  align-items: start;
35
+ /* A name and its value are two rows of the grid here, and the gap is between every two
36
+ rows. A value is moved up by that gap, to its name (see below): what is left after it,
37
+ and the gap to the next name, are the room below this row and above the next. The
38
+ room above the first row is the padding of the list. */
39
+ row-gap: var(--_el-description-list-padding);
28
40
  /* The lines between the rows are placed from here. */
29
41
  position: relative;
30
42
  margin: 0;
43
+ padding-block: var(--_el-description-list-padding) 0;
44
+ padding-inline: 0;
31
45
  color: var(--el-color-fg, inherit);
32
46
  font-family: var(--el-font-family, inherit);
33
47
  font-size: var(--el-font-size-md, inherit);
34
48
  line-height: var(--el-line-height, inherit);
35
49
  }
36
50
 
51
+ /* A list with nothing in it has no room for a row. A stylesheet in here cannot ask for less:
52
+ whether the element has a row in it (:has() in :host()) is not answered by every browser. */
53
+ :host(:empty) .list {
54
+ padding-block: 0;
55
+ }
56
+
37
57
  /* ── Name ─────────────────────────────────────────────────────────────── */
38
58
 
39
59
  /* Quieter than its value. Its line is as high as a line of the value, so the two stand on
40
- one line side by side without being moved against each other. */
60
+ one line side by side without being moved against each other. The margin is taken off: a
61
+ browser gives none to a dt, and the list counts on none. */
41
62
  ::slotted(dt) {
42
63
  grid-column: 1 / -1;
43
64
  min-width: 0;
44
65
  margin: 0;
45
- padding-block-start: var(--_el-description-list-padding);
46
66
  color: var(--el-color-fg-muted, inherit);
47
67
  font-size: var(--el-font-size-sm, 0.875em);
48
68
  line-height: 1lh;
@@ -52,12 +72,14 @@ const style = css`
52
72
  /* ── Value ────────────────────────────────────────────────────────────── */
53
73
 
54
74
  /* A long value breaks, inside of a word where it has to: it cannot widen the list. The margin
55
- is the one the browser gives a dd. */
75
+ is the one the browser gives a dd. It stands right under its name: moved up by the gap of
76
+ the grid, with a position, which takes no room and which a reset leaves alone. */
56
77
  ::slotted(dd) {
57
78
  grid-column: 1;
79
+ position: relative;
80
+ inset-block-start: calc(-1 * var(--_el-description-list-padding));
58
81
  min-width: 0;
59
82
  margin: 0;
60
- padding-block-end: var(--_el-description-list-padding);
61
83
  overflow-wrap: anywhere;
62
84
  }
63
85
 
@@ -65,31 +87,38 @@ const style = css`
65
87
 
66
88
  /* At the end of the row, as high as one line of the value and with its content in the middle
67
89
  of that line. A button is higher than a line: it reaches out of the box above and below, and
68
- the row stays as high as a row without an action. The box has no padding above and below,
69
- so its height is the same whichever way the page counts the sizes of its elements. */
90
+ the row stays as high as a row without an action. */
70
91
  ::slotted(dd[data-action]) {
71
92
  grid-column: 2;
72
93
  display: flex;
73
94
  align-items: center;
74
95
  height: 1lh;
75
- padding-block: 0;
76
- padding-inline-start: var(--_el-description-list-gap);
77
96
  overflow-wrap: normal;
78
97
  white-space: nowrap;
79
98
  }
80
99
 
100
+ /* The gap to the value is an empty box in front of the content of the action, as wide as the
101
+ gap: the column of the actions has no width, and no gap, in a list without an action. */
102
+ ::slotted(dd[data-action])::before {
103
+ content: '';
104
+ flex: none;
105
+ inline-size: var(--_el-description-list-gap);
106
+ }
107
+
81
108
  /* ── Line between two rows ────────────────────────────────────────────── */
82
109
 
83
110
  /* A row begins with its name, and the line above a row is drawn by that name: over the whole
84
- width of the list, at the upper edge of the name. It is a box with a height and a fill, not
85
- a border: a reset of the page that takes the border off every element reaches the name and
86
- what it generates, and wins there. Without a theme the line has no height. */
111
+ width of the list, in the middle of the room between two rows, which is where the row of
112
+ this name begins. It is a box with a height and a fill, not a border, and it is moved there
113
+ with translate, not with a margin: a reset of the page that takes the border and the margin
114
+ off every element reaches the name and what it generates, and wins there. Without a theme
115
+ the line has no height. */
87
116
  ::slotted(dt)::before {
88
117
  content: '';
89
118
  position: absolute;
90
119
  inset-inline: 0;
91
120
  height: var(--el-border-width, 0);
92
- margin-block-start: calc(-1 * var(--_el-description-list-padding));
121
+ translate: 0 calc(-1 * var(--_el-description-list-padding));
93
122
  background: var(--el-color-border, transparent);
94
123
  }
95
124
 
@@ -107,32 +136,32 @@ const style = css`
107
136
 
108
137
  /* ── Side by side ─────────────────────────────────────────────────────── */
109
138
 
110
- /* From 30rem of the list itself: a column for the names, one for the values and one for the
111
- actions. The values of all rows begin on one line. */
139
+ /* From 30rem of the list itself: a column for the names, the gap, a column for the values and
140
+ one for the actions. The values of all rows begin on one line. A name and its value are one
141
+ row of the grid here, so the gap between two rows is the room below one and above the next,
142
+ and a value stays where it is. */
112
143
  @container (min-width: 30rem) {
113
144
  .list {
114
145
  grid-template-columns:
115
- var(--el-description-list-term-width, fit-content(40%))
146
+ var(--el-description-list-term-width, fit-content(calc(40% - var(--_el-description-list-gap))))
147
+ var(--_el-description-list-gap)
116
148
  minmax(0, 1fr)
117
149
  auto;
150
+ row-gap: calc(2 * var(--_el-description-list-padding));
151
+ padding-block: var(--_el-description-list-padding);
118
152
  }
119
153
 
120
154
  ::slotted(dt) {
121
155
  grid-column: 1;
122
- padding-block: var(--_el-description-list-padding);
123
- padding-inline-end: var(--_el-description-list-gap);
124
156
  }
125
157
 
126
158
  ::slotted(dd) {
127
- grid-column: 2;
128
- padding-block: var(--_el-description-list-padding);
159
+ grid-column: 3;
160
+ inset-block-start: 0;
129
161
  }
130
162
 
131
- /* The line of the value begins after the padding of the row. */
132
163
  ::slotted(dd[data-action]) {
133
- grid-column: 3;
134
- height: calc(1lh + 2 * var(--_el-description-list-padding));
135
- padding-block: 0;
164
+ grid-column: 4;
136
165
  }
137
166
  }
138
167
  `;
@@ -12,6 +12,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
12
12
 
13
13
  ## Unreleased
14
14
 
15
+ ## [0.5.0] - 2026-11-27
16
+
17
+ ### Added
18
+
19
+ - A container can give its lines room: it names the room in a property that inherits (`--_el-context-divider-space`, internal), and the line has it in front of it and after it, above and below a horizontal line and at both sides of a vertical one. `el-menu` does so for a line between two entries. Outside of such a container a divider has no space around it, as before. ([#206](https://github.com/webtides/element-library/issues/206))
20
+
15
21
  ## [0.3.0] - 2026-11-17
16
22
 
17
23
  ### Added
@@ -66,7 +66,7 @@ _None._
66
66
 
67
67
  ## Space around the line
68
68
 
69
- A divider has no space around it. Where it stands in a layout with a `gap`, the gap is the distance to the content on both sides. Anywhere else, set a margin on the element:
69
+ A divider has no space around it. Where it stands in a layout with a `gap`, the gap is the distance to the content on both sides. In an [`el-menu`](../menu/menu.readme.md) the menu gives it room above and below. Anywhere else, set a margin on the element:
70
70
 
71
71
  ```css
72
72
  el-divider {
@@ -22,6 +22,10 @@ const style = css`
22
22
  width: auto;
23
23
  height: 0;
24
24
  margin: 0;
25
+ /* A container that gives its lines room, a menu, says how much in a property that
26
+ inherits: the room in front of the line and after it. It is a margin of the line in
27
+ here. Outside of such a container the property is not set, and the line has no room. */
28
+ margin-block: var(--_el-context-divider-space, 0px);
25
29
  border: none;
26
30
  border-block-start: var(--_el-divider-line);
27
31
  color: inherit;
@@ -42,6 +46,8 @@ const style = css`
42
46
  /* The line stretches to the height of the host, as a flex item does. */
43
47
  :host([orientation='vertical']) .divider {
44
48
  height: auto;
49
+ margin-block: 0;
50
+ margin-inline: var(--_el-context-divider-space, 0px);
45
51
  border-block-start: none;
46
52
  border-inline-start: var(--_el-divider-line);
47
53
  }
@@ -12,6 +12,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
12
12
 
13
13
  ## Unreleased
14
14
 
15
+ ## [0.5.0] - 2026-11-27
16
+
17
+ ### Added
18
+
19
+ - `drop-message`: an area to drop a file onto, around the control, with that text in it. The control took a drop on its small button, and nothing invited one. While a dragged file is over the area it looks different, and the host has the state `dragover`. A click on the area opens the dialog; the keyboard is on the control in it. ([#197](https://github.com/webtides/element-library/issues/197))
20
+ - A drop is a choice as one in the dialog: the control has the files, `input` and `change` are fired on it, and `input-change` reports them. A drop that `accept` or `multiple` refuses is not taken, the control keeps what it had, and the field says that the choice was not valid, with its `error-message`. ([#197](https://github.com/webtides/element-library/issues/197))
21
+ - Without JavaScript the area is a box with its text around the control of the browser, which posts the file with its form as before. ([#197](https://github.com/webtides/element-library/issues/197))
22
+
15
23
  ## [0.3.0] - 2026-11-17
16
24
 
17
25
  ### Added
@@ -10,15 +10,21 @@ import style from './file-field.style.js';
10
10
  * The files come from the user. A script cannot choose one, the browser does not allow that; it can
11
11
  * take the choice away with an empty `value`.
12
12
  *
13
+ * With `drop-message` the field shows an area around its control to drop a file onto, with that
14
+ * text in it. The area looks different while a dragged file is over it, a click on it opens the
15
+ * dialog, and a drop is a choice as one in the dialog is: the control has the files, and the same
16
+ * events are fired.
17
+ *
13
18
  * @element el-file-field
14
19
  *
15
- * @fires {CustomEvent<string[]>} input-change - Fired when the user has chosen files, and when the
16
- * choice was taken away. `detail` is the list of the names; the files are in `files` of the
17
- * element. Bubbles.
20
+ * @fires {CustomEvent<string[]>} input-change - Fired when the user has chosen files, in the
21
+ * dialog or with a drop, and when the choice was taken away. `detail` is the list of the names;
22
+ * the files are in `files` of the element. Bubbles.
18
23
  *
19
24
  * @cssstate touched - Set on the host once the user has left the control for another place of the
20
25
  * page, or the browser has refused a submit because of it. Inherits `valid` and `invalid` from
21
26
  * `FormField`.
27
+ * @cssstate dragover - Set on the host while a dragged file is over the area to drop onto.
22
28
  *
23
29
  * @property {string[]} value - The names of the chosen files. It follows the control: a script can
24
30
  * set it to an empty list, which takes the choice away, and to nothing else.
@@ -31,8 +37,17 @@ import style from './file-field.style.js';
31
37
  * @property {'small'|'medium'|'large'} size - Size of the control: its height, its padding and its
32
38
  * font size. Default `'medium'`. Reflected to the `size` attribute. It shows once the control is
33
39
  * decorated (`styles/native.css`); a control with the look of the browser keeps its size.
40
+ * @property {string} dropMessage - The text of an area to drop a file onto: "Drop the list here,
41
+ * or choose it". With one the field shows the area, around its control. Default `''`.
34
42
  */
35
43
  export default class FileField extends FormField {
44
+ /**
45
+ * How many elements of the area a dragged file is over: the browser tells of every one it
46
+ * enters and leaves, the text and the control in the area as well.
47
+ * @private
48
+ */
49
+ _dragDepth = 0;
50
+
36
51
  /**
37
52
  * The names the control had when the field last looked. See `_matchControl()`.
38
53
  * @private
@@ -64,6 +79,7 @@ export default class FileField extends FormField {
64
79
  multiple: false,
65
80
  capture: null,
66
81
  size: 'medium',
82
+ dropMessage: '',
67
83
  };
68
84
  }
69
85
 
@@ -108,9 +124,88 @@ export default class FileField extends FormField {
108
124
  blur: () => document.hasFocus() && this.onBlur(),
109
125
  invalid: (event) => this._onInvalid(event.target),
110
126
  },
127
+ '.drop-area': {
128
+ click: (event) => this._onAreaClick(event),
129
+ dragenter: (event) => this._onDrag(event, 1),
130
+ dragover: (event) => this._onDrag(event, 0),
131
+ dragleave: (event) => this._onDrag(event, -1),
132
+ drop: (event) => this._onDrop(event),
133
+ },
111
134
  };
112
135
  }
113
136
 
137
+ /**
138
+ * A click on the area beside its control opens the dialog, as a click on the control does.
139
+ * @private
140
+ * @param {MouseEvent} event
141
+ */
142
+ _onAreaClick(event) {
143
+ const control = this.$refs.input;
144
+ if (event.target === control || control.disabled) return;
145
+ control.click();
146
+ }
147
+
148
+ /**
149
+ * A file is dragged into the area, over it or out of it. The area says that it takes the file
150
+ * (the browser shows a drop that is allowed with the pointer), and the host has the state
151
+ * `dragover` for as long. Text or a link that is dragged is nothing for this field.
152
+ * @private
153
+ * @param {DragEvent} event
154
+ * @param {-1 | 0 | 1} step - Into an element of the area, over one, or out of one.
155
+ */
156
+ _onDrag(event, step) {
157
+ if (this.$refs.input.disabled || !event.dataTransfer?.types?.includes('Files')) return;
158
+ event.preventDefault();
159
+ event.dataTransfer.dropEffect = 'copy';
160
+
161
+ this._dragDepth = Math.max(0, this._dragDepth + step);
162
+ if (this._dragDepth > 0 || step === 0) this._internals.states.add('dragover');
163
+ else this._internals.states.delete('dragover');
164
+ }
165
+
166
+ /**
167
+ * Files were dropped onto the area. They are a choice as one in the dialog is: the control
168
+ * gets them and tells of it with `input` and `change`, which the field follows as it does for
169
+ * the dialog.
170
+ *
171
+ * The dialog does not offer what `accept` leaves out, and one file alone without `multiple`.
172
+ * A drop can bring anything, so the field asks itself. A drop it cannot take as a whole is
173
+ * not taken at all: the control keeps what it had, and the field says that the choice was
174
+ * not valid, with its error message.
175
+ * @private
176
+ * @param {DragEvent} event
177
+ */
178
+ _onDrop(event) {
179
+ const control = this.$refs.input;
180
+ if (control.disabled || !event.dataTransfer?.types?.includes('Files')) return;
181
+ // The browser would open the file in place of the page.
182
+ event.preventDefault();
183
+ this._dragDepth = 0;
184
+ this._internals.states.delete('dragover');
185
+
186
+ const files = [...event.dataTransfer.files];
187
+ if (files.length === 0) return;
188
+ if ((files.length > 1 && !this.multiple) || !files.every((file) => accepts(this.accept, file))) {
189
+ this.touched = true;
190
+ this.valid = false;
191
+ return;
192
+ }
193
+
194
+ control.files = event.dataTransfer.files;
195
+ control.dispatchEvent(new Event('input', { bubbles: true }));
196
+ control.dispatchEvent(new Event('change', { bubbles: true }));
197
+ }
198
+
199
+ /**
200
+ * The description of the control: the text of the area first, then the messages of the field.
201
+ * @private
202
+ * @returns {string}
203
+ */
204
+ _describedBy() {
205
+ const ids = super._describedBy();
206
+ return this.dropMessage ? `${this._idOf('drop-message')} ${ids}` : ids;
207
+ }
208
+
114
209
  /**
115
210
  * The user has chosen files, or has taken the choice away in the dialog.
116
211
  * @returns {void}
@@ -180,8 +275,7 @@ export default class FileField extends FormField {
180
275
  /** @private */
181
276
  fieldTemplate() {
182
277
  const capture = this.capture ?? false;
183
-
184
- return html`
278
+ const control = html`
185
279
  <input
186
280
  ref="input"
187
281
  type="file"
@@ -197,9 +291,45 @@ export default class FileField extends FormField {
197
291
  aria-errormessage="${this._idOf('error-message')}"
198
292
  />
199
293
  `;
294
+
295
+ // A field without an area is its control, as it was.
296
+ if (!this.dropMessage) return control;
297
+
298
+ // The control is in the area and stays the control of the browser: it shows the name of
299
+ // the file, takes the keyboard, and posts the file where no script runs.
300
+ return html`
301
+ <div class="drop-area">
302
+ <span id="${this._idOf('drop-message')}" class="drop-message">${this.dropMessage}</span>
303
+ ${control}
304
+ </div>
305
+ `;
200
306
  }
201
307
  }
202
308
 
309
+ /**
310
+ * Whether a file is one of the kinds an `accept` attribute names: an ending (`.pdf`), a type
311
+ * (`application/pdf`) or a group of types (`image/*`), with commas between them. Without one
312
+ * every file is.
313
+ * @param {string} accept
314
+ * @param {File} file
315
+ * @returns {boolean}
316
+ */
317
+ export function accepts(accept, file) {
318
+ const kinds = String(accept ?? '')
319
+ .split(',')
320
+ .map((kind) => kind.trim().toLowerCase())
321
+ .filter(Boolean);
322
+ if (kinds.length === 0) return true;
323
+
324
+ const name = file.name.toLowerCase();
325
+ const type = file.type.toLowerCase();
326
+ return kinds.some((kind) => {
327
+ if (kind.startsWith('.')) return name.endsWith(kind);
328
+ if (kind.endsWith('/*')) return type.startsWith(kind.slice(0, -1));
329
+ return type === kind;
330
+ });
331
+ }
332
+
203
333
  export function define() {
204
334
  defineElement('el-file-field', FileField);
205
335
  }
@@ -1,6 +1,6 @@
1
1
  # FileField
2
2
 
3
- `file-field` takes one or several files for a form: a CV, a receipt, a picture. It renders a native `<input type="file">`, so the dialog of the system, a drop onto the control, the keyboard and the form submission are the ones of the browser. It extends `form-field`, inheriting the label, help text, error message, `required` and touched-state handling.
3
+ `file-field` takes one or several files for a form: a CV, a receipt, a picture. It renders a native `<input type="file">`, so the dialog of the system, the keyboard and the form submission are the ones of the browser. With `drop-message` it shows an area to drop a file onto. It extends `form-field`, inheriting the label, help text, error message, `required` and touched-state handling.
4
4
 
5
5
  It is headless by default: the control keeps the look of the browser. `styles/native.css` gives it the border of the other fields and its button the tokens of the theme.
6
6
 
@@ -43,6 +43,31 @@ The files come from the user. A script cannot choose one, the browser does not a
43
43
  field.value = [];
44
44
  ```
45
45
 
46
+ #### An area to drop a file onto
47
+
48
+ The control of the browser takes a drop, on its small button, and nothing invites one. With `drop-message` the field shows an area around the control, with that text in it:
49
+
50
+ ```html
51
+ <el-file-field
52
+ name="list"
53
+ label="Your list"
54
+ accept=".opml,.csv"
55
+ drop-message="Drop the list here, or choose it"
56
+ error-message="An OPML or a CSV file"
57
+ ></el-file-field>
58
+ ```
59
+
60
+ - **While a file is dragged over the area** it looks different: a line that is drawn through in the accent colour, and a tint of it. The host has the state `dragover` for a look of the page (`el-file-field:state(dragover)`).
61
+ - **A drop is a choice**, as one in the dialog: the control has the files, `input` and `change` are fired on it, and the field reports them with `input-change`. A page that reads the file on a change needs no second path.
62
+ - **A click on the area** opens the dialog. The keyboard is on the control in the area, which the Tab key stops at: `Enter` and `Space` open the dialog, and the ring of the focus is around the area.
63
+ - **What the field does not take.** The dialog offers only what `accept` names, and one file without `multiple`. A drop can bring anything, so the field asks itself: a file whose ending or type `accept` does not name, or more than one file for a field that takes one. Such a drop is not taken at all, also where some of its files would do. The control keeps what it had, and the field says that the choice was not valid: `valid` is `false` and the `error-message` shows, until the next choice.
64
+ - **Only files.** A text or a link that is dragged over the area is nothing for the field.
65
+ - **The text describes the control** for assistive technology (`aria-describedby`), in front of the help message.
66
+ - **Without JavaScript** the area is a box with its text around the control of the browser, which posts the file with its form as before. The script adds the drop and the click.
67
+ - **A field that is disabled** takes no drop and opens no dialog, and the area fades.
68
+
69
+ Not in the field: the progress of an upload, and previews of the chosen files.
70
+
46
71
  #### Checks of the page
47
72
 
48
73
  The browser knows `required` and nothing else about a file: `accept` only says what the dialog offers. The size, the number and the kind of the files are checked by the page. It renders the field as not valid, with the reason as the error message:
@@ -70,20 +95,22 @@ Inherits all of `form-field`'s properties (`name`, `value`, `required`, `disable
70
95
  | `multiple` | `boolean` | `false` | Whether more than one file can be chosen. |
71
96
  | `capture` | `string \| null` | `null` | A phone takes the picture or the recording with its camera (`user`, `environment`) and does not open its files. |
72
97
  | `size` | `'small' \| 'medium' \| 'large'` | `'medium'` | Size of the control. Reflected to the `size` attribute. It shows once the control is decorated. |
98
+ | `dropMessage` | `string` | `''` | The text of an area to drop a file onto. With one the field shows the area, around its control. |
73
99
 
74
100
  #### Events
75
101
 
76
102
  | Name | Detail | Description |
77
103
  | --- | --- | --- |
78
- | `input-change` | `string[]` (the value) | Fired when the user has chosen files, also ones with the names of the files before, and when the choice was taken away. |
104
+ | `input-change` | `string[]` (the value) | Fired when the user has chosen files, in the dialog or with a drop, also ones with the names of the files before, and when the choice was taken away. |
79
105
 
80
106
  #### CSS States
81
107
 
82
- | Name | Description |
83
- | --------- | ------------------------------------------------------------------------------------------------- |
108
+ | Name | Description |
109
+ | --- | --- |
84
110
  | `touched` | Set once the user has left the control for another place of the page. The dialog does not set it. |
85
- | `valid` | Set while the field passes validation. |
86
- | `invalid` | Set while the field fails validation (`required` with no file, or the page says so with `valid`). |
111
+ | `valid` | Set while the field passes validation. |
112
+ | `invalid` | Set while the field fails validation (`required` with no file, a drop the field did not take, or the page says so with `valid`). |
113
+ | `dragover` | Set while a dragged file is over the area to drop onto. |
87
114
 
88
115
  #### CSS Custom Properties
89
116
 
@@ -93,6 +120,8 @@ With `styles/native.css` the control has the border, the radius, the colours and
93
120
 
94
121
  The label, the help message, the control and the error message stack in a column, and the texts have one look in every field: see [Layout](../form-field/form-field.readme.md#layout) in the readme of `form-field`.
95
122
 
123
+ The area to drop onto is no control of the browser, so it has its look without `styles/native.css`: a dashed line from `--el-color-border` and `--el-border-width` (the colour of the text without a theme), `--el-radius-md`, `--el-space-4` of padding, its text in `--el-color-fg-muted`, and `--el-color-accent` while a file is over it. In the area the control has no border of its own.
124
+
96
125
  On a touch screen (`@media (any-pointer: coarse)`) the control is at least `--el-touch-target` high. Without that token, and on a fine pointer, the size stays as it is.
97
126
 
98
127
  ## Accessibility
@@ -7,9 +7,80 @@ const css = String.raw;
7
7
  /**
8
8
  * The control keeps the look of the browser, as the control of every field does: `styles/native.css`
9
9
  * gives it the border of the other fields and its button the tokens of the theme.
10
+ *
11
+ * The area to drop a file onto is no control of the browser, so its look is here: a dashed line
12
+ * around its text and the control, with the colours of the text where there is no theme. In the
13
+ * area the control has no border of its own, with and without `styles/native.css`: the area is
14
+ * the box. The rules for the control in the area name the area, so they win over the rules for
15
+ * the control of that file whichever comes first.
10
16
  */
11
17
  const style = css`
12
18
  el-file-field {
19
+ .drop-area {
20
+ display: flex;
21
+ flex: 1 1 auto;
22
+ flex-direction: column;
23
+ align-items: center;
24
+ gap: var(--el-space-2, 8px);
25
+ box-sizing: border-box;
26
+ min-inline-size: 0;
27
+ padding: var(--el-space-4, 16px);
28
+ border: var(--el-border-width, 1px) dashed var(--el-color-border, currentColor);
29
+ border-radius: var(--el-radius-md, 0);
30
+ background: var(--el-color-bg, transparent);
31
+ color: var(--el-color-fg-muted, inherit);
32
+ text-align: center;
33
+ cursor: pointer;
34
+ transition:
35
+ border-color var(--el-duration-md, 0s) var(--el-ease, linear),
36
+ background-color var(--el-duration-md, 0s) var(--el-ease, linear);
37
+ }
38
+
39
+ .drop-area input {
40
+ inline-size: auto;
41
+ max-inline-size: 100%;
42
+ min-block-size: 0;
43
+ border: 0;
44
+ padding: 0;
45
+ background: transparent;
46
+ box-shadow: none;
47
+ }
48
+
49
+ /* The ring of the keyboard is around the area, for the control that is in it. */
50
+ .drop-area input:focus {
51
+ outline: none;
52
+ box-shadow: none;
53
+ }
54
+
55
+ .drop-area:has(input:focus-visible) {
56
+ outline: var(--el-focus-ring-width, 2px) solid var(--el-color-focus-ring, currentColor);
57
+ outline-offset: var(--el-focus-ring-offset, 2px);
58
+ }
59
+
60
+ /* A file is over the area: a line that is drawn through, in the accent colour, and a tint
61
+ of it. The line is what shows where the user forces colours. */
62
+ &:state(dragover) .drop-area {
63
+ border-style: solid;
64
+ border-color: var(--el-color-accent, currentColor);
65
+ background: color-mix(in srgb, var(--el-color-accent, currentColor) 8%, var(--el-color-bg, transparent));
66
+ color: var(--el-color-fg, inherit);
67
+ }
68
+
69
+ &:state(invalid) .drop-area {
70
+ border-color: var(--el-color-danger, currentColor);
71
+ }
72
+
73
+ /* A field that is disabled takes no file: the area fades as a control does, and its
74
+ control not a second time. */
75
+ .drop-area:has(input:disabled) {
76
+ opacity: 0.55;
77
+ cursor: not-allowed;
78
+ }
79
+
80
+ .drop-area input:disabled {
81
+ opacity: 1;
82
+ }
83
+
13
84
  /* Touch screens: the control is at least --el-touch-target high, whatever the size of the
14
85
  field. Without the token the size stays as it is. */
15
86
  @media (any-pointer: coarse) {
@@ -320,7 +320,7 @@ export default class FormField extends TemplateElement {
320
320
  * The id is another one on every page load. Server-rendered markup has the ids of the server
321
321
  * until the element starts, which writes its own to the same elements.
322
322
  * @private
323
- * @param {'input' | 'help-message' | 'error-message' | 'list'} part
323
+ * @param {'input' | 'help-message' | 'error-message' | 'list' | 'control-start' | 'control-end' | 'drop-message'} part
324
324
  * @returns {string}
325
325
  */
326
326
  _idOf(part) {
@@ -12,6 +12,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
12
12
 
13
13
  ## Unreleased
14
14
 
15
+ ## [0.5.0] - 2026-11-27
16
+
17
+ ### Added
18
+
19
+ - Content of the page at the start and at the end of the control: an element with `slot="start"` or `slot="end"` among the children of the field is taken into the control when the field renders. An icon, a unit, the start of an address, a button. It stands in a row with the input, whose text does not run under it, and follows the reading direction. The field moves the element of the page and does not copy it, and server-rendered markup has it in its place. ([#168](https://github.com/webtides/element-library/issues/168))
20
+ - A click on a text or on an icon in the control puts the focus into the input; a button or a link there keeps its click and its stop of the Tab key. A text there is part of the description of the input (`aria-describedby`), so a unit is read with it; an icon and a button are not. ([#168](https://github.com/webtides/element-library/issues/168))
21
+ - `clearable`: a button at the end of the control that empties the field. It shows while the field has a value and is not disabled, `input-change` reports the empty value, and the focus stays in the input. `clear-label` is its name (`Clear`). ([#168](https://github.com/webtides/element-library/issues/168))
22
+ - With `styles/native.css` the control with its content is the control to the eye: the border, the surface and the focus ring are around all of it, as the border of a field that is not valid and the look of a disabled one, and it is as high as an input of its size alone. Without that file the content stands beside an input with the look of the browser. A field without content and without `clearable` renders its input alone, as before. ([#168](https://github.com/webtides/element-library/issues/168))
23
+ - `maxlength` and `minlength` are passed on to the native `<input>`, in server-rendered markup as well, and one that is not set is not rendered. The control takes no more characters than `maxlength` while the user types, and a typed text that is shorter than `minlength` makes the field invalid the way `required` and `pattern` do, with its `error-message`. Set on the element they did nothing before. The fields that extend this one take both as well. ([#190](https://github.com/webtides/element-library/issues/190))
24
+
15
25
  ## [0.3.0] - 2026-11-17
16
26
 
17
27
  ### Added