Place a rail's highlight again whenever the rail changes size

The highlight was placed only when an item was pressed or released, the
window resized, or the pointer moved through an edge strip. A rail hidden
and shown again (Context docked and undocked) was left with its open item
unmarked, and a rail turned from a column to a row (panels moved to the
screen edge) kept its highlight where the icon had been. Each rail is now
watched for size changes, and its highlight placed again when it changes.

Co-authored-by: Sameh Khamis <[email protected]>
This commit is contained in:
Manjunath PaparajuandSameh Khamis authored and Sameh Khamis committed 2026-11-14 13:41:07 -08:00
1 parent 4568b9ff12
commit 4debb49fe0
1 file changed
+19
+19
View File
@@ -105,6 +105,7 @@ export function installRailEdgeScroll(doc = globalThis.document) {
win.cancelAnimationFrame(frame); win.cancelAnimationFrame(frame);
let left = frames; let left = frames;
const tick = () => { const tick = () => {
watchRails();
doc.querySelectorAll('.ui-rail').forEach(glide); doc.querySelectorAll('.ui-rail').forEach(glide);
if ((left -= 1) > 0) frame = win.requestAnimationFrame(tick); if ((left -= 1) > 0) frame = win.requestAnimationFrame(tick);
}; };
@@ -126,6 +127,23 @@ export function installRailEdgeScroll(doc = globalThis.document) {
attributeFilter: ['aria-pressed'], attributeFilter: ['aria-pressed'],
}); });
// A rail also changes shape with nothing pressed or released: hidden and
// shown again (Context docked and undocked), or turned from a column to a
// row (panels moved to the screen edge). Its highlight is placed again
// whenever its size changes, so it is never left where an icon was.
const sized =
typeof win.ResizeObserver === 'function' ? new win.ResizeObserver(() => follow(2)) : null;
const watched = new WeakSet();
const watchRails = () => {
if (!sized) return;
doc.querySelectorAll('.ui-rail').forEach((rail) => {
if (watched.has(rail)) return;
watched.add(rail);
sized.observe(rail);
});
};
watchRails();
// ── The edge strip ── // ── The edge strip ──
/** The rail whose strip holds the point, unless a control there owns it. */ /** The rail whose strip holds the point, unless a control there owns it. */
function railAt(x, target) { function railAt(x, target) {
@@ -279,6 +297,7 @@ export function installRailEdgeScroll(doc = globalThis.document) {
win.clearTimeout(heldStep); win.clearTimeout(heldStep);
setHot(null); setHot(null);
observer?.disconnect(); observer?.disconnect();
sized?.disconnect();
win.cancelAnimationFrame(frame); win.cancelAnimationFrame(frame);
doc.removeEventListener('pointermove', onMove); doc.removeEventListener('pointermove', onMove);
doc.removeEventListener('pointerout', onLeave); doc.removeEventListener('pointerout', onLeave);