Skip to content
This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Commit bb6b5c1

Browse files
committed
Merge branch 'event'
2 parents f8c78de + 5e3f837 commit bb6b5c1

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# <details-dialog> element
22

3-
A modal dialog that's opened with a <details> button.
3+
A modal dialog that's opened with a <details> button.
44

55
## Installation
66

@@ -43,17 +43,18 @@ If the `preload` attribute is present, hovering over the `<details>` element wil
4343

4444
## Events
4545

46-
### `details-dialog:will-close`
46+
### `details-dialog-close`
4747

48-
A `details-dialog:will-close` event is fired when a request to close the dialog
49-
is made either by pressing escape, clicking a `data-close-dialog` element,
50-
clicking on the `<summary>` element, or when `.toggle(false)` is called on an
51-
open dialog.
48+
`details-dialog-close` event is fired from `<details-dialog>` when a request to close the dialog is made from
5249

53-
This event can be cancelled to keep the dialog open.
50+
- pressing <kbd>escape</kbd>,
51+
- clicking on `summary, [data-close-dialog]`, or
52+
- `dialog.toggle(false)`
53+
54+
This event bubbles, and can be canceled to keep the dialog open.
5455

5556
```js
56-
document.addEventListener('details-dialog:will-close', function(event) {
57+
document.addEventListener('details-dialog-close', function(event) {
5758
if (!confirm('Are you sure?')) {
5859
event.preventDefault()
5960
}

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function allowClosingDialog(details: Element): boolean {
6565
if (!(dialog instanceof DetailsDialogElement)) return true
6666

6767
return dialog.dispatchEvent(
68-
new CustomEvent('details-dialog:will-close', {
68+
new CustomEvent('details-dialog-close', {
6969
bubbles: true,
7070
cancelable: true
7171
})
@@ -77,7 +77,7 @@ function onSummaryClick(event: Event): void {
7777
const details = event.currentTarget.closest('details[open]')
7878
if (!details) return
7979

80-
// Prevent summary click events if details-dialog:will-close was cancelled
80+
// Prevent summary click events if details-dialog-close was cancelled
8181
if (!allowClosingDialog(details)) {
8282
event.preventDefault()
8383
event.stopPropagation()

test/test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ describe('details-dialog-element', function() {
8888
assert.equal(document.activeElement, document.querySelector(`[${CLOSE_ATTR}]`))
8989
})
9090

91-
it('supports a cancellable details-dialog:will-close event when a summary element is present', async function() {
91+
it('supports a cancellable details-dialog-close event when a summary element is present', async function() {
9292
dialog.toggle(true)
9393
await waitForToggleEvent(details)
9494
assert(details.open)
9595

9696
let closeRequestCount = 0
9797
let allowCloseToHappen = false
9898
dialog.addEventListener(
99-
'details-dialog:will-close',
99+
'details-dialog-close',
100100
function(event) {
101101
closeRequestCount++
102102
if (!allowCloseToHappen) {
@@ -133,15 +133,15 @@ describe('details-dialog-element', function() {
133133
summary.remove()
134134
})
135135

136-
it('supports a cancellable details-dialog:will-close event', async function() {
136+
it('supports a cancellable details-dialog-close event', async function() {
137137
dialog.toggle(true)
138138
await waitForToggleEvent(details)
139139
assert(details.open)
140140

141141
let closeRequestCount = 0
142142
let allowCloseToHappen = false
143143
dialog.addEventListener(
144-
'details-dialog:will-close',
144+
'details-dialog-close',
145145
function(event) {
146146
closeRequestCount++
147147
if (!allowCloseToHappen) {

0 commit comments

Comments
 (0)