Skip to content

Commit

Permalink
feat(admin/ui/modal): Add close action
Browse files Browse the repository at this point in the history
This removes the dialog element from the dom after closing it.
Combined with the new pages index controller we can open and close
modals without leaving the page. Much faster and less round trips.
  • Loading branch information
tvdeyen committed Dec 19, 2024
1 parent b13d7cc commit b839363
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
**@attributes
) %>
>
<a href="<%= @close_path %>" aria-hidden="true" class="cursor-default fixed inset-0 bg-full-black/50 overflow-y-auto"></a>
<a aria-hidden="true" class="cursor-default fixed inset-0 bg-full-black/50 overflow-y-auto" data-action="click-><%= stimulus_id %>#close"></a>
<div class="fixed inset-0 z-10 pointer-events-none flex min-h-full justify-center p-4 text-center items-center">
<div class="min-w-[40rem] max-h-screen pointer-events-auto cursor-auto relative transform overflow-auto rounded-lg bg-white text-left shadow-xl max-w-lg divide-y divide-gray-100">

Expand Down
9 changes: 9 additions & 0 deletions admin/app/components/solidus_admin/ui/modal/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@ import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
this.element.showModal()
this.element.addEventListener("close", () => this.removeModal())
}

close() {
this.element.close()
}

removeModal() {
this.element.remove()
}
}

0 comments on commit b839363

Please sign in to comment.