lostcoords-ui 0.14.2 → 0.14.4
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 +30 -0
- data/app/assets/tailwind/lostcoords/ui/base.css +4 -2
- data/app/assets/tailwind/lostcoords/ui/choice.css +1 -1
- data/app/assets/tailwind/lostcoords/ui/emoji-picker.css +1 -1
- data/app/assets/tailwind/lostcoords/ui/theme.css +4 -0
- data/app/javascript/lostcoords/ui/controllers/lc_emoji_picker_controller.js +5 -1
- data/app/javascript/lostcoords/ui/controllers/lc_search_controller.js +2 -0
- data/app/javascript/lostcoords/ui/helpers/dialog.js +5 -1
- data/app/javascript/lostcoords/ui/helpers/dismiss_stack.js +3 -0
- data/app/javascript/lostcoords/ui/helpers/floating_panel.js +9 -0
- data/app/javascript/lostcoords/ui/helpers/focus.js +39 -0
- data/lib/lostcoords/ui/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bc2680ff811f6c0d51e586c45ddbc29aaee4783bc56e3eda656cd90938013102
|
|
4
|
+
data.tar.gz: bde23f13ab360332b7ab58f7019d860ddaaa041031142dbcb39adb14b5a6a91f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e7675f0f64ea64f171c155856e542199c2b60eefc11f9e5e4ed71f448424316a8d340ac379f4c7143352042bcd96d719a8b89a1339ddee8ad2d9a813a1236a0f
|
|
7
|
+
data.tar.gz: e53e9eb35f0bafa7711431bd48cfb3973cc5064c2a6a1bbd74be31d4c6e6ef0d15247f0d926f4fd400ffa3d9b13499417a38872f5ff307ef11c548e147591a79
|
data/README.md
CHANGED
|
@@ -170,6 +170,29 @@ 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.4
|
|
174
|
+
|
|
175
|
+
Nothing needs an edit. Focus behaves more like the platform:
|
|
176
|
+
|
|
177
|
+
- **Returned focus shows its ring only for keyboard users.** Browsers ring whatever is focused after a key
|
|
178
|
+
press, and Escape, Enter in a field and typing are key presses, so a dialog opened with the mouse and
|
|
179
|
+
closed with Escape left a ring on its button. Focus that comes back from a closed dialog, sheet, menu,
|
|
180
|
+
popover or search now shows the ring only after Tab or an arrow key moved focus. A controller that moves
|
|
181
|
+
focus back itself calls the new **`settleFocus()`** from `lostcoords/ui/helpers/focus`.
|
|
182
|
+
- **A panel closed from inside returns focus to what opened it.** Choosing a menu item or an emoji left
|
|
183
|
+
focus on a hidden element, so it fell to the page.
|
|
184
|
+
- **The emoji picker's search halo reads `--ring`** like every other field, not a `--focus-halo` variable
|
|
185
|
+
the library never defined.
|
|
186
|
+
|
|
187
|
+
## Changes in 0.14.3
|
|
188
|
+
|
|
189
|
+
Nothing needs an edit, and one look changes:
|
|
190
|
+
|
|
191
|
+
- **An unchecked switch has a visible track on any surface.** It drew its track with `--input`, so on a host
|
|
192
|
+
whose cards share the field fill it showed only its thumb. The track is now `--lc-switch-track`, a
|
|
193
|
+
translucent foreground tint that shows on the page, a card or any other fill, in both themes. Set it to
|
|
194
|
+
restyle the track; checked switches still fill with `--primary`.
|
|
195
|
+
|
|
173
196
|
## Changes in 0.14.2
|
|
174
197
|
|
|
175
198
|
Nothing needs an edit unless you override the disabled look, and one look changes:
|
|
@@ -1110,6 +1133,13 @@ Every interactive component works from the keyboard without extra code:
|
|
|
1110
1133
|
| Emoji picker | Arrow Down from the search enters the grid, arrows move through it by row, Arrow Up from the top row returns to the search, and Enter in the search picks the best match. The grid is one Tab stop. |
|
|
1111
1134
|
| Dialogs, sheets, popovers, menus, tooltips | Escape closes the topmost one and returns focus to what opened it; an open tooltip closes before the menu or dialog around it. Escape in a search field with text clears it first. |
|
|
1112
1135
|
|
|
1136
|
+
The focus ring follows how the person is moving. Focus that comes back from a closed dialog, sheet, menu
|
|
1137
|
+
or popover shows its ring only after Tab or an arrow key moved focus; Escape, Enter in a field and typing
|
|
1138
|
+
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. A controller that
|
|
1140
|
+
moves focus back itself calls `settleFocus()` from `lostcoords/ui/helpers/focus` afterwards for the same
|
|
1141
|
+
rule. Hosts that skip `base.css` hide the ring on `[data-lc-focus-quiet]:focus-visible`.
|
|
1142
|
+
|
|
1113
1143
|
Page-wide shortcuts focus a field or press a button. Merge `lc_shortcut_data` into the element's data and
|
|
1114
1144
|
show the keys with `lc_kbd`:
|
|
1115
1145
|
|
|
@@ -24,13 +24,15 @@
|
|
|
24
24
|
|
|
25
25
|
:where([popover]) { color: inherit; }
|
|
26
26
|
|
|
27
|
-
:
|
|
27
|
+
/* data-lc-focus-quiet: focus handed back by a closed dialog or panel while the person is not
|
|
28
|
+
on the keyboard (helpers/focus). */
|
|
29
|
+
:is(a, button, input, textarea, select, summary, [tabindex]:not(dialog)):focus-visible:not([data-lc-focus-quiet]),
|
|
28
30
|
label:has(input.sr-only:focus-visible, + input.sr-only:focus-visible) {
|
|
29
31
|
outline: calc(var(--spacing) * 0.5) solid var(--ring, color-mix(in oklab, var(--primary) 50%, transparent));
|
|
30
32
|
outline-offset: 0;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
dialog:focus-visible { outline: none; }
|
|
35
|
+
dialog:focus-visible, [data-lc-focus-quiet]:focus-visible { outline: none; }
|
|
34
36
|
|
|
35
37
|
:where(code):not(:where(pre code)) {
|
|
36
38
|
@apply lc-inline-code;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
inline-size: calc(var(--spacing) * 9);
|
|
9
9
|
block-size: calc(var(--spacing) * 5.5);
|
|
10
10
|
border-radius: var(--radius-pill);
|
|
11
|
-
background-color: var(--
|
|
11
|
+
background-color: var(--lc-switch-track);
|
|
12
12
|
background-image: radial-gradient(circle closest-side, var(--lc-switch-thumb) calc(100% - var(--spacing) * 0.375), transparent 100%);
|
|
13
13
|
background-size: calc(var(--spacing) * 5.5) calc(var(--spacing) * 5.5);
|
|
14
14
|
background-repeat: no-repeat;
|
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
|
|
176
176
|
&:focus {
|
|
177
177
|
outline: none;
|
|
178
|
-
box-shadow: var(--
|
|
178
|
+
box-shadow: 0 0 0 calc(var(--spacing) * 0.5) var(--ring, color-mix(in oklab, var(--primary) 50%, transparent));
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
|
|
@@ -204,6 +204,10 @@
|
|
|
204
204
|
--lc-scrim-veil: color-mix(in oklab, var(--background) 35%, transparent);
|
|
205
205
|
--lc-input-hover: color-mix(in oklab, var(--foreground) 13%, var(--accent));
|
|
206
206
|
|
|
207
|
+
/* The unchecked switch track is a translucent tint, not a fill, so it shows on the page,
|
|
208
|
+
a card or any host surface, even one that matches --input. */
|
|
209
|
+
--lc-switch-track: color-mix(in oklab, var(--foreground) 20%, transparent);
|
|
210
|
+
|
|
207
211
|
--lc-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.05);
|
|
208
212
|
--lc-shadow:
|
|
209
213
|
0 1px 3px rgb(0 0 0 / 0.05),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CatalogPicker } from "lostcoords/ui/helpers/catalog_picker"
|
|
2
2
|
import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
|
|
3
|
+
import { settleFocus } from "lostcoords/ui/helpers/focus"
|
|
3
4
|
import { menuItems, navigateMenu } from "lostcoords/ui/helpers/menu_keys"
|
|
4
5
|
import { navigate } from "lostcoords/ui/helpers/roving_focus"
|
|
5
6
|
import { prefersReducedMotion } from "lostcoords/ui/helpers/viewport"
|
|
@@ -202,7 +203,10 @@ export default class extends CatalogPicker {
|
|
|
202
203
|
this.unregisterTones = null
|
|
203
204
|
const hadFocus = this.toneMenuTarget.contains(document.activeElement)
|
|
204
205
|
this.toneMenuTarget.hidden = true
|
|
205
|
-
if (hadFocus)
|
|
206
|
+
if (hadFocus) {
|
|
207
|
+
this.toneToggleTarget.focus({ preventScroll: true })
|
|
208
|
+
settleFocus()
|
|
209
|
+
}
|
|
206
210
|
this.toneToggleTarget.setAttribute("aria-expanded", "false")
|
|
207
211
|
}
|
|
208
212
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Controller } from "@hotwired/stimulus"
|
|
2
2
|
import { registerDialog } from "lostcoords/ui/helpers/dialog"
|
|
3
|
+
import { settleFocus } from "lostcoords/ui/helpers/focus"
|
|
3
4
|
import { prefersReducedMotion } from "lostcoords/ui/helpers/viewport"
|
|
4
5
|
|
|
5
6
|
// Full-screen search. Each query dispatches lc-search:query with { query, results }; a listener
|
|
@@ -85,6 +86,7 @@ export default class extends Controller {
|
|
|
85
86
|
this.reset()
|
|
86
87
|
this.returnFocus?.focus({ preventScroll: true })
|
|
87
88
|
this.returnFocus = null
|
|
89
|
+
settleFocus()
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
// A click on the backdrop closes search, and so does choosing a result, which matters for
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
|
|
2
|
+
import { settleFocus } from "lostcoords/ui/helpers/focus"
|
|
2
3
|
|
|
3
4
|
const registrations = new WeakMap()
|
|
4
5
|
|
|
@@ -63,8 +64,11 @@ export function registerDialog(
|
|
|
63
64
|
if (!inside) close(event)
|
|
64
65
|
}
|
|
65
66
|
// 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.
|
|
66
68
|
const unregisterOnClose = () => {
|
|
67
|
-
if (
|
|
69
|
+
if (dialog.open) return
|
|
70
|
+
unregister()
|
|
71
|
+
settleFocus()
|
|
68
72
|
}
|
|
69
73
|
const unregister = () => {
|
|
70
74
|
if (registrations.get(dialog) !== unregister) return
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { settleFocus } from "lostcoords/ui/helpers/focus"
|
|
2
|
+
|
|
1
3
|
const stack = []
|
|
2
4
|
let nextOrder = 0
|
|
3
5
|
let lockedScrollY = 0
|
|
@@ -83,6 +85,7 @@ function closeEntry(entry, event) {
|
|
|
83
85
|
if (closed === false) return
|
|
84
86
|
|
|
85
87
|
entry.restoreFocus?.()
|
|
88
|
+
settleFocus()
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
function topDismissable(scope = topModal()?.element) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Controller } from "@hotwired/stimulus"
|
|
2
2
|
import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
|
|
3
|
+
import { settleFocus } from "lostcoords/ui/helpers/focus"
|
|
3
4
|
import { liftToTopLayer, onPageLeave } from "lostcoords/ui/helpers/top_layer"
|
|
4
5
|
|
|
5
6
|
const BEFORE_OPEN = "overlay:before-open"
|
|
@@ -73,10 +74,18 @@ export class FloatingPanel extends Controller {
|
|
|
73
74
|
|
|
74
75
|
closeNow({ immediate = false } = {}) {
|
|
75
76
|
const wasOpen = this.isOpen
|
|
77
|
+
// Focus left on a hidden item would fall to the body: a panel closed from inside, such as by
|
|
78
|
+
// choosing a menu item, hands focus back to what opened it.
|
|
79
|
+
const heldFocus = wasOpen && !immediate && this.popoverTarget.contains(document.activeElement)
|
|
76
80
|
if (wasOpen) this.hide()
|
|
77
81
|
this.release({ immediate })
|
|
78
82
|
if (!wasOpen) return
|
|
79
83
|
|
|
84
|
+
if (heldFocus) {
|
|
85
|
+
this.focusOnClose?.focus({ preventScroll: true })
|
|
86
|
+
settleFocus()
|
|
87
|
+
}
|
|
88
|
+
|
|
80
89
|
if (this.hasTriggerTarget) this.triggerTarget.setAttribute("aria-expanded", "false")
|
|
81
90
|
this.afterClose()
|
|
82
91
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isEditable } from "lostcoords/ui/helpers/roving_focus"
|
|
2
|
+
|
|
3
|
+
// Browsers show the focus ring on anything focused after a key press, and Escape, Enter in a
|
|
4
|
+
// field and typing are key presses: a dialog opened with the mouse and closed with Escape hands
|
|
5
|
+
// focus back to its opener with a ring nobody asked for. Only moving focus by key counts here.
|
|
6
|
+
const MOVES = new Set(["Tab", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End"])
|
|
7
|
+
const QUIET = "data-lc-focus-quiet"
|
|
8
|
+
let byKeyboard = false
|
|
9
|
+
|
|
10
|
+
document.addEventListener(
|
|
11
|
+
"keydown",
|
|
12
|
+
(event) => {
|
|
13
|
+
if (event.key === "Tab" || (MOVES.has(event.key) && !isEditable(event.target)))
|
|
14
|
+
byKeyboard = true
|
|
15
|
+
},
|
|
16
|
+
true,
|
|
17
|
+
)
|
|
18
|
+
document.addEventListener(
|
|
19
|
+
"pointerdown",
|
|
20
|
+
() => {
|
|
21
|
+
byKeyboard = false
|
|
22
|
+
},
|
|
23
|
+
true,
|
|
24
|
+
)
|
|
25
|
+
// A same-URL refresh morphs the page against server HTML, which never carries the mark.
|
|
26
|
+
document.addEventListener("turbo:before-morph-attribute", (event) => {
|
|
27
|
+
if (event.detail.attributeName === QUIET) event.preventDefault()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// Call after focus has come back from a closed dialog, menu or panel. Unless the person is moving
|
|
31
|
+
// focus by keyboard, the element that has it keeps it without the ring until focus moves on.
|
|
32
|
+
// A text field always shows its ring, as it does on a click.
|
|
33
|
+
export function settleFocus() {
|
|
34
|
+
const element = document.activeElement
|
|
35
|
+
if (byKeyboard || !element || element === document.body || isEditable(element)) return
|
|
36
|
+
|
|
37
|
+
element.setAttribute(QUIET, "")
|
|
38
|
+
element.addEventListener("blur", () => element.removeAttribute(QUIET), { once: true })
|
|
39
|
+
}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lostcoords-ui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.14.
|
|
4
|
+
version: 0.14.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lost Coordinates
|
|
@@ -192,6 +192,7 @@ files:
|
|
|
192
192
|
- app/javascript/lostcoords/ui/helpers/dialog.js
|
|
193
193
|
- app/javascript/lostcoords/ui/helpers/dismiss_stack.js
|
|
194
194
|
- app/javascript/lostcoords/ui/helpers/floating_panel.js
|
|
195
|
+
- app/javascript/lostcoords/ui/helpers/focus.js
|
|
195
196
|
- app/javascript/lostcoords/ui/helpers/menu_keys.js
|
|
196
197
|
- app/javascript/lostcoords/ui/helpers/roving_focus.js
|
|
197
198
|
- app/javascript/lostcoords/ui/helpers/sheet_motion.js
|