impress/app/assets/javascripts/pose-picker.js

33 lines
918 B
JavaScript
Raw Normal View History

2025-11-11 17:41:57 -08:00
/**
* PosePickerPopover web component
2025-11-11 17:41:57 -08:00
*
* Scrolls the selected style into view when the style picker list becomes
* visible (e.g. tab switch or popover open).
2025-11-11 17:41:57 -08:00
*/
2025-11-11 18:07:06 -08:00
class PosePickerPopover extends HTMLElement {
#styleListObserver;
2025-11-11 17:41:57 -08:00
connectedCallback() {
// When the style picker list becomes visible (e.g. tab switch or
// popover open), scroll the selected style into view.
const styleList = this.querySelector(".style-picker-list");
if (styleList) {
this.#styleListObserver = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
const checked = styleList.querySelector("input:checked");
checked
?.closest("label")
?.scrollIntoView({ block: "nearest" });
}
});
this.#styleListObserver.observe(styleList);
}
}
disconnectedCallback() {
this.#styleListObserver?.disconnect();
2025-11-11 17:41:57 -08:00
}
}
2025-11-11 18:07:06 -08:00
customElements.define("pose-picker-popover", PosePickerPopover);