Skip to content

Commit cf48d96

Browse files
authored
Update invokers explainer (#1139)
- Remove left over references to `input[type=button]` as that's not supported. - Update explanations for type="reset" and type="submit". - Add explanation for why `input[type=button]` isn't supported. - Add explicit type="button" to all the example buttons.
1 parent f609b55 commit cf48d96

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

site/src/pages/components/invokers.explainer.mdx

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ the balance.
8080
`Space` or `Enter` (Carriage Return) key on the keyboard. For other HIDs such
8181
as eye tracking or pedals or game controllers, the equivalent expected "click"
8282
action should be used to invoke the element.
83-
- Invoker: An invoker is a button element (that is a `<button>`,
84-
`<input type="button">`, or `<input type="reset">`) that has an `commandfor`
85-
and `command` attribute set.
83+
- Invoker: An invoker is a button control (that is a `<button type="button">`) that has a
84+
`commandfor` and `command` attribute set.
8685
- Invoker Target: An element which is referenced to by an Invoker, via the
8786
`commandfor` attribute.
8887

@@ -167,7 +166,7 @@ When pointing to a `popover`, `commandfor` acts much like `popovertarget`,
167166
allowing the toggling of popovers.
168167

169168
```html
170-
<button commandfor="my-popover" command="toggle-popover">Open Popover</button>
169+
<button type="button" commandfor="my-popover" command="toggle-popover">Open Popover</button>
171170
<!-- Effectively the same as popovertarget="my-popover" -->
172171

173172
<div id="my-popover" popover="auto">Hello world</div>
@@ -179,12 +178,12 @@ When pointing to a `<dialog>`, `command` can toggle a `<dialog>`'s
179178
openness.
180179

181180
```html
182-
<button commandfor="my-dialog" command="show-modal">Open Dialog</button>
181+
<button type="button" commandfor="my-dialog" command="show-modal">Open Dialog</button>
183182

184183
<dialog id="my-dialog">
185184
Hello world!
186185

187-
<button commandfor="my-dialog" command="close">Close</button>
186+
<button type="button" commandfor="my-dialog" command="close">Close</button>
188187
</dialog>
189188
```
190189

@@ -196,7 +195,7 @@ When pointing to a `<details>`, `commandfor` can toggle a `<details>`'
196195
openness.
197196

198197
```html
199-
<button commandfor="my-details" command="open">Open Details</button>
198+
<button type="button" commandfor="my-details" command="open">Open Details</button>
200199
<!-- Can be used to replicate the `<summary>` interaction -->
201200

202201
<details id="my-details">
@@ -214,7 +213,7 @@ rendered button _within_ the input; and can be used to declare a customised
214213
alternative button to the input's button.
215214

216215
```html
217-
<button commandfor="my-file" command="show-picker">Pick a file...</button>
216+
<button type="button" commandfor="my-file" command="show-picker">Pick a file...</button>
218217

219218
<input id="my-file" type="file" />
220219
```
@@ -228,8 +227,8 @@ shines, allowing multiple buttons to handle different interactions with the
228227
video player.
229228

230229
```html
231-
<button commandfor="my-video" command="play-pause">Play/Pause</button>
232-
<button commandfor="my-video" command="toggle-muted">Mute/Unmute</button>
230+
<button type="button" commandfor="my-video" command="play-pause">Play/Pause</button>
231+
<button type="button" commandfor="my-video" command="toggle-muted">Mute/Unmute</button>
233232

234233
<video id="my-video"></video>
235234
```
@@ -242,7 +241,7 @@ manual event handlers to the Invokers.
242241

243242
```html
244243
<!-- Custom commands must contain a double dash! -->
245-
<button commandfor="my-custom" command="--my-frobulate">Frobulate</button>
244+
<button type="button" commandfor="my-custom" command="--my-frobulate">Frobulate</button>
246245

247246
<div id="my-custom"></div>
248247

@@ -579,7 +578,7 @@ As the underlying system for invoke elements uses event dispatch, Custom Element
579578
can make use of `CommandEvent` for their own behaviours. Consider the following:
580579

581580
```html
582-
<button commandfor="my-element" command="--spin-widget">
581+
<button type="button" commandfor="my-element" command="--spin-widget">
583582
Spin the widget
584583
</button>
585584

@@ -696,7 +695,7 @@ fullscreen may now declare a button that can fullscreen. Consider the following:
696695
```html
697696
<iframe sandbox allow="fullscreen">
698697
<html id="invokee">
699-
<button commandfor="invokee" command="toggleFullscreen">Invoke</button>
698+
<button type="button" commandfor="invokee" command="toggleFullscreen">Invoke</button>
700699
<button onclick="invokee.requestFullscreen()">Go fullscreen</button>
701700
</html>
702701
</iframe>
@@ -810,29 +809,25 @@ for non-interactive elements. While `<a>`s _are_ interactive, they should _only_
810809
be used for page navigation and not for invoking other behaviours, and so
811810
`command`/`commandfor` should not be allowed.
812811

813-
#### Why isn't `input[type=submit]` included?
812+
#### Why isn't `button[type=submit]` included?
814813

815814
This is not added by design. Submit inputs already have a default action:
816815
submitting forms. If you want a button to control the submission of a form, use
817-
`input[type=submit]`, if you want a button to control invocation of something
818-
_other_ than a form then you should use `input[type=button]`.
816+
`button[type=submit]`, if you want a button to control invocation of something
817+
_other_ than a form then you should use `button[type=button]`.
819818

820-
#### Why _is_ `input[type=reset]` included?
819+
#### Why isn't `button[type=reset]` included?
821820

822-
It may stand to reason that if `input[type=submit]` is _excluded_ then so should
823-
`input[type=reset]`, however, there are valid use cases to resetting a form at
824-
the same time as some other action, for example closing the dialog that contains
825-
a form:
821+
This is not added by design. Reset inputs already have a default action:
822+
resetting forms. If you want a button to control the resetting of a form, use
823+
`button[type=reset]`, if you want a button to control invocation of something
824+
_other_ than a form then you should use `button[type=button]`.
826825

827-
```html
828-
<dialog id="my-dialog">
829-
<form>
830-
<input type="text" />
831-
<!-- This button closes the dialog _and_ resets the form -->
832-
<input type="reset" commandfor="my-dialog" command="close" value="Cancel" />
833-
</form>
834-
</dialog>
835-
```
826+
#### Why isn't `input[type=button]` included?
827+
828+
This is not added by design. `input[type=button]` is a legacy element,
829+
use of this element is discouraged in favour of `<button>`. So we only support
830+
`<button>` elements.
836831

837832
#### What does this mean for `popovertarget`?
838833

@@ -854,7 +849,7 @@ methods, if that's desired:
854849

855850

856851
```html
857-
<button commandfor="my-element" command="--spin-widget">
852+
<button type="button" commandfor="my-element" command="--spin-widget">
858853
Spin the widget
859854
</button>
860855

@@ -888,9 +883,9 @@ you feel it necessary you can invent your own DSLs for passing extra data using
888883
this hint. For example:
889884

890885
```html
891-
<button commandfor="my-counter" command="--add-1">Add 1</button>
892-
<button commandfor="my-counter" command="--add-2">Add 2</button>
893-
<button commandfor="my-counter" command="--add-10">Add 10</button>
886+
<button type="button" commandfor="my-counter" command="--add-1">Add 1</button>
887+
<button type="button" commandfor="my-counter" command="--add-2">Add 2</button>
888+
<button type="button" commandfor="my-counter" command="--add-10">Add 10</button>
894889

895890
<input readonly id="my-counter" value="0" />
896891

@@ -909,9 +904,9 @@ You can also leverage the buttons `value` attribute to effectively parameterise
909904
certain commands:
910905

911906
```html
912-
<button commandfor="my-counter" command="--add-num" value="1">Add 1</button>
913-
<button commandfor="my-counter" command="--add-num" value="2">Add 2</button>
914-
<button commandfor="my-counter" command="--add-num" value="10">Add 10</button>
907+
<button type="button" commandfor="my-counter" command="--add-num" value="1">Add 1</button>
908+
<button type="button" commandfor="my-counter" command="--add-num" value="2">Add 2</button>
909+
<button type="button" commandfor="my-counter" command="--add-num" value="10">Add 10</button>
915910

916911
<input readonly id="my-counter" value="0" />
917912

@@ -924,3 +919,5 @@ certain commands:
924919
});
925920
</script>
926921
```
922+
923+
You could also use `data-*` attributes for even more granular control.

0 commit comments

Comments
 (0)