Remove inline-handler → window.* contract (issue #28)
Finish the behavioural refactor from #28: no first-party JS lives on the global object solely to be reachable from a server-rendered inline on* attribute, and no inline Alpine blobs remain in the filter bar / year picker. - Filter-bar collapse: drop the inline onclick for a delegated click listener on the persistent <filter-bar> custom element (data-filter-bar-toggle). The inner #filter-bar body is htmx-swapped while connectedCallback does not re-run, so delegation on the host preserves the swap-survival the inline handler had. - YearPicker: convert the Alpine x-data/x-on/x-ref/_pickerInstance f-string into a <year-picker> custom element with typed props (YearPickerProps). Behavior moves to ts/elements/year-picker.ts; ts/year_picker.ts and _YEAR_PICKER_MEDIA are removed. The builder lives in primitives.py (next to YearPicker) to avoid a circular import; registration stays in custom_elements.py for codegen. - Add bindPopupDismiss (ts/utils.ts): shared Escape + outside-click dismiss with a cleanup return and an extraInside hook for popups mounted on document.body. Adopted by date-range-picker.ts (1:1) and year-picker.ts (Datepicker popup is body-mounted, passed as an extra inside root). Follow-up #49 tracks unifying popup/dismiss/positioning across the remaining dropdown/search-select/Flowbite cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -403,6 +403,16 @@ class FilterBarElement extends HTMLElement {
|
||||
const form = this.querySelector<HTMLFormElement>("form");
|
||||
if (!form) return;
|
||||
|
||||
// Delegated on the persistent custom element so the toggle keeps working
|
||||
// after the inner #filter-bar body is htmx-swapped — connectedCallback does
|
||||
// not re-run for inner swaps, so a direct listener on the button would be
|
||||
// lost (this is why the toggle was previously an inline onclick).
|
||||
this.addEventListener("click", (event) => {
|
||||
if ((event.target as Element).closest("[data-filter-bar-toggle]")) {
|
||||
this.querySelector("#filter-bar-body")?.classList.toggle("hidden");
|
||||
}
|
||||
});
|
||||
|
||||
form.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
const filter = buildFilterJSON(form);
|
||||
|
||||
Reference in New Issue
Block a user