Skip to content
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

Revert #29639 & create page for HTMLInputElement.cancel_event #36439

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions files/en-us/_redirects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8099,7 +8099,7 @@
/en-US/docs/Web/API/Element/MozMousePixelScroll /en-US/docs/Web/API/Element/MozMousePixelScroll_event
/en-US/docs/Web/API/Element/accessKey /en-US/docs/Web/API/HTMLElement/accessKey
/en-US/docs/Web/API/Element/attachInternals /en-US/docs/Web/API/HTMLElement/attachInternals
/en-US/docs/Web/API/Element/cancel_event /en-US/docs/Web/API/HTMLElement/cancel_event
/en-US/docs/Web/API/Element/cancel_event /en-US/docs/Web/API/HTMLDialogElement/cancel_event
/en-US/docs/Web/API/Element/contentvisibilityautostatechanged_event /en-US/docs/Web/API/Element/contentvisibilityautostatechange_event
/en-US/docs/Web/API/Element/createShadowRoot /en-US/docs/Web/API/Element/shadowRoot
/en-US/docs/Web/API/Element/error_event /en-US/docs/Web/API/HTMLElement/error_event
Expand Down Expand Up @@ -8417,7 +8417,6 @@
/en-US/docs/Web/API/HTMLContentElement.select /en-US/docs/Web/API/HTMLSlotElement
/en-US/docs/Web/API/HTMLContentElement/getDistributedNodes /en-US/docs/Web/API/HTMLSlotElement
/en-US/docs/Web/API/HTMLContentElement/select /en-US/docs/Web/API/HTMLSlotElement
/en-US/docs/Web/API/HTMLDialogElement/cancel_event /en-US/docs/Web/API/HTMLElement/cancel_event
/en-US/docs/Web/API/HTMLDialogElement/close() /en-US/docs/Web/API/HTMLDialogElement/close
/en-US/docs/Web/API/HTMLDialogElement/returnValue() /en-US/docs/Web/API/HTMLDialogElement/returnValue
/en-US/docs/Web/API/HTMLDialogElement/show() /en-US/docs/Web/API/HTMLDialogElement/show
Expand Down Expand Up @@ -11786,7 +11785,7 @@
/en-US/docs/Web/Events/blur /en-US/docs/Web/API/Element/blur_event
/en-US/docs/Web/Events/boundary /en-US/docs/Web/API/SpeechSynthesisUtterance/boundary_event
/en-US/docs/Web/Events/bufferedamountlow /en-US/docs/Web/API/RTCDataChannel/bufferedamountlow_event
/en-US/docs/Web/Events/cancel /en-US/docs/Web/API/HTMLElement/cancel_event
/en-US/docs/Web/Events/cancel /en-US/docs/Web/API/HTMLDialogElement/cancel_event
/en-US/docs/Web/Events/canplay /en-US/docs/Web/API/HTMLMediaElement/canplay_event
/en-US/docs/Web/Events/canplaythrough /en-US/docs/Web/API/HTMLMediaElement/canplaythrough_event
/en-US/docs/Web/Events/change /en-US/docs/Web/API/HTMLElement/change_event
Expand Down
12 changes: 12 additions & 0 deletions files/en-us/_wikihistory.json
Original file line number Diff line number Diff line change
Expand Up @@ -37674,6 +37674,18 @@
"dhodder"
]
},
"Web/API/HTMLDialogElement/cancel_event": {
"modified": "2020-10-15T21:43:04.572Z",
"contributors": [
"mfuji09",
"fscholz",
"mfluehr",
"sideshowbarker",
"fgwang",
"rolfedh",
"cvrebert"
]
},
"Web/API/HTMLDialogElement/close": {
"modified": "2020-10-15T21:52:17.118Z",
"contributors": ["fscholz", "chrisdavidmills"]
Expand Down
95 changes: 95 additions & 0 deletions files/en-us/web/api/htmldialogelement/cancel_event/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
title: "HTMLDialogElement: cancel event"
short-title: cancel
slug: Web/API/HTMLDialogElement/cancel_event
page-type: web-api-event
browser-compat: api.HTMLDialogElement.cancel_event
---

{{APIRef}}

The **`cancel`** event fires on a {{HTMLElement("dialog")}} element when the user instructs the browser that they wish to dismiss the current open dialog. The browser fires this event when the user presses the <kbd>Esc</kbd> key.

This event is cancelable but can not bubble.

When a `<dialog>` is dismissed with the <kbd>Esc</kbd> key, both the `cancel` and {{domxref("HTMLDialogElement/close_event", "close")}} events are fired.

## Syntax

Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.

```js
addEventListener("cancel", (event) => {});

oncancel = (event) => {};
```

## Event type

A generic {{domxref("Event")}}.

## Examples

### Canceling a dialog

#### HTML

```html
<dialog class="example-dialog">
<button class="close" type="reset">Close</button>
</dialog>

<button class="open-dialog">Open dialog</button>

<div class="result"></div>
```

```css hidden
button,
div {
margin: 0.5rem;
}
```

#### JavaScript

```js
const result = document.querySelector(".result");

const dialog = document.querySelector(".example-dialog");

dialog.addEventListener("cancel", (event) => {
result.textContent = "dialog was canceled";
});

const openDialog = document.querySelector(".open-dialog");
openDialog.addEventListener("click", () => {
if (typeof dialog.showModal === "function") {
dialog.showModal();
result.textContent = "";
} else {
result.textContent = "The dialog API is not supported by this browser";
}
});

const closeButton = document.querySelector(".close");
closeButton.addEventListener("click", () => {
dialog.close();
});
```

#### Result

{{ EmbedLiveSample('Canceling a dialog', '100%', '100px') }}

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- HTML {{HTMLElement("dialog")}} element
8 changes: 5 additions & 3 deletions files/en-us/web/api/htmldialogelement/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The **`HTMLDialogElement`** interface provides methods to manipulate {{HTMLEleme

## Instance properties

_Inherits properties from its parent, {{domxref("HTMLElement")}}._
_Also inherits properties from its parent interface, {{domxref("HTMLElement")}}._

- {{domxref("HTMLDialogElement.open")}}
- : A boolean value reflecting the [`open`](/en-US/docs/Web/HTML/Element/dialog#open) HTML attribute, indicating whether the dialog is available for interaction.
Expand All @@ -22,7 +22,7 @@ _Inherits properties from its parent, {{domxref("HTMLElement")}}._

## Instance methods

_Inherits methods from its parent, {{domxref("HTMLElement")}}._
_Also inherits methods from its parent interface, {{domxref("HTMLElement")}}._

- {{domxref("HTMLDialogElement.close()")}}
- : Closes the dialog. An optional string may be passed as an argument, updating the `returnValue` of the dialog.
Expand All @@ -37,14 +37,16 @@ _Also inherits events from its parent interface, {{DOMxRef("HTMLElement")}}._

Listen to these events using {{DOMxRef("EventTarget.addEventListener", "addEventListener()")}} or by assigning an event listener to the `oneventname` property of this interface.

- {{domxref("HTMLDialogElement/cancel_event", "cancel")}}
- : Fired when the user dismisses the current open dialog with the escape key.
- {{domxref("HTMLDialogElement/close_event", "close")}}
- : Fired when the dialog is closed, whether with the escape key, the `HTMLDialogElement.close()` method, or via submitting a form within the dialog with [`method="dialog"`](/en-US/docs/Web/HTML/Element/form#method).

## Examples

### Opening a modal dialog

The following example shows a button that, when clicked, opens a modal {{htmlelement("dialog")}} containing a form via the {{domxref("HTMLDialogElement.showModal()")}} function. While open, everything other than the modal dialog's contents is inert. From there you can click the _Cancel_ button to close the dialog (via the {{domxref("HTMLDialogElement.close()")}} function), or submit the form via the submit button. Selecting the cancel button closes the dialog, creating a {{domxref("HTMLDialogElement/close_event", "close")}} event, not a {{domxref("HTMLElement/cancel_event", "cancel")}} event.
The following example shows a button that, when clicked, opens a modal {{htmlelement("dialog")}} containing a form via the {{domxref("HTMLDialogElement.showModal()")}} function. While open, everything other than the modal dialog's contents is inert. From there you can click the _Cancel_ button to close the dialog (via the {{domxref("HTMLDialogElement.close()")}} function), or submit the form via the submit button. Selecting the cancel button closes the dialog, creating a {{domxref("HTMLDialogElement/close_event", "close")}} event, not a {{domxref("HTMLDialogElement/cancel_event", "cancel")}} event.

#### HTML

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/htmldialogelement/showmodal/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ None ({{jsxref("undefined")}}).

### Opening a modal dialog

The following example shows a button that, when clicked, opens a modal {{htmlelement("dialog")}} containing a form via the `HTMLDialogElement.showModal()` function. While open, everything other than the modal dialog's contents is inert. From there you can click the _Cancel_ button to close the dialog (via the {{domxref("HTMLDialogElement.close()")}} function), or submit the form via the submit button. Selecting the cancel button closes the dialog, creating a {{domxref("HTMLDialogElement/close_event", "close")}} event, not a {{domxref("HTMLElement/cancel_event", "cancel")}} event.
The following example shows a button that, when clicked, opens a modal {{htmlelement("dialog")}} containing a form via the `HTMLDialogElement.showModal()` function. While open, everything other than the modal dialog's contents is inert. From there you can click the _Cancel_ button to close the dialog (via the {{domxref("HTMLDialogElement.close()")}} function), or submit the form via the submit button. Selecting the cancel button closes the dialog, creating a {{domxref("HTMLDialogElement/close_event", "close")}} event, not a {{domxref("HTMLDialogElement/cancel_event", "cancel")}} event.

#### HTML

Expand Down
138 changes: 0 additions & 138 deletions files/en-us/web/api/htmlelement/cancel_event/index.md

This file was deleted.

Loading