mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-04-02 16:44:56 +02:00
fix: move focus-trap logic from inline attribute to JS method
The @keydown.tab handler in fediverse-modal.njk contained complex inline JS with arrow functions, querySelector strings with escaped quotes, and comparison operators — all of which confused html-minifier-terser's HTML parser, causing parse errors on every page that includes the modal (i.e., nearly every page). Moved the focus-trap logic to a trapFocus() method on the Alpine component where it belongs. Confab-Link: http://localhost:8080/sessions/edb1b7b0-da66-4486-bd9c-d1cfa7553b88
This commit is contained in:
@@ -133,6 +133,15 @@ document.addEventListener("alpine:init", () => {
|
||||
}
|
||||
},
|
||||
|
||||
trapFocus(event) {
|
||||
const focusable = [...this.$el.querySelectorAll('button, input, a, [tabindex]:not([tabindex="-1"])')].filter(el => !el.closest('[x-show]') || el.closest('[x-show]').style.display !== 'none');
|
||||
if (!focusable.length) return;
|
||||
const first = focusable[0];
|
||||
const last = focusable[focusable.length - 1];
|
||||
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
||||
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
||||
},
|
||||
|
||||
redirectToInstance(domain) {
|
||||
if (this.mode === "share") {
|
||||
window.location.href = `https://${domain}/share?text=${encodeURIComponent(this.targetUrl)}`;
|
||||
|
||||
Reference in New Issue
Block a user