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

32 lines
867 B
JavaScript
Raw Normal View History

2025-11-11 17:41:57 -08:00
/**
* PosePicker web component
*
* Progressive enhancement for pose picker forms:
* - Auto-submits the form when a pose is selected (if JS is enabled)
* - Shows a submit button as fallback (if JS is disabled or slow to load)
* - Uses Custom Element internals API to communicate state to CSS
*/
2025-11-11 18:07:06 -08:00
class PosePickerPopover extends HTMLElement {
2025-11-11 17:41:57 -08:00
#internals;
constructor() {
super();
this.#internals = this.attachInternals();
}
connectedCallback() {
// Listen for changes to auto-submit the form, then tell CSS about it!
this.addEventListener("change", this.#handleChange);
this.#internals.states.add("auto-loading");
}
#handleChange(e) {
// Only auto-submit if a radio button was changed
if (e.target.type === "radio") {
this.querySelector("form").requestSubmit();
}
}
}
2025-11-11 18:07:06 -08:00
customElements.define("pose-picker-popover", PosePickerPopover);