lostcoords-ui 0.14.5 → 0.14.7
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.
- checksums.yaml +4 -4
- data/README.md +22 -1
- data/app/javascript/lostcoords/ui/helpers/confirm.js +0 -3
- data/app/javascript/lostcoords/ui/helpers/context_dialog.js +2 -1
- data/app/javascript/lostcoords/ui/helpers/dialog.js +11 -5
- data/app/javascript/lostcoords/ui/helpers/focus.js +22 -1
- data/lib/lostcoords/ui/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e59511fee6edfa9e200f7b2561e8937d9d17c3884690db48e153346031fb54b
|
|
4
|
+
data.tar.gz: af8f42618286ed51b91f7dfcfe9f97cbf8f44bf24472a1ca1e2bb5eea603a3e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8867f7a32ba7c848d3d908eabdd3bb326ae482ff3856faba090fbc3db0999f2a25c50133f5ebd3a057e7bbd0e026a926f8198f02fd0733ebd7260e5b87947398
|
|
7
|
+
data.tar.gz: 0c7ebba325be9b795f36d5dbe6ec20ca6fc851fe09069c231c78218fa78c0402413312b31a5a6d7831768f45b4951df7b22e8df6c9bb4ed7f232ccec4d2221af
|
data/README.md
CHANGED
|
@@ -170,6 +170,25 @@ Omit `only` to register every library controller. Unknown identifiers raise befo
|
|
|
170
170
|
registered, and repeated calls on the same application keep later overrides, so register defaults
|
|
171
171
|
before application overrides.
|
|
172
172
|
|
|
173
|
+
## Changes in 0.14.7
|
|
174
|
+
|
|
175
|
+
Nothing needs an edit. Fixed:
|
|
176
|
+
|
|
177
|
+
- **Focus also returns when the host removes the dialog as it closes.** Such a caller unregisters before
|
|
178
|
+
the `close` event arrives, which is where 0.14.6 returned focus, so Safari still left it on the page.
|
|
179
|
+
Focus now settles when a closed dialog is unregistered.
|
|
180
|
+
|
|
181
|
+
## Changes in 0.14.6
|
|
182
|
+
|
|
183
|
+
Nothing needs an edit. Fixed:
|
|
184
|
+
|
|
185
|
+
- **Focus returns to the pressed control in Safari.** Safari on a Mac doesn't focus a button or link on
|
|
186
|
+
click, so the browser had nothing to hand focus back to when a dialog closed and it fell to the page.
|
|
187
|
+
`registerDialog` now remembers what was pressed and returns focus there when closing leaves it nowhere.
|
|
188
|
+
- **`showContextDialog` opens through `showDialog`**, so a dialog anchored to a menu takes focus itself, as
|
|
189
|
+
every other dialog does, instead of ringing its first control. The confirm sheet no longer repeats the
|
|
190
|
+
step.
|
|
191
|
+
|
|
173
192
|
## Changes in 0.14.5
|
|
174
193
|
|
|
175
194
|
One edit, only for a host that skips `base.css`:
|
|
@@ -1152,7 +1171,9 @@ Every interactive component works from the keyboard without extra code:
|
|
|
1152
1171
|
The focus ring follows how the person is moving. Focus that comes back from a closed dialog, sheet, menu
|
|
1153
1172
|
or popover shows its ring only after Tab or an arrow key moved focus; Escape, Enter in a field and typing
|
|
1154
1173
|
don't count, so a dialog opened with the mouse and closed with Escape leaves no ring on its button. A panel
|
|
1155
|
-
closed from inside, such as by choosing a menu item, returns focus to what opened it
|
|
1174
|
+
closed from inside, such as by choosing a menu item, returns focus to what opened it, and a dialog
|
|
1175
|
+
closed with nothing focused before it, as after a click in Safari, returns focus to the control that was
|
|
1176
|
+
pressed. A controller that
|
|
1156
1177
|
moves focus back itself calls `settleFocus()` from `lostcoords/ui/helpers/focus` afterwards for the same
|
|
1157
1178
|
rule. Hosts that skip `base.css` hide the ring on `[data-lc-focus-quiet]:focus-visible`.
|
|
1158
1179
|
|
|
@@ -50,8 +50,5 @@ export function ask(
|
|
|
50
50
|
dialog.style.removeProperty("--lc-dialog-origin")
|
|
51
51
|
showContextDialog(dialog, anchor)
|
|
52
52
|
registerDialog(dialog, { lockScroll: false })
|
|
53
|
-
// showModal focuses Cancel, and a confirm raised while typing would hand it the field's focus ring.
|
|
54
|
-
// The sheet itself takes focus; Tab still reaches both buttons.
|
|
55
|
-
dialog.focus({ preventScroll: true })
|
|
56
53
|
})
|
|
57
54
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { showDialog } from "lostcoords/ui/helpers/dialog"
|
|
1
2
|
import { isSheetViewport } from "lostcoords/ui/helpers/viewport"
|
|
2
3
|
|
|
3
4
|
const EDGE = 16
|
|
4
5
|
|
|
5
6
|
export function showContextDialog(dialog, menu) {
|
|
6
7
|
delete dialog.dataset.anchored
|
|
7
|
-
|
|
8
|
+
showDialog(dialog)
|
|
8
9
|
|
|
9
10
|
const rect = menu?.getBoundingClientRect()
|
|
10
11
|
const corner = rect?.height
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
|
|
2
|
-
import { settleFocus } from "lostcoords/ui/helpers/focus"
|
|
2
|
+
import { currentOpener, returnFocus, settleFocus } from "lostcoords/ui/helpers/focus"
|
|
3
3
|
|
|
4
4
|
const registrations = new WeakMap()
|
|
5
5
|
|
|
@@ -42,6 +42,8 @@ export function registerDialog(
|
|
|
42
42
|
const existing = registrations.get(dialog)
|
|
43
43
|
if (existing) return existing
|
|
44
44
|
|
|
45
|
+
const opener = currentOpener(dialog)
|
|
46
|
+
|
|
45
47
|
const unregisterDismissable = registerDismissable({
|
|
46
48
|
element: dialog,
|
|
47
49
|
type: "lc-dialog",
|
|
@@ -64,12 +66,12 @@ export function registerDialog(
|
|
|
64
66
|
if (!inside) close(event)
|
|
65
67
|
}
|
|
66
68
|
// A dialog closed and shown again in the same task fires close while it is already open again.
|
|
67
|
-
// By now the browser has handed focus back to what had it before the dialog opened.
|
|
68
69
|
const unregisterOnClose = () => {
|
|
69
|
-
if (dialog.open)
|
|
70
|
-
unregister()
|
|
71
|
-
settleFocus()
|
|
70
|
+
if (!dialog.open) unregister()
|
|
72
71
|
}
|
|
72
|
+
// A closed dialog has handed focus back to what had it before it opened, if anything had. A
|
|
73
|
+
// caller that removes the dialog as it closes unregisters before the close event arrives, so
|
|
74
|
+
// focus settles here and not in that event.
|
|
73
75
|
const unregister = () => {
|
|
74
76
|
if (registrations.get(dialog) !== unregister) return
|
|
75
77
|
registrations.delete(dialog)
|
|
@@ -77,6 +79,10 @@ export function registerDialog(
|
|
|
77
79
|
dialog.removeEventListener("close", unregisterOnClose)
|
|
78
80
|
dialog.removeEventListener("click", closeOnBackdrop)
|
|
79
81
|
unregisterDismissable()
|
|
82
|
+
if (dialog.open) return
|
|
83
|
+
|
|
84
|
+
returnFocus(opener, dialog)
|
|
85
|
+
settleFocus()
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
registrations.set(dialog, unregister)
|
|
@@ -5,11 +5,14 @@ import { isEditable } from "lostcoords/ui/helpers/roving_focus"
|
|
|
5
5
|
// focus back to its opener with a ring nobody asked for. Only moving focus by key counts here.
|
|
6
6
|
const MOVES = new Set(["Tab", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End"])
|
|
7
7
|
const QUIET = "data-lc-focus-quiet"
|
|
8
|
+
const CONTROL = "a[href], button, summary, [tabindex]"
|
|
8
9
|
let byKeyboard = false
|
|
10
|
+
let pressed = null
|
|
9
11
|
|
|
10
12
|
document.addEventListener(
|
|
11
13
|
"keydown",
|
|
12
14
|
(event) => {
|
|
15
|
+
pressed = null
|
|
13
16
|
if (event.key === "Tab" || (MOVES.has(event.key) && !isEditable(event.target)))
|
|
14
17
|
byKeyboard = true
|
|
15
18
|
},
|
|
@@ -17,8 +20,9 @@ document.addEventListener(
|
|
|
17
20
|
)
|
|
18
21
|
document.addEventListener(
|
|
19
22
|
"pointerdown",
|
|
20
|
-
() => {
|
|
23
|
+
(event) => {
|
|
21
24
|
byKeyboard = false
|
|
25
|
+
pressed = event.target.closest?.(CONTROL) ?? null
|
|
22
26
|
},
|
|
23
27
|
true,
|
|
24
28
|
)
|
|
@@ -27,6 +31,23 @@ document.addEventListener("turbo:before-morph-attribute", (event) => {
|
|
|
27
31
|
if (event.detail.attributeName === QUIET) event.preventDefault()
|
|
28
32
|
})
|
|
29
33
|
|
|
34
|
+
// What opened whatever is opening now: the element with focus, or the control just pressed.
|
|
35
|
+
// Safari on a Mac doesn't focus a button or link on click, so there the browser has nothing to
|
|
36
|
+
// hand focus back to when a dialog closes.
|
|
37
|
+
export function currentOpener(overlay) {
|
|
38
|
+
const active = document.activeElement
|
|
39
|
+
if (active && active !== document.body && !overlay.contains(active)) return active
|
|
40
|
+
return pressed && !overlay.contains(pressed) ? pressed : null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Focus goes back to opener when closing overlay left it nowhere: on the body, or still inside.
|
|
44
|
+
export function returnFocus(opener, overlay) {
|
|
45
|
+
const active = document.activeElement
|
|
46
|
+
const lost = !active || active === document.body || overlay.contains(active)
|
|
47
|
+
if (lost && opener?.isConnected && opener.getClientRects().length > 0)
|
|
48
|
+
opener.focus({ preventScroll: true })
|
|
49
|
+
}
|
|
50
|
+
|
|
30
51
|
// Call after focus has come back from a closed dialog, menu or panel. Unless the person is moving
|
|
31
52
|
// focus by keyboard, the element that has it keeps it without the ring until focus moves on.
|
|
32
53
|
// A text field always shows its ring, as it does on a click.
|