-
Notifications
You must be signed in to change notification settings - Fork 22.9k
41143 enable command for #41423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
41143 enable command for #41423
Conversation
Preview URLs
(comment last updated: 2025-10-07 16:01:55) |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
… into 41143-enable-commandFor
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Would these also need to be updated in BCD (https://github.com/mdn/browser-compat-data/blob/main/html/elements/button.json):
They all link to the same bug: bug 1983523 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review for the <button>
page
|
||
## Examples | ||
|
||
### Basic example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Basic example | |
### Creating a basic button |
``` | ||
|
||
{{ EmbedLiveSample('Example', 200, 64) }} | ||
{{ EmbedLiveSample('basic_example', 200, 64) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the macro will need updating if you accept the title change
```html | ||
<button name="button">Press me</button> | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that this example was already on the page and not one you've added. Since we're touching it here anyway, sharing some thoughts I have for improving it slightly. LMK what you think.
If we don't mention the type
, its default value is submit
but that's true when the button is inside a form. In this case, since we're not showing a form or explaining any other context for the button, let's explicitly specify the type
as a best practice. Also suggesting a different name for the button to hint that it doesn't do anything.
```html | |
<button name="button">Press me</button> | |
``` | |
This example creates a clickable button. | |
The `type="button"` attribute ensures the button has no default behavior. | |
You can make this button interactive using JavaScript or attributes such as `command` and `commandfor`. | |
```html | |
<button type="button" name="button">I'm a button</button> |
{{ EmbedLiveSample('Example', 200, 64) }} | ||
{{ EmbedLiveSample('basic_example', 200, 64) }} | ||
|
||
### Command request-close |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Command request-close | |
### Using the `request-close` value for the `command` attribute |
|
||
### Command request-close | ||
|
||
This example uses the `request-close` value for the command attribute to check if a dialog is [`cancelable`](/en-US/docs/Web/API/Event/cancelable) when clicking a close button. When clicking the close button inside the dialog it checks to see if the radio button is set to yes, if not the dialog will not close. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the UI description before the code and move all explanations about what's happening behind the scenes to after the Result frame.
So here, we can keep it as:
This example uses the `request-close` value for the command attribute to check if a dialog is [`cancelable`](/en-US/docs/Web/API/Event/cancelable) when clicking a close button. When clicking the close button inside the dialog it checks to see if the radio button is set to yes, if not the dialog will not close. | |
The dialog in this example has two radio buttons that control whether or not the dialog can be closed. | |
Select **Yes** or **No**, and then click **Request to Close** to try to close the dialog. | |
If **Yes** is selected, the dialog closes; if **No** is selected, the dialog stays open and shows a message instead. |
<dialog id="mydialog"> | ||
<div class="wrapper"> | ||
<form> | ||
<legend>Would you like to be able to close this dialog:</legend> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
<legend>Would you like to be able to close this dialog:</legend> | |
<legend>Allow this dialog to close when requested?</legend> |
<form> | ||
<legend>Would you like to be able to close this dialog:</legend> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a fieldset to the form?
<form> | |
<legend>Would you like to be able to close this dialog:</legend> | |
<form> | |
<fieldset> | |
<legend>Would you like to be able to close this dialog:</legend> |
Request to Close | ||
</button> | ||
<p class="warning" hidden> | ||
You have not selected yes so can not close this dialog. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have not selected yes so can not close this dialog. | |
You must choose "Yes" to close this dialog. |
}); | ||
``` | ||
|
||
{{ EmbedLiveSample('command_request-close', 200) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macro will need updating if changing the section title
``` | ||
|
||
{{ EmbedLiveSample('command_request-close', 200) }} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's explain here (after the result frame) what's happening behind the scenes. Just jotting down some rough points to outline the flow:
- The Open Dialog button opens the dialog using
command="show-modal"
. - The Request to Close button has
command="request-close"
andcommandfor="mydialog"
. So when it's clicked, it asks the dialog if it can be closed (unlike theclose
command, which would close the dialog immediately). - This triggers a cancelable
cancel
event on the dialog. - The script listening for this event calls
preventDefault()
when No is selected. in turn keeping dialog open and showing message. - If event is not canceled (when Yes is selected), the browser closes the dialog.
Description
command
attribute on:commandEvent()
pagecommand
property pagerequest-close
value forcommand
attributeMotivation
Related issues and pull requests