lostcoords-ui 0.14.4 → 0.14.6
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 +35 -1
- data/app/assets/tailwind/lostcoords/ui/base.css +1 -2
- data/app/assets/tailwind/lostcoords/ui/emoji-picker.css +0 -5
- data/app/assets/tailwind/lostcoords/ui/utilities.css +8 -0
- data/app/helpers/lostcoords/ui/form_helper.rb +1 -2
- data/app/helpers/lostcoords/ui/list_group_helper.rb +1 -2
- data/app/javascript/lostcoords/ui/controllers/lc_emoji_picker_controller.js +7 -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 +6 -2
- 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: b9905bd1837028339420ab4601d23e1499a6a9ba355b694707fa79284dad63fd
|
|
4
|
+
data.tar.gz: 7f53b12ddc748f8aa39d820af1a278b07d9cdcbafca0eef0392258352f3eacdf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 923ff077a975fd90c19daf1a186a1a334516dacb0351e89fb1094a13016b86068d21e0f3e5cabd52c70c72d5d3a3f58e97909dc6b299d3de2c0f950c394c4f5e
|
|
7
|
+
data.tar.gz: 73ed37232a4ac32ecf122f81df0e039bc8b9040f6812a343fa79f25e214a90d2255c41ae35c08c577590c2d5f458fa35e836624f7a50c9d82719fa185bdec007
|
data/README.md
CHANGED
|
@@ -170,6 +170,33 @@ 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.6
|
|
174
|
+
|
|
175
|
+
Nothing needs an edit. Fixed:
|
|
176
|
+
|
|
177
|
+
- **Focus returns to the pressed control in Safari.** Safari on a Mac doesn't focus a button or link on
|
|
178
|
+
click, so the browser had nothing to hand focus back to when a dialog closed and it fell to the page.
|
|
179
|
+
`registerDialog` now remembers what was pressed and returns focus there when closing leaves it nowhere.
|
|
180
|
+
- **`showContextDialog` opens through `showDialog`**, so a dialog anchored to a menu takes focus itself, as
|
|
181
|
+
every other dialog does, instead of ringing its first control. The confirm sheet no longer repeats the
|
|
182
|
+
step.
|
|
183
|
+
|
|
184
|
+
## Changes in 0.14.5
|
|
185
|
+
|
|
186
|
+
One edit, only for a host that skips `base.css`:
|
|
187
|
+
|
|
188
|
+
- **The focus ring is drawn in one place, `lc-focus-ring`.** Fields and the emoji picker's search drew their
|
|
189
|
+
own copy as a box shadow, and a linked list row drew a third with a different offset. They now take the
|
|
190
|
+
shared ring: `base.css` applies it to whatever holds keyboard focus, and the list row applies the same
|
|
191
|
+
utility while its link has focus. A host with its own base styles gets its own focus style on fields; to
|
|
192
|
+
keep the library's, add `:is(input, textarea, select):focus-visible { @apply lc-focus-ring; }`.
|
|
193
|
+
|
|
194
|
+
Faster:
|
|
195
|
+
|
|
196
|
+
- **The emoji catalog loads when someone reaches for the picker** (pointer, touch or focus), not with every
|
|
197
|
+
page that has one. It is every emoji there is, about 900KB of markup; opening the picker waits for the
|
|
198
|
+
same request.
|
|
199
|
+
|
|
173
200
|
## Changes in 0.14.4
|
|
174
201
|
|
|
175
202
|
Nothing needs an edit. Focus behaves more like the platform:
|
|
@@ -1136,10 +1163,17 @@ Every interactive component works from the keyboard without extra code:
|
|
|
1136
1163
|
The focus ring follows how the person is moving. Focus that comes back from a closed dialog, sheet, menu
|
|
1137
1164
|
or popover shows its ring only after Tab or an arrow key moved focus; Escape, Enter in a field and typing
|
|
1138
1165
|
don't count, so a dialog opened with the mouse and closed with Escape leaves no ring on its button. A panel
|
|
1139
|
-
closed from inside, such as by choosing a menu item, returns focus to what opened it
|
|
1166
|
+
closed from inside, such as by choosing a menu item, returns focus to what opened it, and a dialog
|
|
1167
|
+
closed with nothing focused before it, as after a click in Safari, returns focus to the control that was
|
|
1168
|
+
pressed. A controller that
|
|
1140
1169
|
moves focus back itself calls `settleFocus()` from `lostcoords/ui/helpers/focus` afterwards for the same
|
|
1141
1170
|
rule. Hosts that skip `base.css` hide the ring on `[data-lc-focus-quiet]:focus-visible`.
|
|
1142
1171
|
|
|
1172
|
+
The ring itself is the `lc-focus-ring` utility: two units of `--ring` hugging the element's own radius.
|
|
1173
|
+
`base.css` draws it on every focusable element, so a component never restates an outline. One whose ring
|
|
1174
|
+
belongs on another element applies the utility through a variant, as a linked list row does with
|
|
1175
|
+
`has-[[data-slot=list-link]:focus-visible]:lc-focus-ring`.
|
|
1176
|
+
|
|
1143
1177
|
Page-wide shortcuts focus a field or press a button. Merge `lc_shortcut_data` into the element's data and
|
|
1144
1178
|
show the keys with `lc_kbd`:
|
|
1145
1179
|
|
|
@@ -28,8 +28,7 @@
|
|
|
28
28
|
on the keyboard (helpers/focus). */
|
|
29
29
|
:is(a, button, input, textarea, select, summary, [tabindex]:not(dialog)):focus-visible:not([data-lc-focus-quiet]),
|
|
30
30
|
label:has(input.sr-only:focus-visible, + input.sr-only:focus-visible) {
|
|
31
|
-
|
|
32
|
-
outline-offset: 0;
|
|
31
|
+
@apply lc-focus-ring;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
dialog:focus-visible, [data-lc-focus-quiet]:focus-visible { outline: none; }
|
|
@@ -172,11 +172,6 @@
|
|
|
172
172
|
-webkit-appearance: none;
|
|
173
173
|
appearance: none;
|
|
174
174
|
}
|
|
175
|
-
|
|
176
|
-
&:focus {
|
|
177
|
-
outline: none;
|
|
178
|
-
box-shadow: 0 0 0 calc(var(--spacing) * 0.5) var(--ring, color-mix(in oklab, var(--primary) 50%, transparent));
|
|
179
|
-
}
|
|
180
175
|
}
|
|
181
176
|
|
|
182
177
|
/* ---- Skin-tone control ------------------------------------------- */
|
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
@custom-variant lc-disabled (&:disabled:not([aria-busy="true"]));
|
|
6
6
|
@custom-variant lc-pending (&:disabled[aria-busy="true"]);
|
|
7
7
|
|
|
8
|
+
/* The focus ring, drawn here and nowhere else. base.css puts it on whatever holds keyboard
|
|
9
|
+
focus; a component whose ring belongs on another element, such as a row around its link,
|
|
10
|
+
applies it through a variant. */
|
|
11
|
+
@utility lc-focus-ring {
|
|
12
|
+
outline: calc(var(--spacing) * 0.5) solid var(--ring, color-mix(in oklab, var(--primary) 50%, transparent));
|
|
13
|
+
outline-offset: 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
/* A control gives a little as it is pressed, unless it is disabled. */
|
|
9
17
|
@utility lc-press {
|
|
10
18
|
@media (prefers-reduced-motion: no-preference) {
|
|
@@ -36,9 +36,8 @@ module Lostcoords::Ui
|
|
|
36
36
|
"w-full max-w-full min-w-0 " \
|
|
37
37
|
"px-3 " \
|
|
38
38
|
"font-sans text-base bg-(--lc-field-bg,var(--input)) text-foreground placeholder:text-muted-foreground " \
|
|
39
|
-
"border border-transparent rounded-xl lc-squircle
|
|
39
|
+
"border border-transparent rounded-xl lc-squircle " \
|
|
40
40
|
"transition-[border-color,box-shadow] duration-(--lc-motion-quick) ease-(--lc-ease-out) " \
|
|
41
|
-
"focus:shadow-[0_0_0_calc(var(--spacing)*0.5)_var(--ring,color-mix(in_oklab,var(--primary)_50%,transparent))] " \
|
|
42
41
|
"aria-invalid:border-destructive aria-invalid:shadow-[0_0_0_3px_color-mix(in_oklab,var(--destructive)_16%,transparent)]"
|
|
43
42
|
|
|
44
43
|
# Text and nothing else: for a control inside a row that shows focus itself, such as lc_list_field.
|
|
@@ -14,8 +14,7 @@ module Lostcoords::Ui
|
|
|
14
14
|
# A linked li or div row: the title's link covers the row, the row's own controls sit above it,
|
|
15
15
|
# and the row shows the link's focus ring.
|
|
16
16
|
LIST_ROW_LINKED =
|
|
17
|
-
"relative has-[[data-slot=list-link]:focus-visible]:
|
|
18
|
-
"has-[[data-slot=list-link]:focus-visible]:outline-(--ring,color-mix(in_oklab,var(--primary)_50%,transparent)) " \
|
|
17
|
+
"relative has-[[data-slot=list-link]:focus-visible]:lc-focus-ring " \
|
|
19
18
|
"[&_:is(a[href],button,input,select,textarea,summary,[tabindex]):not([data-slot=list-link])]:relative " \
|
|
20
19
|
"[&_:is(a[href],button,input,select,textarea,summary,[tabindex]):not([data-slot=list-link])]:z-raised"
|
|
21
20
|
LIST_LINK = "text-inherit no-underline focus-visible:outline-none after:absolute after:inset-0 after:rounded-[inherit] after:content-['']"
|
|
@@ -7,6 +7,7 @@ import { prefersReducedMotion } from "lostcoords/ui/helpers/viewport"
|
|
|
7
7
|
|
|
8
8
|
const TONE_MODIFIERS = ["", "\u{1F3FB}", "\u{1F3FC}", "\u{1F3FD}", "\u{1F3FE}", "\u{1F3FF}"]
|
|
9
9
|
const TONE_STORAGE_KEY = "lostcoords_ui:lc-emoji-picker:tone"
|
|
10
|
+
const REACH = ["pointerenter", "touchstart", "focusin"]
|
|
10
11
|
|
|
11
12
|
function markCurrent(element, current) {
|
|
12
13
|
element.setAttribute("aria-current", String(current))
|
|
@@ -36,10 +37,15 @@ export default class extends CatalogPicker {
|
|
|
36
37
|
super.connect()
|
|
37
38
|
this.tone = this.readTone()
|
|
38
39
|
this.syncTones()
|
|
39
|
-
|
|
40
|
+
// The catalog is every emoji there is. It loads once someone reaches for the picker, not
|
|
41
|
+
// with each page that has one: opening it waits for the same request.
|
|
42
|
+
this.reach = () => this.fetchCatalog()
|
|
43
|
+
for (const type of REACH)
|
|
44
|
+
this.element.addEventListener(type, this.reach, { once: true, passive: true })
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
disconnect() {
|
|
48
|
+
for (const type of REACH) this.element.removeEventListener(type, this.reach)
|
|
43
49
|
this.unregisterTones?.()
|
|
44
50
|
this.clearPopover()
|
|
45
51
|
super.disconnect()
|
|
@@ -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,10 +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
|
|
69
|
+
// By now the browser has handed focus back to what had it before the dialog opened, if
|
|
70
|
+
// anything had.
|
|
68
71
|
const unregisterOnClose = () => {
|
|
69
72
|
if (dialog.open) return
|
|
70
73
|
unregister()
|
|
74
|
+
returnFocus(opener, dialog)
|
|
71
75
|
settleFocus()
|
|
72
76
|
}
|
|
73
77
|
const 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.
|