layered-ui-rails 0.28.0 → 0.28.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c66f8427345d985e75698323e24a88f786660e98fe32e8befd0be09075929f9a
4
- data.tar.gz: 3417a418226cb32d22d6bf8a948e84294b23d3fe9cf05a0346869f1234091598
3
+ metadata.gz: d0f239bdc2e4c3003b0e877dd5e7820122f447c19aa13772c0445de8e2809aa0
4
+ data.tar.gz: 86c4b71af97fceb7db059715be9b5440b51250f3e2cb2c189825f2c0abacab92
5
5
  SHA512:
6
- metadata.gz: e53007f6b0bff6208c9ef11e1296c876c24fed859b77592743013a4c1b28c4a3b6e92dba759d42c754eef5715323a0e1bc3b2d7647d21ffb068ed6b8f14b23e2
7
- data.tar.gz: d685b0bc30779dd77d0192c8542d4342850a70cb3a3bf22c8a74a1dbf986453f5f685c49280d51e9acc82ccfa838cd57f87a698652de2ec77486e7b89bf7203c
6
+ metadata.gz: 35b11296d6b291b518731f08e7df45810644c9fa661db5adda10ff056e7b128cc58bf535a3a55b91585337ef7c049d5c5cca2d284b4d9e6ef5b3860d837b4ecd
7
+ data.tar.gz: 6117f559bc283001afe48fdd1e54d3ce9a58c65a1c98d9f706da04bcfcf733876e0b0e604774832898c97e1c5893d40f7b8f5cc9c888f9ed13be1625d2b3276d
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.28.2] - 2026-11-12
6
+
7
+ ### Fixed
8
+
9
+ - Popovers no longer flash in the top-left corner of the screen before moving into place when opened.
10
+ - 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.
11
+ - An open popover now follows the page when Turbo restores the scroll position on back navigation.
12
+
13
+ ## [0.28.1] - 2026-10-28
14
+
15
+ ### Fixed
16
+
17
+ - A single-select `l_ui_combobox` no longer shows its placeholder once a value is chosen. The placeholder stayed visible beside the token and read as a second value. It is now transparent while a token is selected; multi-select comboboxes are unchanged.
18
+
5
19
  ## [0.28.0] - 2026-10-25
6
20
 
7
21
  ### Added
@@ -2177,6 +2177,14 @@ pre.l-ui-surface {
2177
2177
  outline-none;
2178
2178
  }
2179
2179
 
2180
+ /* A single select holds one value, so once a token is chosen the placeholder
2181
+ would read as a second value beside it. It is made transparent rather than
2182
+ removed so the input keeps its width and the attribute stays intact. */
2183
+ .l-ui-combobox[data-l-ui--combobox-multiple-value="false"]
2184
+ .l-ui-combobox__tokens:not(:empty) ~ .l-ui-combobox__input::placeholder {
2185
+ @apply text-transparent;
2186
+ }
2187
+
2180
2188
  .l-ui-combobox__listbox {
2181
2189
  @apply absolute right-0 left-0 z-30
2182
2190
  max-h-64
@@ -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.0"
3
+ VERSION = "0.28.2"
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.0
4
+ version: 0.28.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - layered.ai