layered-ui-rails 0.28.1 → 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 +4 -4
- data/CHANGELOG.md +8 -0
- data/app/javascript/layered_ui/controllers/l_ui/popover_controller.js +49 -11
- data/lib/layered/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: d0f239bdc2e4c3003b0e877dd5e7820122f447c19aa13772c0445de8e2809aa0
|
|
4
|
+
data.tar.gz: 86c4b71af97fceb7db059715be9b5440b51250f3e2cb2c189825f2c0abacab92
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35b11296d6b291b518731f08e7df45810644c9fa661db5adda10ff056e7b128cc58bf535a3a55b91585337ef7c049d5c5cca2d284b4d9e6ef5b3860d837b4ecd
|
|
7
|
+
data.tar.gz: 6117f559bc283001afe48fdd1e54d3ce9a58c65a1c98d9f706da04bcfcf733876e0b0e604774832898c97e1c5893d40f7b8f5cc9c888f9ed13be1625d2b3276d
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
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
|
+
|
|
5
13
|
## [0.28.1] - 2026-10-28
|
|
6
14
|
|
|
7
15
|
### Fixed
|
|
@@ -16,32 +16,50 @@ export default class extends Controller {
|
|
|
16
16
|
static GAP = 8
|
|
17
17
|
|
|
18
18
|
popoverTargetConnected(element) {
|
|
19
|
-
|
|
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("
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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("
|
|
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
|
}
|
data/lib/layered/ui/version.rb
CHANGED