phlex_kit 0.14.0 → 0.14.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 +4 -4
- data/app/components/phlex_kit/context_menu/context_menu_controller.js +15 -1
- data/app/components/phlex_kit/dropdown_menu/dropdown_menu_controller.js +15 -1
- data/app/components/phlex_kit/menubar/menubar_controller.js +17 -1
- data/app/components/phlex_kit/popover/popover_content.rb +8 -1
- data/app/components/phlex_kit/popover/popover_controller.js +4 -0
- data/app/components/phlex_kit/radio_button/radio_button.css +16 -0
- data/app/components/phlex_kit/select/select.rb +1 -1
- data/app/components/phlex_kit/select/select_controller.js +32 -0
- data/app/components/phlex_kit/table/table_head.rb +6 -1
- data/app/components/phlex_kit/toggle_group/toggle_group.rb +1 -0
- data/app/components/phlex_kit/toggle_group/toggle_group_controller.js +6 -1
- data/lib/phlex_kit/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: cc498540064c2a8e95dbe9b86dad991b2decb5dbd36c58f8ea8c39dce04fd146
|
|
4
|
+
data.tar.gz: 4b04765fe0ef28d0562542546df1d841fe2a9bd0a6df3cde2c344a5f80902d98
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f94e22d2a6537aae8571df45dea339fe6f03c2ed64b084223ee9359240f4032c85c1ce2132b63321e9d334b99cd9e0619babe7ec390937446913759434ae2a6c
|
|
7
|
+
data.tar.gz: e8a31936f3a6bd52fa30b61f3faf36e0ac8845ad78fd5c10624a021f3c0c6e6e99124eab540e42e0a0fd0dbe99bb4e6e2e2845c978939f646755a92e0576e30e
|
|
@@ -164,7 +164,7 @@ export default class extends Controller {
|
|
|
164
164
|
// trigger still counts). Escape stays global while the menu is open (APG).
|
|
165
165
|
if (e.key !== "Escape" && !this.element.contains(document.activeElement)) return
|
|
166
166
|
|
|
167
|
-
const items = this.
|
|
167
|
+
const items = this.rovingItems()
|
|
168
168
|
const index = items.indexOf(document.activeElement)
|
|
169
169
|
switch (e.key) {
|
|
170
170
|
case "Escape":
|
|
@@ -254,4 +254,18 @@ export default class extends Controller {
|
|
|
254
254
|
(el) => !el.closest("[data-disabled]") && el.getClientRects().length > 0
|
|
255
255
|
)
|
|
256
256
|
}
|
|
257
|
+
|
|
258
|
+
// The list ArrowUp/Down/Home/End rove — level-aware. A submenu reveals on
|
|
259
|
+
// :focus-within, so focusing a sub-trigger makes its rows visible and
|
|
260
|
+
// items() would pick them up; roving would then dive into the submenu on
|
|
261
|
+
// ArrowDown instead of moving to the next PARENT item (APG reserves
|
|
262
|
+
// ArrowRight/enterKey for entering). When focus is inside a sub panel, rove
|
|
263
|
+
// that panel's own rows; otherwise rove the top-level rows, excluding any
|
|
264
|
+
// sub-content the reveal exposed. Mirrored in menubar/dropdown (shared model).
|
|
265
|
+
rovingItems() {
|
|
266
|
+
const rows = this.items()
|
|
267
|
+
const sub = document.activeElement?.closest(".pk-context-menu-sub-content")
|
|
268
|
+
if (sub) return rows.filter((el) => el.closest(".pk-context-menu-sub-content") === sub)
|
|
269
|
+
return rows.filter((el) => !el.closest(".pk-context-menu-sub-content"))
|
|
270
|
+
}
|
|
257
271
|
}
|
|
@@ -164,7 +164,7 @@ export default class extends Controller {
|
|
|
164
164
|
// while the menu is open (APG).
|
|
165
165
|
if (e.key !== "Escape" && !this.element.contains(document.activeElement)) return;
|
|
166
166
|
|
|
167
|
-
const items = this.#
|
|
167
|
+
const items = this.#rovingItems();
|
|
168
168
|
if (items.length === 0) return;
|
|
169
169
|
const index = items.indexOf(document.activeElement);
|
|
170
170
|
|
|
@@ -245,6 +245,20 @@ export default class extends Controller {
|
|
|
245
245
|
);
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
// The list ArrowUp/Down/Home/End rove — level-aware. A submenu reveals on
|
|
249
|
+
// :focus-within, so focusing a sub-trigger makes its rows visible and
|
|
250
|
+
// #items() would pick them up; roving would then dive into the submenu on
|
|
251
|
+
// ArrowDown instead of moving to the next PARENT item (APG reserves
|
|
252
|
+
// ArrowRight/enterKey for entering). When focus is inside a sub panel, rove
|
|
253
|
+
// that panel's own rows; otherwise rove the top-level rows, excluding any
|
|
254
|
+
// sub-content the reveal exposed. Mirrored in menubar/context (shared model).
|
|
255
|
+
#rovingItems() {
|
|
256
|
+
const rows = this.#items();
|
|
257
|
+
const sub = document.activeElement?.closest(".pk-dropdown-menu-sub-content");
|
|
258
|
+
if (sub) return rows.filter((el) => el.closest(".pk-dropdown-menu-sub-content") === sub);
|
|
259
|
+
return rows.filter((el) => !el.closest(".pk-dropdown-menu-sub-content"));
|
|
260
|
+
}
|
|
261
|
+
|
|
248
262
|
#addEventListeners() {
|
|
249
263
|
document.addEventListener("keydown", this.boundHandleKeydown);
|
|
250
264
|
}
|
|
@@ -210,7 +210,7 @@ export default class extends Controller {
|
|
|
210
210
|
}
|
|
211
211
|
return
|
|
212
212
|
}
|
|
213
|
-
const items = this.
|
|
213
|
+
const items = this.rovingItems()
|
|
214
214
|
const index = items.indexOf(document.activeElement)
|
|
215
215
|
switch (e.key) {
|
|
216
216
|
case "Escape":
|
|
@@ -333,6 +333,22 @@ export default class extends Controller {
|
|
|
333
333
|
return menu.querySelector("[role=\"menu\"], .pk-menubar-content, .pk-navigation-menu-content")
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
+
// The list ArrowUp/Down/Home/End rove — level-aware. A submenu reveals on
|
|
337
|
+
// :focus-within, so focusing a sub-trigger makes its rows visible and
|
|
338
|
+
// items() would pick them up; roving would then dive into the submenu on
|
|
339
|
+
// ArrowDown instead of moving to the next PARENT item (APG reserves
|
|
340
|
+
// ArrowRight/enterKey for entering). When focus is inside a sub panel, rove
|
|
341
|
+
// that panel's own rows; otherwise rove the top-level rows, excluding any
|
|
342
|
+
// sub-content the reveal exposed. Mirrored in dropdown/context (shared model).
|
|
343
|
+
rovingItems() {
|
|
344
|
+
const menu = this.openMenu
|
|
345
|
+
if (!menu) return []
|
|
346
|
+
const rows = this.items(menu)
|
|
347
|
+
const sub = document.activeElement?.closest(".pk-menubar-sub-content")
|
|
348
|
+
if (sub) return rows.filter((el) => el.closest(".pk-menubar-sub-content") === sub)
|
|
349
|
+
return rows.filter((el) => !el.closest(".pk-menubar-sub-content"))
|
|
350
|
+
}
|
|
351
|
+
|
|
336
352
|
items(menu) {
|
|
337
353
|
const panel = this.panel(menu)
|
|
338
354
|
if (!panel) return []
|
|
@@ -13,7 +13,14 @@ module PhlexKit
|
|
|
13
13
|
|
|
14
14
|
def view_template(&)
|
|
15
15
|
classes = [ "pk-popover-content", fetch_option(ALIGNS, @align, :align) ].compact.join(" ")
|
|
16
|
-
|
|
16
|
+
# `popover:` is a named default, not a merged attr: `mix` joins duplicate
|
|
17
|
+
# attrs (a caller's `popover: "manual"` would fuse into "auto manual",
|
|
18
|
+
# which the browser normalizes to manual — killing the native light
|
|
19
|
+
# dismiss/Escape this controller relies on). Skip the default when the
|
|
20
|
+
# caller sets it (mirrors MenubarContent).
|
|
21
|
+
base = { class: classes, data: { phlex_kit__popover_target: "content", state: "closed" } }
|
|
22
|
+
base[:popover] = "auto" unless attr_set?(:popover)
|
|
23
|
+
div(**mix(base, @attrs), &)
|
|
17
24
|
end
|
|
18
25
|
end
|
|
19
26
|
end
|
|
@@ -16,6 +16,10 @@ export default class extends Controller {
|
|
|
16
16
|
const invoker = this.triggerTarget.querySelector("button")
|
|
17
17
|
if (invoker) {
|
|
18
18
|
invoker.popoverTargetElement = this.contentTarget
|
|
19
|
+
// popoverTargetElement gives native aria-expanded but not haspopup —
|
|
20
|
+
// shadcn/Radix Popover.Trigger ships aria-haspopup="dialog", so add it
|
|
21
|
+
// (leave a caller-set value alone) to match the button-less path below.
|
|
22
|
+
if (!invoker.hasAttribute("aria-haspopup")) invoker.setAttribute("aria-haspopup", "dialog")
|
|
19
23
|
} else {
|
|
20
24
|
// Button-less fallback: keyboard toggling and popup semantics don't
|
|
21
25
|
// come for free like they do with popoverTargetElement — wire Enter
|
|
@@ -38,6 +38,22 @@
|
|
|
38
38
|
box-shadow: 0 0 0 3px color-mix(in oklab, var(--pk-red) 40%, transparent);
|
|
39
39
|
}
|
|
40
40
|
.pk-radio[aria-invalid="true"]:checked { border-color: var(--pk-brand); }
|
|
41
|
+
/* Invalid + keyboard focus: the always-on invalid ring above would otherwise
|
|
42
|
+
swallow the equal-specificity :focus-visible rule, leaving no visible focus
|
|
43
|
+
change (and the theme-scoped invalid arms below beat it outright in light).
|
|
44
|
+
Keep the red border (invalid stays legible) but switch the ring to the
|
|
45
|
+
standard focus color — mirrors checkbox.css. */
|
|
46
|
+
.pk-radio[aria-invalid="true"]:focus-visible,
|
|
47
|
+
:root[data-theme="light"] .pk-radio[aria-invalid="true"]:focus-visible {
|
|
48
|
+
border-color: var(--pk-red);
|
|
49
|
+
box-shadow: 0 0 0 3px color-mix(in oklab, var(--pk-ring) 50%, transparent);
|
|
50
|
+
}
|
|
51
|
+
@media (prefers-color-scheme: light) {
|
|
52
|
+
:root[data-theme="system"] .pk-radio[aria-invalid="true"]:focus-visible {
|
|
53
|
+
border-color: var(--pk-red);
|
|
54
|
+
box-shadow: 0 0 0 3px color-mix(in oklab, var(--pk-ring) 50%, transparent);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
41
57
|
.pk-radio:disabled { cursor: not-allowed; opacity: .5; }
|
|
42
58
|
:root[data-theme="light"] .pk-radio:not(:checked) { background: transparent; }
|
|
43
59
|
:root[data-theme="light"] .pk-radio[aria-invalid="true"] {
|
|
@@ -39,7 +39,7 @@ module PhlexKit
|
|
|
39
39
|
# keydown.esc rides on the root (not only the items) so Escape closes
|
|
40
40
|
# the [popover=manual] panel with focus on the trigger too; handleEsc
|
|
41
41
|
# no-ops while closed.
|
|
42
|
-
action: "click@window->phlex-kit--select#clickOutside keydown.esc->phlex-kit--select#handleEsc focusout->phlex-kit--select#onFocusout"
|
|
42
|
+
action: "mousedown@window->phlex-kit--select#onMousedownOutside click@window->phlex-kit--select#clickOutside keydown.esc->phlex-kit--select#handleEsc focusout->phlex-kit--select#onFocusout"
|
|
43
43
|
}
|
|
44
44
|
}, @attrs), &block)
|
|
45
45
|
end
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { Controller } from "@hotwired/stimulus";
|
|
2
2
|
|
|
3
|
+
// One-shot capture listener swallowing the click an outside mousedown is about
|
|
4
|
+
// to produce (see onMousedownOutside; same helper in dropdown/context/menubar
|
|
5
|
+
// — duplicated per controller by design). Select is a MODAL menu: the
|
|
6
|
+
// dismissing outside click ONLY dismisses, never also acts on what sits under
|
|
7
|
+
// the pointer. Armed at MOUSEDOWN because for a focusable click target the same
|
|
8
|
+
// gesture's focusout closes the panel before the click fires (a click-time
|
|
9
|
+
// check would already see it closed and skip the swallow — audit round 8).
|
|
10
|
+
const swallowClick = (ev) => {
|
|
11
|
+
ev.preventDefault();
|
|
12
|
+
ev.stopPropagation();
|
|
13
|
+
};
|
|
14
|
+
function armSwallowClick() {
|
|
15
|
+
window.addEventListener("click", swallowClick, { once: true, capture: true });
|
|
16
|
+
}
|
|
17
|
+
|
|
3
18
|
// Ported from ruby_ui's phlex-kit--select controller, minus the
|
|
4
19
|
// @floating-ui/dom dependency: the panel is a native [popover=manual] in the
|
|
5
20
|
// top layer, anchor-positioned with viewport-edge flipping by select.css
|
|
@@ -53,6 +68,12 @@ export default class extends Controller {
|
|
|
53
68
|
const newValue = item.dataset.value;
|
|
54
69
|
|
|
55
70
|
this.inputTarget.value = newValue;
|
|
71
|
+
// Also set the value ATTRIBUTE, not just the .value property: a Turbo
|
|
72
|
+
// snapshot restore clones the DOM (dropping the dirty property) and would
|
|
73
|
+
// otherwise revert the hidden input to its server value while the label
|
|
74
|
+
// and aria-selected still show the chosen item — submitting the wrong
|
|
75
|
+
// value behind a correct-looking UI. (re-derive-from-live-truth rule.)
|
|
76
|
+
this.inputTarget.setAttribute("value", newValue);
|
|
56
77
|
this.valueTarget.innerText = item.innerText;
|
|
57
78
|
|
|
58
79
|
this.dispatchOnChange(oldValue, newValue);
|
|
@@ -162,6 +183,17 @@ export default class extends Controller {
|
|
|
162
183
|
this.itemTargets.forEach((item) => item.removeAttribute("aria-current"));
|
|
163
184
|
}
|
|
164
185
|
|
|
186
|
+
// Modal dismiss: arm the swallow at mousedown so the outside click that
|
|
187
|
+
// dismisses an open select doesn't ALSO activate a focusable control under
|
|
188
|
+
// the pointer (the same gesture's focusout closes the panel before the
|
|
189
|
+
// click, so clickOutside below would already see it closed). Mirrors
|
|
190
|
+
// dropdown/context/menubar.
|
|
191
|
+
onMousedownOutside(event) {
|
|
192
|
+
if (!this.contentTarget.matches(":popover-open")) return;
|
|
193
|
+
if (this.element.contains(event.target)) return;
|
|
194
|
+
armSwallowClick();
|
|
195
|
+
}
|
|
196
|
+
|
|
165
197
|
clickOutside(event) {
|
|
166
198
|
if (!this.contentTarget.matches(":popover-open")) return;
|
|
167
199
|
if (this.element.contains(event.target)) return;
|
|
@@ -6,7 +6,12 @@ module PhlexKit
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def view_template(&block)
|
|
9
|
-
|
|
9
|
+
# scope="col" is the common case (header cells sit in a TableHeader row);
|
|
10
|
+
# a generated default, not a merged attr — `mix` would fuse a caller's
|
|
11
|
+
# `scope: "row"` into "col row" — so skip it when the caller sets scope.
|
|
12
|
+
base = { class: "pk-table-head" }
|
|
13
|
+
base[:scope] = "col" unless attr_set?(:scope)
|
|
14
|
+
th(**mix(base, @attrs), &block)
|
|
10
15
|
end
|
|
11
16
|
end
|
|
12
17
|
end
|
|
@@ -88,6 +88,7 @@ module PhlexKit
|
|
|
88
88
|
data: { controller: "phlex-kit--toggle-group",
|
|
89
89
|
phlex_kit__toggle_group_type_value: @type.to_s,
|
|
90
90
|
phlex_kit__toggle_group_name_value: @name.to_s,
|
|
91
|
+
phlex_kit__toggle_group_disabled_value: @disabled.to_s,
|
|
91
92
|
orientation: @orientation.to_s, spacing: @spacing.to_s } }
|
|
92
93
|
# spacing: N gaps the items by N × .25rem (Tailwind-style scale) via the
|
|
93
94
|
# custom property toggle_group.css reads. Trailing ";" so a caller
|
|
@@ -3,7 +3,7 @@ import { Controller } from "@hotwired/stimulus"
|
|
|
3
3
|
// Connects to data-controller="phlex-kit--toggle-group"
|
|
4
4
|
export default class extends Controller {
|
|
5
5
|
static targets = ["item", "input"]
|
|
6
|
-
static values = { type: String, name: String }
|
|
6
|
+
static values = { type: String, name: String, disabled: Boolean }
|
|
7
7
|
|
|
8
8
|
connect() { this.reconcile() }
|
|
9
9
|
|
|
@@ -100,6 +100,11 @@ export default class extends Controller {
|
|
|
100
100
|
input.type = "hidden"
|
|
101
101
|
input.name = name
|
|
102
102
|
input.value = value
|
|
103
|
+
// A disabled group's hidden input is server-rendered `disabled` so it
|
|
104
|
+
// won't submit (toggle_group.rb). rebuildInputs() removes that server
|
|
105
|
+
// input and recreates it here on connect() — carry the disabled flag or
|
|
106
|
+
// the group would start submitting its value post-hydration.
|
|
107
|
+
if (this.disabledValue) input.disabled = true
|
|
103
108
|
input.setAttribute("data-phlex-kit--toggle-group-target", "input")
|
|
104
109
|
return input
|
|
105
110
|
}
|
data/lib/phlex_kit/version.rb
CHANGED