@webtides/element-library 0.3.0 → 0.3.1
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.
- package/CHANGELOG.md +15 -0
- package/custom-elements.json +37 -2
- package/package.json +1 -1
- package/src/components/button/button.changelog.md +10 -0
- package/src/components/button/button.js +64 -11
- package/src/components/button/button.readme.md +10 -2
- package/src/components/checkbox-field/checkbox-field.changelog.md +6 -0
- package/src/components/checkbox-field/checkbox-field.js +7 -1
- package/src/components/switch-field/switch-field.changelog.md +6 -0
- package/src/components/switch-field/switch-field.js +7 -1
- package/types/src/components/button/button.d.ts +36 -7
- package/web-types.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/) and this
|
|
|
12
12
|
|
|
13
13
|
## Unreleased
|
|
14
14
|
|
|
15
|
+
## [0.3.1] - 2026-11-17
|
|
16
|
+
|
|
17
|
+
### button
|
|
18
|
+
|
|
19
|
+
- Changed: an `el-button` of the type `submit` makes its hidden native `<button type="submit">` when the form is first submitted with it: with a click, or with Enter in an `<input>` or a `<select>` of the form. Before, it appended that button as soon as it started. Until the first submit the children of the `el-button` are what the page wrote, and `form.querySelector('[type="submit"]')` does not find a native button in it. When the page replaces the content of the button, the native button is made again with the next submit, and no longer with the next render. A native submit button that the page writes is taken as before. ([#184](https://github.com/webtides/element-library/issues/184))
|
|
20
|
+
- Fixed: a server-rendered `el-button` of the type `submit` no longer breaks the hydration of its page. The element appended its native submit button as soon as it started, and a framework that hydrated after that found a child it had not rendered (Svelte 5: `hydration_mismatch`, the page was built again, and what the user had typed into the form by then was gone). See "On a page that a framework hydrates" in the readme of the button. ([#184](https://github.com/webtides/element-library/issues/184))
|
|
21
|
+
|
|
22
|
+
### checkbox-field
|
|
23
|
+
|
|
24
|
+
- Fixed: `checked` set from outside moves the checkbox, also after the user has pressed it. The field wrote the `checked` attribute of its native input alone, which is the default of the control: after a press the control no longer follows it. `field.checked = false`, or the `checked` attribute, took the check mark away, while the native checkbox stayed checked and the form went on submitting the value. The field now writes the property of the input as well, before it dispatches `input-change`. ([#185](https://github.com/webtides/element-library/issues/185))
|
|
25
|
+
|
|
26
|
+
### switch-field
|
|
27
|
+
|
|
28
|
+
- Fixed: `checked` set from outside moves the switch, also after the user has pressed it. The field wrote the `checked` attribute of its native input alone, which is the default of the control: after a press the control no longer follows it. `field.checked = false`, or the `checked` attribute, turned the host and its `:state(checked)` off, while the track stayed on and the form went on submitting the value. The field now writes the property of the input as well, before it dispatches `input-change`. ([#185](https://github.com/webtides/element-library/issues/185))
|
|
29
|
+
|
|
15
30
|
## [0.3.0] - 2026-11-17
|
|
16
31
|
|
|
17
32
|
### Packaging
|
package/custom-elements.json
CHANGED
|
@@ -1553,7 +1553,7 @@
|
|
|
1553
1553
|
"declarations": [
|
|
1554
1554
|
{
|
|
1555
1555
|
"kind": "class",
|
|
1556
|
-
"description": "A themeable button that renders a native `<button>` — or an `<a>` when `href` is set — and\ndecorates it with the `--el-*` design tokens. Speaks the library's shared vocabulary: a semantic\n`variant`, an `appearance` and a `size`. Also supports pill / circle shapes, an optional\ndropdown caret and a loading spinner.\n\nARIA attributes on the element reach the control inside it, which is what has the focus and what\na screen reader announces: `aria-label`, `aria-description`, `aria-expanded`, `aria-haspopup`,\n`aria-pressed` and `aria-current` as they are, `aria-labelledby`, `aria-describedby` and\n`aria-controls` as references to the elements they name.\n\nThe element is form-associated: a `<fieldset disabled>` around it disables it, and it is listed in\nthe `elements` of its form. A button of the type `submit`
|
|
1556
|
+
"description": "A themeable button that renders a native `<button>` — or an `<a>` when `href` is set — and\ndecorates it with the `--el-*` design tokens. Speaks the library's shared vocabulary: a semantic\n`variant`, an `appearance` and a `size`. Also supports pill / circle shapes, an optional\ndropdown caret and a loading spinner.\n\nARIA attributes on the element reach the control inside it, which is what has the focus and what\na screen reader announces: `aria-label`, `aria-description`, `aria-expanded`, `aria-haspopup`,\n`aria-pressed` and `aria-current` as they are, `aria-labelledby`, `aria-describedby` and\n`aria-controls` as references to the elements they name.\n\nThe element is form-associated: a `<fieldset disabled>` around it disables it, and it is listed in\nthe `elements` of its form. A button of the type `submit` submits its form with a hidden native\n`<button type=\"submit\">` in its content: it is the `submitter` of the `submit` event, its `name`\nand `value` are in the data of the form, and Enter in a field of the form finds it. The element\nmakes that button when the form is first submitted with it, by a click or by Enter in a field.\nUntil then its content is what the page wrote, so a framework can hydrate a server-rendered\nbutton, also when the element has started before the framework does. The attributes `form`,\n`formaction`, `formenctype`, `formmethod`, `formnovalidate` and `formtarget` of the element do\nwhat they do on a native button. A `click` listener of the page that calls `preventDefault()`\nkeeps the button from submitting or resetting.",
|
|
1557
1557
|
"name": "Button",
|
|
1558
1558
|
"cssParts": [
|
|
1559
1559
|
{
|
|
@@ -1616,6 +1616,16 @@
|
|
|
1616
1616
|
"text": "HTMLButtonElement | undefined"
|
|
1617
1617
|
}
|
|
1618
1618
|
},
|
|
1619
|
+
{
|
|
1620
|
+
"kind": "field",
|
|
1621
|
+
"name": "_keydownRoot",
|
|
1622
|
+
"default": "undefined",
|
|
1623
|
+
"description": "Where the element listens for Enter in a field of its form, see `afterUpdate()`.",
|
|
1624
|
+
"privacy": "private",
|
|
1625
|
+
"type": {
|
|
1626
|
+
"text": "Node | undefined"
|
|
1627
|
+
}
|
|
1628
|
+
},
|
|
1619
1629
|
{
|
|
1620
1630
|
"kind": "field",
|
|
1621
1631
|
"name": "isLink",
|
|
@@ -1640,6 +1650,20 @@
|
|
|
1640
1650
|
],
|
|
1641
1651
|
"description": "`disabled` is reflected as the platform reads it: the attribute is there while the button is\ndisabled, and gone while it is not. element-js would write `disabled=\"false\"`."
|
|
1642
1652
|
},
|
|
1653
|
+
{
|
|
1654
|
+
"kind": "field",
|
|
1655
|
+
"name": "_onRootKeydown",
|
|
1656
|
+
"description": "Enter in a field of the form submits the form with its first submit button, and without one\nonly a form with a single field. The browser looks for that button once every listener has\nhad the key, so the native submit button of the element is made here, if it is not there yet.\n\nOnly for a key the browser may submit with: Enter in an `<input>` or a `<select>` of the\nform, and not while a text is being composed. Enter in a `<textarea>` is a line break, and\nleaves the content of the element as it is.",
|
|
1657
|
+
"privacy": "private",
|
|
1658
|
+
"parameters": [
|
|
1659
|
+
{
|
|
1660
|
+
"name": "event",
|
|
1661
|
+
"type": {
|
|
1662
|
+
"text": "KeyboardEvent"
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
]
|
|
1666
|
+
},
|
|
1643
1667
|
{
|
|
1644
1668
|
"kind": "method",
|
|
1645
1669
|
"name": "focus",
|
|
@@ -1694,7 +1718,18 @@
|
|
|
1694
1718
|
{
|
|
1695
1719
|
"kind": "method",
|
|
1696
1720
|
"name": "_syncSubmitter",
|
|
1697
|
-
"
|
|
1721
|
+
"parameters": [
|
|
1722
|
+
{
|
|
1723
|
+
"name": "create",
|
|
1724
|
+
"default": "false",
|
|
1725
|
+
"description": "Whether to make the button when there is none.",
|
|
1726
|
+
"optional": true,
|
|
1727
|
+
"type": {
|
|
1728
|
+
"text": "boolean"
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
],
|
|
1732
|
+
"description": "Keeps the native submit button of a button of the type `submit`: a hidden\n`<button type=\"submit\">` in the content of the element, in the page, where it belongs to the\nform. A form is submitted with a submit button that belongs to it, and with nothing else: the\nbutton is the `submitter` of the `submit` event, its `name` and `value` are in the data, it\nsays how to submit (`formmethod`, `formnovalidate`, …), and Enter in a field looks for it.\nThe control in the shadow root has no form, and the element itself is no submit button for the\nplatform.\n\nThe button takes over `name`, `value` and the attributes of the element that a native submit\nbutton has. It is disabled while the element is disabled or loading, which keeps Enter from\nsubmitting as well. One that is in the content already is taken: written by the page, for a\nform that is submitted with Enter before the script has run, or copied with the element.\n\nThe element makes the button only when the form is about to be submitted with it (`create`):\nwith a click, or with Enter in a field. A render does not. The content of the element is what\nthe page wrote until then: a framework that hydrates a server-rendered page after the element\nhas started finds the children it rendered, and no other.",
|
|
1698
1733
|
"privacy": "private",
|
|
1699
1734
|
"return": {
|
|
1700
1735
|
"type": {
|
package/package.json
CHANGED
|
@@ -12,6 +12,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|
|
12
12
|
|
|
13
13
|
## Unreleased
|
|
14
14
|
|
|
15
|
+
## [0.3.1] - 2026-11-17
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- A button of the type `submit` makes its hidden native `<button type="submit">` when the form is first submitted with it: with a click, or with Enter in an `<input>` or a `<select>` of the form. Before, it appended that button as soon as it started. Until the first submit the children of the `el-button` are what the page wrote, and `form.querySelector('[type="submit"]')` does not find a native button in it. When the page replaces the content of the button, the native button is made again with the next submit, and no longer with the next render. A native submit button that the page writes is taken as before. ([#184](https://github.com/webtides/element-library/issues/184))
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- A server-rendered `el-button` of the type `submit` no longer breaks the hydration of its page. The element appended its native submit button as soon as it started, and a framework that hydrated after that found a child it had not rendered (Svelte 5: `hydration_mismatch`, the page was built again, and what the user had typed into the form by then was gone). See "On a page that a framework hydrates" in the readme. ([#184](https://github.com/webtides/element-library/issues/184))
|
|
24
|
+
|
|
15
25
|
## [0.3.0] - 2026-11-17
|
|
16
26
|
|
|
17
27
|
### Added
|
|
@@ -44,12 +44,15 @@ const SUBMITTER_ATTRIBUTES = ['form', 'formaction', 'formenctype', 'formmethod',
|
|
|
44
44
|
* `aria-controls` as references to the elements they name.
|
|
45
45
|
*
|
|
46
46
|
* The element is form-associated: a `<fieldset disabled>` around it disables it, and it is listed in
|
|
47
|
-
* the `elements` of its form. A button of the type `submit`
|
|
48
|
-
* `<button type="submit">` in its content
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
47
|
+
* the `elements` of its form. A button of the type `submit` submits its form with a hidden native
|
|
48
|
+
* `<button type="submit">` in its content: it is the `submitter` of the `submit` event, its `name`
|
|
49
|
+
* and `value` are in the data of the form, and Enter in a field of the form finds it. The element
|
|
50
|
+
* makes that button when the form is first submitted with it, by a click or by Enter in a field.
|
|
51
|
+
* Until then its content is what the page wrote, so a framework can hydrate a server-rendered
|
|
52
|
+
* button, also when the element has started before the framework does. The attributes `form`,
|
|
53
|
+
* `formaction`, `formenctype`, `formmethod`, `formnovalidate` and `formtarget` of the element do
|
|
54
|
+
* what they do on a native button. A `click` listener of the page that calls `preventDefault()`
|
|
55
|
+
* keeps the button from submitting or resetting.
|
|
53
56
|
*
|
|
54
57
|
* @element el-button
|
|
55
58
|
*
|
|
@@ -106,12 +109,19 @@ export default class Button extends TemplateElement {
|
|
|
106
109
|
*/
|
|
107
110
|
_submitter = undefined;
|
|
108
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Where the element listens for Enter in a field of its form, see `afterUpdate()`.
|
|
114
|
+
* @private
|
|
115
|
+
* @type {Node | undefined}
|
|
116
|
+
*/
|
|
117
|
+
_keydownRoot = undefined;
|
|
118
|
+
|
|
109
119
|
constructor() {
|
|
110
120
|
super({
|
|
111
121
|
styles: [style],
|
|
112
122
|
shadowRender: true,
|
|
113
|
-
//
|
|
114
|
-
//
|
|
123
|
+
// A native submit button that the page writes into the content of the element is
|
|
124
|
+
// taken with the next render, see `_syncSubmitter()`.
|
|
115
125
|
mutationObserverOptions: { childList: true },
|
|
116
126
|
// The shared style modules select the host by these attributes.
|
|
117
127
|
propertyOptions: {
|
|
@@ -199,8 +209,39 @@ export default class Button extends TemplateElement {
|
|
|
199
209
|
afterUpdate() {
|
|
200
210
|
this._syncAriaRelations();
|
|
201
211
|
this._syncSubmitter();
|
|
212
|
+
|
|
213
|
+
// `keydown` passes the root of its tree on the way to the field, the document or a shadow
|
|
214
|
+
// root: there the element hears Enter before the browser looks for the submit button.
|
|
215
|
+
if (!this._keydownRoot) {
|
|
216
|
+
this._keydownRoot = this.getRootNode();
|
|
217
|
+
this._keydownRoot.addEventListener('keydown', this._onRootKeydown, true);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
disconnected() {
|
|
222
|
+
this._keydownRoot?.removeEventListener('keydown', this._onRootKeydown, true);
|
|
223
|
+
this._keydownRoot = undefined;
|
|
202
224
|
}
|
|
203
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Enter in a field of the form submits the form with its first submit button, and without one
|
|
228
|
+
* only a form with a single field. The browser looks for that button once every listener has
|
|
229
|
+
* had the key, so the native submit button of the element is made here, if it is not there yet.
|
|
230
|
+
*
|
|
231
|
+
* Only for a key the browser may submit with: Enter in an `<input>` or a `<select>` of the
|
|
232
|
+
* form, and not while a text is being composed. Enter in a `<textarea>` is a line break, and
|
|
233
|
+
* leaves the content of the element as it is.
|
|
234
|
+
* @private
|
|
235
|
+
* @param {KeyboardEvent} event
|
|
236
|
+
*/
|
|
237
|
+
_onRootKeydown = (event) => {
|
|
238
|
+
if (event.key !== 'Enter' || event.isComposing || this.isLink || this.type !== 'submit') return;
|
|
239
|
+
const field = event.target;
|
|
240
|
+
const form = this._internals.form;
|
|
241
|
+
if (!form || field?.form !== form || !field.matches('input, select')) return;
|
|
242
|
+
this._syncSubmitter(true);
|
|
243
|
+
};
|
|
244
|
+
|
|
204
245
|
/** Focuses the underlying control. */
|
|
205
246
|
focus(options) {
|
|
206
247
|
this.$refs.control?.focus(options);
|
|
@@ -234,7 +275,7 @@ export default class Button extends TemplateElement {
|
|
|
234
275
|
// Both are taken here, while the button is not disabled, and act once the page
|
|
235
276
|
// has had the click.
|
|
236
277
|
if (this.type === 'submit') {
|
|
237
|
-
const submitter = this._syncSubmitter();
|
|
278
|
+
const submitter = this._syncSubmitter(true);
|
|
238
279
|
this._afterListeners(event, () => submitter?.form?.requestSubmit(submitter));
|
|
239
280
|
} else if (this.type === 'reset') {
|
|
240
281
|
const form = this._internals.form;
|
|
@@ -294,10 +335,17 @@ export default class Button extends TemplateElement {
|
|
|
294
335
|
* button has. It is disabled while the element is disabled or loading, which keeps Enter from
|
|
295
336
|
* submitting as well. One that is in the content already is taken: written by the page, for a
|
|
296
337
|
* form that is submitted with Enter before the script has run, or copied with the element.
|
|
338
|
+
*
|
|
339
|
+
* The element makes the button only when the form is about to be submitted with it (`create`):
|
|
340
|
+
* with a click, or with Enter in a field. A render does not. The content of the element is what
|
|
341
|
+
* the page wrote until then: a framework that hydrates a server-rendered page after the element
|
|
342
|
+
* has started finds the children it rendered, and no other.
|
|
297
343
|
* @private
|
|
298
|
-
* @
|
|
344
|
+
* @param {boolean} [create] - Whether to make the button when there is none.
|
|
345
|
+
* @returns {HTMLButtonElement | null} The submit button, or `null`: for a button of another
|
|
346
|
+
* type, and while there is none and none was asked for.
|
|
299
347
|
*/
|
|
300
|
-
_syncSubmitter() {
|
|
348
|
+
_syncSubmitter(create = false) {
|
|
301
349
|
const ours = this._submitter?.parentNode === this ? this._submitter : null;
|
|
302
350
|
let submitter = ours ?? this.querySelector(':scope > button[type="submit"][hidden]');
|
|
303
351
|
|
|
@@ -307,6 +355,11 @@ export default class Button extends TemplateElement {
|
|
|
307
355
|
return null;
|
|
308
356
|
}
|
|
309
357
|
|
|
358
|
+
if (!submitter && !create) {
|
|
359
|
+
this._submitter = undefined;
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
|
|
310
363
|
if (!submitter) {
|
|
311
364
|
submitter = document.createElement('button');
|
|
312
365
|
submitter.type = 'submit';
|
|
@@ -147,11 +147,19 @@ An `el-button` of the type `submit` submits its form as a native submit button d
|
|
|
147
147
|
|
|
148
148
|
#### The native submit button
|
|
149
149
|
|
|
150
|
-
A form is submitted with a submit button that belongs to it. The control of `el-button` is in a shadow root and has no form, so a button of the type `submit`
|
|
150
|
+
A form is submitted with a submit button that belongs to it. The control of `el-button` is in a shadow root and has no form, so a button of the type `submit` submits with a hidden native `<button type="submit">` that is a child of the element. That button carries the `name`, the `value` and the attributes above.
|
|
151
151
|
|
|
152
|
+
- The element makes it when the form is first submitted with the button: with a click on the `el-button`, or with Enter in an `<input>` or a `<select>` of the form. Until then the children of the `el-button` are what the page wrote. After that it stays, as the last child.
|
|
152
153
|
- It is the `submitter` of the `submit` event: `event.submitter.closest('el-button')` is the `el-button`.
|
|
153
154
|
- Enter in a field clicks it, so a `click` listener on the `el-button` hears that click, with the native button as its target. A native submit button hears the same click.
|
|
154
|
-
- When the page replaces the content of the `el-button`, the element
|
|
155
|
+
- When the page replaces the content of the `el-button`, the element makes it again with the next submit.
|
|
156
|
+
- `form.querySelector('[type="submit"]')` does not find it before the first submit. `form.elements` lists the `el-button` from the start.
|
|
157
|
+
|
|
158
|
+
#### On a page that a framework hydrates
|
|
159
|
+
|
|
160
|
+
A framework that hydrates a server-rendered page expects the children it rendered, and no other. The element adds its native submit button for a submit only, so a server-rendered `el-button` hydrates also when the element has started before the framework does (Svelte 5: no `hydration_mismatch`). The page has nothing to write for that.
|
|
161
|
+
|
|
162
|
+
One case is left: a submit before the hydration that does not leave the page, such as a click on the button of a form that is not valid. The native button is there afterwards, and the framework finds a child it did not render. A page that writes the native submit button itself, as in [Before the script has run](#before-the-script-has-run), does not have that case: the framework has rendered the button and expects it.
|
|
155
163
|
|
|
156
164
|
#### The `disabled` attribute
|
|
157
165
|
|
|
@@ -12,6 +12,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|
|
12
12
|
|
|
13
13
|
## Unreleased
|
|
14
14
|
|
|
15
|
+
## [0.3.1] - 2026-11-17
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- `checked` set from outside moves the checkbox, also after the user has pressed it. The field wrote the `checked` attribute of its native input alone, which is the default of the control: after a press the control no longer follows it. `field.checked = false`, or the `checked` attribute, took the check mark away, while the native checkbox stayed checked and the form went on submitting the value. The field now writes the property of the input as well, before it dispatches `input-change`. ([#185](https://github.com/webtides/element-library/issues/185))
|
|
20
|
+
|
|
15
21
|
## [0.3.0] - 2026-11-17
|
|
16
22
|
|
|
17
23
|
### Changed
|
|
@@ -50,7 +50,13 @@ export default class CheckboxField extends FormField {
|
|
|
50
50
|
this.setAttribute('checked', checked ? 'true' : 'false');
|
|
51
51
|
if (checked) this._internals.states.add('checked');
|
|
52
52
|
else this._internals.states.delete('checked');
|
|
53
|
-
|
|
53
|
+
// The `checked` attribute the template writes is only the default of the control:
|
|
54
|
+
// once the user has pressed it, the browser no longer follows the attribute. So a
|
|
55
|
+
// state from outside is written to the control as well, before the event says
|
|
56
|
+
// that it has changed.
|
|
57
|
+
const input = this.$refs.input;
|
|
58
|
+
if (input.checked !== !!checked) input.checked = !!checked;
|
|
59
|
+
this.dispatch(FormFieldEvents.INPUT_CHANGE, input.value);
|
|
54
60
|
},
|
|
55
61
|
};
|
|
56
62
|
}
|
|
@@ -12,6 +12,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|
|
12
12
|
|
|
13
13
|
## Unreleased
|
|
14
14
|
|
|
15
|
+
## [0.3.1] - 2026-11-17
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- `checked` set from outside moves the switch, also after the user has pressed it. The field wrote the `checked` attribute of its native input alone, which is the default of the control: after a press the control no longer follows it. `field.checked = false`, or the `checked` attribute, turned the host and its `:state(checked)` off, while the track stayed on and the form went on submitting the value. The field now writes the property of the input as well, before it dispatches `input-change`. ([#185](https://github.com/webtides/element-library/issues/185))
|
|
20
|
+
|
|
15
21
|
## [0.3.0] - 2026-11-17
|
|
16
22
|
|
|
17
23
|
### Changed
|
|
@@ -51,7 +51,13 @@ export default class SwitchField extends FormField {
|
|
|
51
51
|
this.setAttribute('checked', checked ? 'true' : 'false');
|
|
52
52
|
if (checked) this._internals.states.add('checked');
|
|
53
53
|
else this._internals.states.delete('checked');
|
|
54
|
-
|
|
54
|
+
// The `checked` attribute the template writes is only the default of the control:
|
|
55
|
+
// once the user has pressed it, the browser no longer follows the attribute. So a
|
|
56
|
+
// state from outside is written to the control as well, before the event says
|
|
57
|
+
// that it has changed.
|
|
58
|
+
const input = this.$refs.input;
|
|
59
|
+
if (input.checked !== !!checked) input.checked = !!checked;
|
|
60
|
+
this.dispatch(FormFieldEvents.INPUT_CHANGE, input.value);
|
|
55
61
|
},
|
|
56
62
|
};
|
|
57
63
|
}
|
|
@@ -11,12 +11,15 @@ import { TemplateElement } from '@webtides/element-js';
|
|
|
11
11
|
* `aria-controls` as references to the elements they name.
|
|
12
12
|
*
|
|
13
13
|
* The element is form-associated: a `<fieldset disabled>` around it disables it, and it is listed in
|
|
14
|
-
* the `elements` of its form. A button of the type `submit`
|
|
15
|
-
* `<button type="submit">` in its content
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
14
|
+
* the `elements` of its form. A button of the type `submit` submits its form with a hidden native
|
|
15
|
+
* `<button type="submit">` in its content: it is the `submitter` of the `submit` event, its `name`
|
|
16
|
+
* and `value` are in the data of the form, and Enter in a field of the form finds it. The element
|
|
17
|
+
* makes that button when the form is first submitted with it, by a click or by Enter in a field.
|
|
18
|
+
* Until then its content is what the page wrote, so a framework can hydrate a server-rendered
|
|
19
|
+
* button, also when the element has started before the framework does. The attributes `form`,
|
|
20
|
+
* `formaction`, `formenctype`, `formmethod`, `formnovalidate` and `formtarget` of the element do
|
|
21
|
+
* what they do on a native button. A `click` listener of the page that calls `preventDefault()`
|
|
22
|
+
* keeps the button from submitting or resetting.
|
|
20
23
|
*
|
|
21
24
|
* @element el-button
|
|
22
25
|
*
|
|
@@ -69,6 +72,12 @@ export default class Button extends TemplateElement {
|
|
|
69
72
|
* @type {HTMLButtonElement | undefined}
|
|
70
73
|
*/
|
|
71
74
|
private _submitter;
|
|
75
|
+
/**
|
|
76
|
+
* Where the element listens for Enter in a field of its form, see `afterUpdate()`.
|
|
77
|
+
* @private
|
|
78
|
+
* @type {Node | undefined}
|
|
79
|
+
*/
|
|
80
|
+
private _keydownRoot;
|
|
72
81
|
constructor();
|
|
73
82
|
properties(): {
|
|
74
83
|
variant: string;
|
|
@@ -116,6 +125,19 @@ export default class Button extends TemplateElement {
|
|
|
116
125
|
newValue: unknown;
|
|
117
126
|
}): void;
|
|
118
127
|
afterUpdate(): void;
|
|
128
|
+
disconnected(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Enter in a field of the form submits the form with its first submit button, and without one
|
|
131
|
+
* only a form with a single field. The browser looks for that button once every listener has
|
|
132
|
+
* had the key, so the native submit button of the element is made here, if it is not there yet.
|
|
133
|
+
*
|
|
134
|
+
* Only for a key the browser may submit with: Enter in an `<input>` or a `<select>` of the
|
|
135
|
+
* form, and not while a text is being composed. Enter in a `<textarea>` is a line break, and
|
|
136
|
+
* leaves the content of the element as it is.
|
|
137
|
+
* @private
|
|
138
|
+
* @param {KeyboardEvent} event
|
|
139
|
+
*/
|
|
140
|
+
private _onRootKeydown;
|
|
119
141
|
/** Focuses the underlying control. */
|
|
120
142
|
focus(options: any): void;
|
|
121
143
|
/** Removes focus from the underlying control. */
|
|
@@ -162,8 +184,15 @@ export default class Button extends TemplateElement {
|
|
|
162
184
|
* button has. It is disabled while the element is disabled or loading, which keeps Enter from
|
|
163
185
|
* submitting as well. One that is in the content already is taken: written by the page, for a
|
|
164
186
|
* form that is submitted with Enter before the script has run, or copied with the element.
|
|
187
|
+
*
|
|
188
|
+
* The element makes the button only when the form is about to be submitted with it (`create`):
|
|
189
|
+
* with a click, or with Enter in a field. A render does not. The content of the element is what
|
|
190
|
+
* the page wrote until then: a framework that hydrates a server-rendered page after the element
|
|
191
|
+
* has started finds the children it rendered, and no other.
|
|
165
192
|
* @private
|
|
166
|
-
* @
|
|
193
|
+
* @param {boolean} [create] - Whether to make the button when there is none.
|
|
194
|
+
* @returns {HTMLButtonElement | null} The submit button, or `null`: for a button of another
|
|
195
|
+
* type, and while there is none and none was asked for.
|
|
167
196
|
*/
|
|
168
197
|
private _syncSubmitter;
|
|
169
198
|
/**
|
package/web-types.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
|
|
3
3
|
"name": "@webtides/element-library",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"contributions": {
|
|
7
7
|
"html": {
|
|
@@ -710,7 +710,7 @@
|
|
|
710
710
|
},
|
|
711
711
|
{
|
|
712
712
|
"name": "el-button",
|
|
713
|
-
"description": "A themeable button that renders a native `<button>` — or an `<a>` when `href` is set — and\ndecorates it with the `--el-*` design tokens. Speaks the library's shared vocabulary: a semantic\n`variant`, an `appearance` and a `size`. Also supports pill / circle shapes, an optional\ndropdown caret and a loading spinner.\n\nARIA attributes on the element reach the control inside it, which is what has the focus and what\na screen reader announces: `aria-label`, `aria-description`, `aria-expanded`, `aria-haspopup`,\n`aria-pressed` and `aria-current` as they are, `aria-labelledby`, `aria-describedby` and\n`aria-controls` as references to the elements they name.\n\nThe element is form-associated: a `<fieldset disabled>` around it disables it, and it is listed in\nthe `elements` of its form. A button of the type `submit`
|
|
713
|
+
"description": "A themeable button that renders a native `<button>` — or an `<a>` when `href` is set — and\ndecorates it with the `--el-*` design tokens. Speaks the library's shared vocabulary: a semantic\n`variant`, an `appearance` and a `size`. Also supports pill / circle shapes, an optional\ndropdown caret and a loading spinner.\n\nARIA attributes on the element reach the control inside it, which is what has the focus and what\na screen reader announces: `aria-label`, `aria-description`, `aria-expanded`, `aria-haspopup`,\n`aria-pressed` and `aria-current` as they are, `aria-labelledby`, `aria-describedby` and\n`aria-controls` as references to the elements they name.\n\nThe element is form-associated: a `<fieldset disabled>` around it disables it, and it is listed in\nthe `elements` of its form. A button of the type `submit` submits its form with a hidden native\n`<button type=\"submit\">` in its content: it is the `submitter` of the `submit` event, its `name`\nand `value` are in the data of the form, and Enter in a field of the form finds it. The element\nmakes that button when the form is first submitted with it, by a click or by Enter in a field.\nUntil then its content is what the page wrote, so a framework can hydrate a server-rendered\nbutton, also when the element has started before the framework does. The attributes `form`,\n`formaction`, `formenctype`, `formmethod`, `formnovalidate` and `formtarget` of the element do\nwhat they do on a native button. A `click` listener of the page that calls `preventDefault()`\nkeeps the button from submitting or resetting.\n\n---\n\n\n### **Methods:**\n - **formDisabledCallback()** - The platform says that the element is disabled, or no longer is: by its own attribute, or by a\n`<fieldset disabled>` around it. The template asks the platform, see `_isDisabled()`.\n- **reflectProperty(options: _{ property: string, newValue: unknown }_)** - `disabled` is reflected as the platform reads it: the attribute is there while the button is\ndisabled, and gone while it is not. element-js would write `disabled=\"false\"`.\n- **focus(options)** - Focuses the underlying control.\n- **blur()** - Removes focus from the underlying control.\n- **click()** - Simulates a click on the underlying control.\n\n### **Slots:**\n - _default_ - The button's label.\n- **prefix** - A presentational prefix icon or similar element.\n- **suffix** - A presentational suffix icon or similar element.\n\n### **CSS Parts:**\n - **base** - The internal `<button>` / `<a>`. The surface for background, border, radius.\n- **prefix** - Container wrapping the `prefix` slot.\n- **label** - The default-slot label wrapper.\n- **suffix** - Container wrapping the `suffix` slot.\n- **caret** - The dropdown caret, present only while `caret` is `true`.\n- **spinner** - The loading spinner, present only while `loading` is `true`.",
|
|
714
714
|
"doc-url": "",
|
|
715
715
|
"attributes": [
|
|
716
716
|
{
|