5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 09:06:22 +00:00

feat: pasar el foco al modal al abrir y volver al cerrar

This commit is contained in:
f 2024-06-05 18:01:44 -03:00
parent 295c4f57ef
commit 706f0162a5
No known key found for this signature in database
2 changed files with 12 additions and 2 deletions

View file

@ -26,7 +26,7 @@ export default class extends Controller {
if (!event.target?.dataset?.modalShowValue) return; if (!event.target?.dataset?.modalShowValue) return;
window.dispatchEvent(new CustomEvent("modal:show", { detail: { id: event.target.dataset.modalShowValue } })); window.dispatchEvent(new CustomEvent("modal:show", { detail: { id: event.target.dataset.modalShowValue, previousFocus: event.target.id } }));
} }
/* /*
@ -50,9 +50,17 @@ export default class extends Controller {
window.document.body.classList.add("modal-open"); window.document.body.classList.add("modal-open");
if (event?.detail?.previousFocus) {
this.previousFocus = window.document.getElementById(event.detail.previousFocus);
} else {
this.previousFocus = event?.target;
}
setTimeout(() => { setTimeout(() => {
this.modalTarget.classList.add("show"); this.modalTarget.classList.add("show");
this.backdropTarget.classList.add("show"); this.backdropTarget.classList.add("show");
this.modalTarget.focus();
}, 1); }, 1);
} }
@ -75,6 +83,8 @@ export default class extends Controller {
this.modalTarget.removeAttribute("role"); this.modalTarget.removeAttribute("role");
this.modalTarget.removeAttribute("aria-modal"); this.modalTarget.removeAttribute("aria-modal");
this.previousFocus?.focus();
setTimeout(() => { setTimeout(() => {
this.modalTarget.style.display = ""; this.modalTarget.style.display = "";
this.backdropTarget.style.display = ""; this.backdropTarget.style.display = "";

View file

@ -25,7 +25,7 @@
= hidden_field_tag name, '' = hidden_field_tag name, ''
.d-flex.align-items-center.justify-content-between .d-flex.align-items-center.justify-content-between
= label_tag id, post_label_t(attribute, post: post), class: 'h3' = label_tag id, post_label_t(attribute, post: post), class: 'h3'
= render 'bootstrap/btn', content: t('.edit'), action: 'modal#showAnother', data: { 'modal-show-value': modal_id } = render 'bootstrap/btn', content: t('.edit'), action: 'modal#showAnother', data: { 'modal-show-value': modal_id }, id: random_id
-# Aquí se reemplaza por la tarjeta y el UUID luego de guardar -# Aquí se reemplaza por la tarjeta y el UUID luego de guardar
.row.row-cols-1.no-gutters.placeholder-glow{ id: target_id } .row.row-cols-1.no-gutters.placeholder-glow{ id: target_id }