lostcoords-ui 0.12.0 → 0.12.2
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 -4
- data/app/assets/tailwind/lostcoords/ui/base.css +1 -1
- data/app/helpers/lostcoords/ui/layout_helper.rb +7 -3
- data/app/javascript/lostcoords/ui/controllers/lc_dialog_controller.js +2 -2
- data/app/javascript/lostcoords/ui/helpers/dialog.js +29 -0
- data/app/javascript/lostcoords/ui/helpers/dismiss_stack.js +12 -2
- 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: 8826e4a226e995babe0ca3b5c0b8acc0814e018e992e685d2792f73d499df817
|
|
4
|
+
data.tar.gz: 9b567d198b078a9dc9e07c4fcddc5ab8271febae59bc088c556e9bb2616f46b7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87f135447441e6fa94670fe213ae19c3e9e04d377c174aa9ce27df733b130dfbd8e1c92fd461d663fbbb8d3dfe957ce89d9b3752b9cacc17e9b1a7a501e8fb60
|
|
7
|
+
data.tar.gz: 720a4d496cb092ee008ec9d7580606804feb1f72d1b1086e5e7cbad0f972755b32df1d13d882a2ac3c470b7de855f9d2f36771314d58f1ee008538967675dfbf
|
data/README.md
CHANGED
|
@@ -170,6 +170,30 @@ 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.12.2
|
|
174
|
+
|
|
175
|
+
Nothing needs an edit. Fixed:
|
|
176
|
+
|
|
177
|
+
- **Back no longer brings a dialog back half open.** Turbo snapshots a page with its open dialogs, and
|
|
178
|
+
restoring one kept the `open` attribute without the top layer: no backdrop, focus trap or Escape, and the
|
|
179
|
+
page stayed pinned by the scroll lock. A dialog joined through `registerDialog` now comes back closed and
|
|
180
|
+
the page unpinned; a controller that reopens its dialog on connect shows it as a real modal again.
|
|
181
|
+
|
|
182
|
+
## Changes in 0.12.1
|
|
183
|
+
|
|
184
|
+
Nothing needs an edit. Changed:
|
|
185
|
+
|
|
186
|
+
- **A dialog opens with focus on itself.** `lc-dialog` and the new **`showDialog(dialog)`** helper in
|
|
187
|
+
`lostcoords/ui/helpers/dialog` focus the dialog rather than its first control, so the close button no longer
|
|
188
|
+
shows the focus ring after a tap and a first field no longer raises the keyboard. A control marked
|
|
189
|
+
`autofocus` still takes focus.
|
|
190
|
+
- **The focus halo skips dialogs**, including ones with a `tabindex`.
|
|
191
|
+
|
|
192
|
+
New option:
|
|
193
|
+
|
|
194
|
+
- **`lc_section(header: :from_sm)` hides the heading row on phones**, for a section whose content explains
|
|
195
|
+
itself on a small screen, such as a balance card. Screen readers still get the heading; its actions are hidden.
|
|
196
|
+
|
|
173
197
|
## Changes in 0.12.0
|
|
174
198
|
|
|
175
199
|
One edit, and some components look different:
|
|
@@ -914,10 +938,12 @@ the scroller's edges and clears the home indicator.
|
|
|
914
938
|
<% end %>
|
|
915
939
|
```
|
|
916
940
|
|
|
917
|
-
A controller that opens a `<dialog>` itself joins it to the dismiss
|
|
918
|
-
`lostcoords/ui/helpers/dialog
|
|
919
|
-
|
|
920
|
-
|
|
941
|
+
A controller that opens a `<dialog>` itself shows it with `showDialog(dialog)` and joins it to the dismiss
|
|
942
|
+
stack with `registerDialog`, both from `lostcoords/ui/helpers/dialog`. `showDialog` opens it modal with focus
|
|
943
|
+
on the dialog itself, so no focus ring lands on its close button and no keyboard rises for a first field; a
|
|
944
|
+
control marked `autofocus` still takes focus. With `registerDialog`, Escape, a backdrop click and a swipe close
|
|
945
|
+
it, and the page stops scrolling behind it.
|
|
946
|
+
`registerDialog(dialog, { close, priority, restoreFocus, lockScroll })`: `close` may return `false` to keep the dialog open, such as while it asks to discard changes; `priority` ranks it against panels open in
|
|
921
947
|
it (a dialog is 10, a panel 20); `restoreFocus` runs after a close; `lockScroll: false` leaves the page
|
|
922
948
|
scrollable. It returns the unregister function and ends when the dialog closes; a click on the dialog's own
|
|
923
949
|
padding does not close it.
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
:where([popover]) { color: inherit; }
|
|
26
26
|
|
|
27
|
-
:is(a, button, input, textarea, select, summary, [tabindex]):focus-visible,
|
|
27
|
+
:is(a, button, input, textarea, select, summary, [tabindex]:not(dialog)):focus-visible,
|
|
28
28
|
label:has(input.sr-only:focus-visible, + input.sr-only:focus-visible) {
|
|
29
29
|
outline: calc(var(--spacing) * 0.5) solid var(--ring, color-mix(in oklab, var(--primary) 50%, transparent));
|
|
30
30
|
outline-offset: 0;
|
|
@@ -83,15 +83,19 @@ module Lostcoords::Ui
|
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
# anchor: true links the heading to the section's id:, for pages readers link into.
|
|
86
|
-
|
|
86
|
+
# header: :from_sm shows the heading row from sm up, for content that explains itself on a phone. Below
|
|
87
|
+
# sm the heading stays for screen readers (sr-only also takes it out of the stack gap) and the actions go.
|
|
88
|
+
def lc_section(title:, level: 2, actions: nil, anchor: false, header: :visible, **attributes, &block)
|
|
87
89
|
raise ArgumentError, "title must not be blank" if title.blank?
|
|
88
90
|
raise ArgumentError, "anchor: true needs an id" if anchor && attributes[:id].blank?
|
|
89
91
|
|
|
90
92
|
tag.section(**lc_attributes({ class: lc_stack_class(gap: :heading, extra: ("lc-anchor-target" if anchor)) }, attributes)) do
|
|
91
93
|
heading = lc_heading(title, level: level, size: :heading, anchor: (attributes[:id] if anchor))
|
|
92
94
|
action_content = actions.respond_to?(:call) ? capture(&actions) : actions
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
from_sm = lc_option!(:header, header, %i[visible from_sm]) == :from_sm
|
|
96
|
+
action_content = tag.div(action_content, class: "contents max-sm:hidden") if from_sm && action_content.present?
|
|
97
|
+
header_row = lc_section_header(class: ("max-sm:sr-only" if from_sm)) { safe_join([ heading, action_content ].compact) }
|
|
98
|
+
safe_join([ header_row, lc_stack(&block) ])
|
|
95
99
|
end
|
|
96
100
|
end
|
|
97
101
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Controller } from "@hotwired/stimulus"
|
|
2
|
-
import { registerDialog } from "lostcoords/ui/helpers/dialog"
|
|
2
|
+
import { registerDialog, showDialog } from "lostcoords/ui/helpers/dialog"
|
|
3
3
|
|
|
4
4
|
// Opens a dialog whose body is a Turbo frame fetched on open. It reloads on every
|
|
5
5
|
// open, so what it shows is never staler than the page that opened it.
|
|
@@ -16,7 +16,7 @@ export default class extends Controller {
|
|
|
16
16
|
if (this.frameTarget.src) this.frameTarget.reload()
|
|
17
17
|
else this.frameTarget.src = this.frameTarget.dataset.src
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
showDialog(this.dialogTarget)
|
|
20
20
|
|
|
21
21
|
this.unregisterDialog = registerDialog(this.dialogTarget)
|
|
22
22
|
}
|
|
@@ -2,6 +2,33 @@ import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
|
|
|
2
2
|
|
|
3
3
|
const registrations = new WeakMap()
|
|
4
4
|
|
|
5
|
+
// Turbo snapshots a page for Back with its open dialogs, and restoring one brings back the open
|
|
6
|
+
// attribute but not the top layer: the dialog shows inline, with no backdrop, focus trap or
|
|
7
|
+
// Escape. A dialog registered when the snapshot was taken is marked, so it comes back closed.
|
|
8
|
+
const MARK = "lcDialog"
|
|
9
|
+
document.addEventListener("turbo:before-render", ({ detail: { newBody } }) => {
|
|
10
|
+
for (const dialog of newBody.querySelectorAll("dialog[data-lc-dialog]")) {
|
|
11
|
+
dialog.removeAttribute("open")
|
|
12
|
+
delete dialog.dataset[MARK]
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
// A same-URL refresh morphs the page against server HTML, which never carries the mark.
|
|
16
|
+
document.addEventListener("turbo:before-morph-attribute", (event) => {
|
|
17
|
+
if (event.detail.attributeName === "data-lc-dialog" && registrations.has(event.target))
|
|
18
|
+
event.preventDefault()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
// Shows a modal <dialog> with focus on the dialog itself rather than its first control: a close
|
|
22
|
+
// button would draw the focus ring after a tap that focused nothing, and a first field would raise
|
|
23
|
+
// a phone's keyboard. A control marked autofocus still takes focus, and Tab reaches every control.
|
|
24
|
+
export function showDialog(dialog) {
|
|
25
|
+
if (dialog.open) return
|
|
26
|
+
dialog.showModal()
|
|
27
|
+
if (dialog.querySelector("[autofocus]")) return
|
|
28
|
+
if (!dialog.hasAttribute("tabindex")) dialog.tabIndex = -1
|
|
29
|
+
dialog.focus({ preventScroll: true })
|
|
30
|
+
}
|
|
31
|
+
|
|
5
32
|
// Joins a <dialog> to the dismiss stack: Escape, the backdrop and a swipe call close, which may
|
|
6
33
|
// return false to keep it open, such as while it asks whether to discard changes. priority ranks
|
|
7
34
|
// it against panels open in it (a dialog is 10, a panel 20); restoreFocus runs after a close;
|
|
@@ -42,12 +69,14 @@ export function registerDialog(
|
|
|
42
69
|
const unregister = () => {
|
|
43
70
|
if (registrations.get(dialog) !== unregister) return
|
|
44
71
|
registrations.delete(dialog)
|
|
72
|
+
delete dialog.dataset[MARK]
|
|
45
73
|
dialog.removeEventListener("close", unregisterOnClose)
|
|
46
74
|
dialog.removeEventListener("click", closeOnBackdrop)
|
|
47
75
|
unregisterDismissable()
|
|
48
76
|
}
|
|
49
77
|
|
|
50
78
|
registrations.set(dialog, unregister)
|
|
79
|
+
dialog.dataset[MARK] = ""
|
|
51
80
|
dialog.addEventListener("close", unregisterOnClose)
|
|
52
81
|
dialog.addEventListener("click", closeOnBackdrop)
|
|
53
82
|
return unregister
|
|
@@ -167,12 +167,22 @@ function unlockDocumentScroll() {
|
|
|
167
167
|
const body = document.body
|
|
168
168
|
if (body?.dataset.modalScrollLock !== "true") return
|
|
169
169
|
|
|
170
|
+
releaseScrollLock(body)
|
|
171
|
+
window.scrollTo({ top: lockedScrollY, behavior: "instant" })
|
|
172
|
+
lockedScrollY = 0
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function releaseScrollLock(body) {
|
|
170
176
|
body.style.position = ""
|
|
171
177
|
body.style.inset = ""
|
|
172
178
|
body.style.top = ""
|
|
173
179
|
body.style.removeProperty("--lc-scroll-lock-y")
|
|
174
180
|
body.style.inlineSize = ""
|
|
175
181
|
delete body.dataset.modalScrollLock
|
|
176
|
-
window.scrollTo({ top: lockedScrollY, behavior: "instant" })
|
|
177
|
-
lockedScrollY = 0
|
|
178
182
|
}
|
|
183
|
+
|
|
184
|
+
// A page snapshotted for Back while a dialog held the lock comes back pinned; the dialog
|
|
185
|
+
// that held it comes back closed (helpers/dialog), so the restored page is free to scroll.
|
|
186
|
+
document.addEventListener("turbo:before-render", ({ detail: { newBody } }) => {
|
|
187
|
+
if (newBody.dataset.modalScrollLock === "true") releaseScrollLock(newBody)
|
|
188
|
+
})
|