layered-ui-rails 0.28.1 → 0.29.0

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: a104dd90d9d3788698cd380040b5cb994dd117d4e9977068cbe2dd329cbd9445
4
- data.tar.gz: aa10d890803555e8a66800b854cd88a2c05702b6dd2728bbd1f7dffa420e2798
3
+ metadata.gz: ed4e9ca784badbd812a499a3fd59ef85822db2e673261a9f34e06e7fe1b84cce
4
+ data.tar.gz: '028df125f458decf72fe406a678330350782aa3b5737cea75de12f4d3fb9defb'
5
5
  SHA512:
6
- metadata.gz: 6051277431bb1c307f38f284aaeb9c35330baf847a33c299cebcb0797fb998365d863ac7478152b656d0361a3b5f833475494c050e9a07c4995d568cfd74c5b7
7
- data.tar.gz: 51cd2b99a0bc22e7c27bb5a8d6b6e66a14304abbd979c89db6606a2c6e249784474213659c44182e06667bf988552dea36fd56a27cd05ab7b15149d55f9360cc
6
+ metadata.gz: 6033542830743b4e3990313fbc6d2e43af50ca0a804221e24339e701bb5a3281409bf50212ea7c1e93144a5a0158dabf5d88be0e45a40515b7e386c4a0a76fb6
7
+ data.tar.gz: 3ab6dee77700a6ee492a348d5b6e15210f291646c6eb0a252b1e9d822fb1e0c414da18c85848b69faf3d20a4b42c702bbd3499b19ba1fc2d2813a11a0b3ef236
@@ -150,6 +150,7 @@ Features:
150
150
  - Dragging is a pointer enhancement only, advertised by a decorative grip handle - the move buttons are the accessible path, as WCAG 2.2 SC 2.5.7 requires
151
151
  - Selections, filter counts, and moves are announced through a local `role="status"` region
152
152
  - With `url` set, each keystroke schedules a debounced fetch of `url?term=...`; the previous request is aborted and an overtaken response is dropped, so the list always answers what is currently typed. Leaving the field abandons a search in flight, so nothing spins beside a closed listbox and nothing is announced after focus has moved on. Responses replace the options wholesale, cloned from the `optionTemplate`, and the browser does no filtering of its own
153
+ - The `url` value can be changed on a connected combobox to repoint it, e.g. a branch field whose endpoint depends on the repository chosen beside it: set `data-l-ui--combobox-url-value` on the controller element (or assign `urlValue`). The options fetched from the old address are dropped, a request in flight is abandoned and paging is reset, so the list only ever shows options from the current address. An open list refetches straight away; a closed one fetches when it is next opened. Selected tokens are left as they are, so remove any that no longer apply yourself. Connecting does not count as a change, so it causes no extra fetch
153
154
  - Further pages are appended as the end of a remote list is reached - within `LOAD_MORE_MARGIN` of its foot (the `scrolled` action, bound to the listbox), or on Down/End at the last option, so the keyboard is not capped at the first page. Down loads instead of wrapping while pages remain, and highlights the first newly loaded option; option ids run on across pages so `aria-activedescendant` can never point at a reused id
154
155
  - The `notice` row carries only durable messages: how far into the matches the list has got, a failed request, and the character threshold. Each appended page is announced through the status region
155
156
  - A request in flight shows a spinner rather than a message - `busy` (trailing the input) while searching, `moreSpinner` (in the notice row) while a page loads - after `SPINNER_DELAY`, so a fast response never flashes one. `aria-busy` goes on the listbox immediately, since it costs nothing and says the same thing to a screen reader
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. This project follows [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## [0.29.0] - 2026-12-02
6
+
7
+ ### Added
8
+
9
+ - A remote `l_ui_combobox` can be repointed after it has connected. Change `data-l-ui--combobox-url-value` on the controller element and the combobox drops the options it fetched from the old address, abandons any request in flight and resets paging, so it offers the new address's options: straight away if the list is open, otherwise the next time it is opened. Selections are left as they are. Previously the new address was ignored until the typed term changed.
10
+
11
+ ## [0.28.2] - 2026-11-12
12
+
13
+ ### Fixed
14
+
15
+ - Popovers no longer flash in the top-left corner of the screen before moving into place when opened.
16
+ - A popover now closes as soon as its trigger is hidden while it's open (e.g. inside a collapsed sidebar or hidden tab panel), rather than staying open or being left in the top-left corner of the screen.
17
+ - An open popover now follows the page when Turbo restores the scroll position on back navigation.
18
+
5
19
  ## [0.28.1] - 2026-10-28
6
20
 
7
21
  ### Fixed
@@ -14,7 +14,9 @@ import { Controller } from "@hotwired/stimulus"
14
14
  // instead of being filtered in the browser, and each response replaces the
15
15
  // list - cloned from the option <template> so remote options are built from the
16
16
  // same markup as server-rendered ones. Further pages are appended as the user
17
- // reaches the end of the list, by pointer and by keyboard alike.
17
+ // reaches the end of the list, by pointer and by keyboard alike. The `url` can
18
+ // be changed on a connected combobox, to repoint it at a different collection:
19
+ // see urlValueChanged.
18
20
  //
19
21
  // Each selection carries its own hidden input, so the control submits with a
20
22
  // normal form post. Values that exist in the collection post under `name`;
@@ -73,14 +75,36 @@ export default class extends Controller {
73
75
  // id that aria-activedescendant might still be pointing at.
74
76
  this._optionSequence = 0
75
77
  this._refreshMoveControls()
78
+ this._connected = true
76
79
  }
77
80
 
78
81
  disconnect() {
82
+ this._connected = false
79
83
  clearTimeout(this._searchTimer)
80
84
  clearTimeout(this._busyTimer)
81
85
  this._abort()
82
86
  }
83
87
 
88
+ // Repointing a connected combobox - a branch field whose endpoint depends on
89
+ // the repository chosen beside it, say. Everything fetched from the old
90
+ // address is dropped, along with any request still out to it, so the list
91
+ // can only ever show options from the current one: an open list refetches at
92
+ // once, a closed one when it is next opened. Selections are the user's
93
+ // answer rather than part of the list, so the tokens are left alone.
94
+ //
95
+ // Stimulus also reports the initial value, before connect() has run. That is
96
+ // not a change, and the first open fetches anyway, so it is ignored.
97
+ urlValueChanged() {
98
+ if (!this._connected) return
99
+
100
+ clearTimeout(this._searchTimer)
101
+ this._resetRemoteList()
102
+ this._setNotice(null)
103
+
104
+ if (this.isOpen && this.isRemote) this._scheduleSearch({ immediate: true })
105
+ this._filterOptions()
106
+ }
107
+
84
108
  get isRemote() {
85
109
  return this.urlValue !== ""
86
110
  }
@@ -567,14 +591,7 @@ export default class extends Controller {
567
591
  // Below the threshold there is nothing worth asking the server, so the list
568
592
  // says what it is waiting for instead of showing stale results.
569
593
  if (this._belowThreshold) {
570
- this._abort()
571
- this._stopBusy()
572
- this._loading = false
573
- this._loadingMore = false
574
- this._loadedTerm = null
575
- this._page = 0
576
- this._pages = 0
577
- this._renderOptions([], { replace: true })
594
+ this._resetRemoteList()
578
595
  this._setNotice(this._text("minChars"))
579
596
  return
580
597
  }
@@ -586,6 +603,19 @@ export default class extends Controller {
586
603
  }
587
604
  }
588
605
 
606
+ // Back to having fetched nothing: no options, no paging, no request out.
607
+ _resetRemoteList() {
608
+ this._abort()
609
+ this._stopBusy()
610
+ this._loading = false
611
+ this._loadingMore = false
612
+ this._loadedTerm = null
613
+ this._page = 0
614
+ this._pages = 0
615
+ this._count = 0
616
+ this._renderOptions([], { replace: true })
617
+ }
618
+
589
619
  // Whether the loaded list stops short of the matches the server has.
590
620
  get _hasMore() {
591
621
  return this.isRemote && this._page > 0 && this._page < this._pages
@@ -16,32 +16,50 @@ export default class extends Controller {
16
16
  static GAP = 8
17
17
 
18
18
  popoverTargetConnected(element) {
19
- this._toggleHandler = (event) => {
19
+ // Handled on `beforetoggle` rather than `toggle`: the native toggle event
20
+ // is dispatched asynchronously, so positioning there lets the browser paint
21
+ // the popover at the viewport origin for a frame first, and attaching the
22
+ // scroll listener there misses any scroll that lands in between (e.g.
23
+ // Turbo restoring the scroll position on back navigation). `beforetoggle`
24
+ // fires synchronously just before the popover opens - too early to measure
25
+ // it, as it isn't rendered yet - so position in the next animation frame,
26
+ // which runs after it opens but before the first paint.
27
+ this._beforeToggleHandler = (event) => {
20
28
  if (event.newState === "open") {
21
- this.position()
22
29
  this._addRepositionListeners()
30
+ requestAnimationFrame(() => this.position())
23
31
  } else {
24
32
  this._removeRepositionListeners()
25
33
  }
26
34
  }
27
- element.addEventListener("toggle", this._toggleHandler)
28
-
29
- // Open on connect when requested (e.g. re-opening a filter popover after
30
- // a form submission re-renders the page). showPopover() and position()
31
- // must run back-to-back in the same task: the native toggle event is
32
- // dispatched asynchronously, so relying on the listener alone would paint
33
- // the popover unpositioned at the viewport origin for one frame.
34
- if (this.openValue && !element.matches(":popover-open")) {
35
+ element.addEventListener("beforetoggle", this._beforeToggleHandler)
36
+
37
+ if (element.matches(":popover-open")) {
38
+ // Already open when connected (e.g. preserved across a Turbo morph).
39
+ this._addRepositionListeners()
40
+ this.position()
41
+ } else if (this.openValue) {
42
+ // Open on connect when requested (e.g. re-opening a filter popover after
43
+ // a form submission re-renders the page). Position in the same task so
44
+ // it never paints unpositioned.
35
45
  element.showPopover()
36
46
  this.position()
37
47
  }
38
48
  }
39
49
 
40
50
  popoverTargetDisconnected(element) {
41
- element.removeEventListener("toggle", this._toggleHandler)
51
+ element.removeEventListener("beforetoggle", this._beforeToggleHandler)
42
52
  this._removeRepositionListeners()
43
53
  }
44
54
 
55
+ triggerTargetConnected(element) {
56
+ this._triggerObserver?.observe(element)
57
+ }
58
+
59
+ triggerTargetDisconnected(element) {
60
+ this._triggerObserver?.unobserve(element)
61
+ }
62
+
45
63
  disconnect() {
46
64
  this._removeRepositionListeners()
47
65
  }
@@ -51,6 +69,15 @@ export default class extends Controller {
51
69
  // the viewport.
52
70
  position() {
53
71
  if (!this.hasTriggerTarget || !this.hasPopoverTarget) return
72
+ if (!this.popoverTarget.matches(":popover-open")) return
73
+
74
+ // A trigger that isn't rendered (e.g. inside a collapsed sidebar or a
75
+ // hidden tab panel) measures as a 0x0 box at the viewport origin, which
76
+ // would strand the popover in the top-left corner. Close it instead.
77
+ if (this.triggerTarget.getClientRects().length === 0) {
78
+ this.popoverTarget.hidePopover()
79
+ return
80
+ }
54
81
 
55
82
  const gap = this.constructor.GAP
56
83
  const trigger = this.triggerTarget.getBoundingClientRect()
@@ -109,15 +136,26 @@ export default class extends Controller {
109
136
  // Private
110
137
 
111
138
  _addRepositionListeners() {
139
+ if (this._repositionHandler) return
112
140
  this._repositionHandler = () => this.position()
113
141
  window.addEventListener("resize", this._repositionHandler)
114
142
  window.addEventListener("scroll", this._repositionHandler, true)
143
+
144
+ // Also watch the trigger itself: hiding it (e.g. switching tabs with the
145
+ // keyboard) shrinks it to 0x0 without any scroll or resize, and position()
146
+ // then closes the popover. Moving or resizing the trigger re-anchors it.
147
+ // triggerTargetConnected/Disconnected keep it on the current trigger if
148
+ // one is swapped in while open (e.g. by a Turbo morph).
149
+ this._triggerObserver = new ResizeObserver(this._repositionHandler)
150
+ if (this.hasTriggerTarget) this._triggerObserver.observe(this.triggerTarget)
115
151
  }
116
152
 
117
153
  _removeRepositionListeners() {
118
154
  if (!this._repositionHandler) return
119
155
  window.removeEventListener("resize", this._repositionHandler)
120
156
  window.removeEventListener("scroll", this._repositionHandler, true)
157
+ this._triggerObserver?.disconnect()
158
+ this._triggerObserver = null
121
159
  this._repositionHandler = null
122
160
  }
123
161
  }
@@ -1,5 +1,5 @@
1
1
  module Layered
2
2
  module Ui
3
- VERSION = "0.28.1"
3
+ VERSION = "0.29.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: layered-ui-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.1
4
+ version: 0.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - layered.ai