lostcoords-ui 0.12.0 → 0.12.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d40b25262f26a57dea7b82cada5df30d683de3fb28f2c9db0046130cfb26a26f
4
- data.tar.gz: 3c3b01b38a8d674bd8a59f068b6b5e7db92563cecd5d56bdeb43b08257373526
3
+ metadata.gz: 7f17b0b2708cbe55957972ef27eb37ada90b102c0e752d635c08feeffcb2a3e2
4
+ data.tar.gz: c1ce053ec741627c1973016a62663093ca06e3a990ea8f455f7c483ea81bd5ff
5
5
  SHA512:
6
- metadata.gz: d05b7df8c044fed6d94d2d8ff97caab7d9e589bdb2d218bf3d5a49bba27c5b7dbb7df2b7c4354e55947ef48025803167fc0d542892ce640bb50c0461efc175fb
7
- data.tar.gz: 9ccbd01d8a5171657cd56e71dd6537628efed50f75fb00445226abc96999559b58fd4ba415664c17ac4820e919908cc74a8dabf2ad8c53efef6b559e6736ef86
6
+ metadata.gz: '0709825a84cc4ec2b8367e2e71af48acf097bc29b6804d5da23e8833e707ad5bdc57439769240b970c76ab1eb013e55387fb546fe23cee73d63efd5252fdba64'
7
+ data.tar.gz: f975b43643f0f2f2aa975b24d6882b6c2b87dca5bf211d15d36fb11bac80d670db86289303812d3ed1aed4eee498c35ce7317a4c6fda76c9cc6bd8385936a339
data/README.md CHANGED
@@ -170,6 +170,21 @@ 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.1
174
+
175
+ Nothing needs an edit. Changed:
176
+
177
+ - **A dialog opens with focus on itself.** `lc-dialog` and the new **`showDialog(dialog)`** helper in
178
+ `lostcoords/ui/helpers/dialog` focus the dialog rather than its first control, so the close button no longer
179
+ shows the focus ring after a tap and a first field no longer raises the keyboard. A control marked
180
+ `autofocus` still takes focus.
181
+ - **The focus halo skips dialogs**, including ones with a `tabindex`.
182
+
183
+ New option:
184
+
185
+ - **`lc_section(header: :from_sm)` hides the heading row on phones**, for a section whose content explains
186
+ itself on a small screen, such as a balance card. Screen readers still get the heading; its actions are hidden.
187
+
173
188
  ## Changes in 0.12.0
174
189
 
175
190
  One edit, and some components look different:
@@ -914,10 +929,12 @@ the scroller's edges and clears the home indicator.
914
929
  <% end %>
915
930
  ```
916
931
 
917
- A controller that opens a `<dialog>` itself joins it to the dismiss stack with `registerDialog` from
918
- `lostcoords/ui/helpers/dialog`, so Escape, a backdrop click and a swipe close it, and the page stops scrolling
919
- behind it. `registerDialog(dialog, { close, priority, restoreFocus, lockScroll })`: `close` may return `false`
920
- to keep the dialog open, such as while it asks to discard changes; `priority` ranks it against panels open in
932
+ A controller that opens a `<dialog>` itself shows it with `showDialog(dialog)` and joins it to the dismiss
933
+ stack with `registerDialog`, both from `lostcoords/ui/helpers/dialog`. `showDialog` opens it modal with focus
934
+ on the dialog itself, so no focus ring lands on its close button and no keyboard rises for a first field; a
935
+ control marked `autofocus` still takes focus. With `registerDialog`, Escape, a backdrop click and a swipe close
936
+ it, and the page stops scrolling behind it.
937
+ `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
938
  it (a dialog is 10, a panel 20); `restoreFocus` runs after a close; `lockScroll: false` leaves the page
922
939
  scrollable. It returns the unregister function and ends when the dialog closes; a click on the dialog's own
923
940
  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
- def lc_section(title:, level: 2, actions: nil, anchor: false, **attributes, &block)
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
- header = lc_section_header { safe_join([ heading, action_content ].compact) }
94
- safe_join([ header, lc_stack(&block) ])
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
- if (!this.dialogTarget.open) this.dialogTarget.showModal()
19
+ showDialog(this.dialogTarget)
20
20
 
21
21
  this.unregisterDialog = registerDialog(this.dialogTarget)
22
22
  }
@@ -2,6 +2,17 @@ import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
2
2
 
3
3
  const registrations = new WeakMap()
4
4
 
5
+ // Shows a modal <dialog> with focus on the dialog itself rather than its first control: a close
6
+ // button would draw the focus ring after a tap that focused nothing, and a first field would raise
7
+ // a phone's keyboard. A control marked autofocus still takes focus, and Tab reaches every control.
8
+ export function showDialog(dialog) {
9
+ if (dialog.open) return
10
+ dialog.showModal()
11
+ if (dialog.querySelector("[autofocus]")) return
12
+ if (!dialog.hasAttribute("tabindex")) dialog.tabIndex = -1
13
+ dialog.focus({ preventScroll: true })
14
+ }
15
+
5
16
  // Joins a <dialog> to the dismiss stack: Escape, the backdrop and a swipe call close, which may
6
17
  // return false to keep it open, such as while it asks whether to discard changes. priority ranks
7
18
  // it against panels open in it (a dialog is 10, a panel 20); restoreFocus runs after a close;
@@ -1,5 +1,5 @@
1
1
  module Lostcoords
2
2
  module Ui
3
- VERSION = "0.12.0"
3
+ VERSION = "0.12.1"
4
4
  end
5
5
  end
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.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lost Coordinates