Skip to content

Commit

Permalink
Rework modal component
Browse files Browse the repository at this point in the history
The component now behaves like a standard dialog:

  * closes on the current page, rather than redirecting elsewhere;
  * the close button is a standard dialog closing form;
  * the `open` attribute is removed, thus allowing ESC keypress
    to close the modal, and creating a focus trap when open. The
    previous behavior (i.e. have the modal open by default) is
    achieved via the new Stimulus controller, which on connect
    opens the dialog via JS.
  • Loading branch information
spaghetticode committed Mar 7, 2024
1 parent 8f8a4be commit 1878496
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
14 changes: 7 additions & 7 deletions admin/app/components/solidus_admin/ui/modal/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
<h3 class="text-xl font-semibold text-gray-900">
<%= @title %>
</h3>
<%= render component('ui/button').new(
tag: :a,
href: @close_path,
icon: 'close-line',
scheme: :ghost,
title: t('.close'),
) %>
<form method="dialog">
<%= render component('ui/button').new(
icon: 'close-line',
scheme: :ghost,
title: t('.close'),
) %>
</form>
</header>

<div class="p-4 overflow-auto">
Expand Down
7 changes: 7 additions & 0 deletions admin/app/components/solidus_admin/ui/modal/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
connect() {
this.element.showModal();
}
}
2 changes: 1 addition & 1 deletion admin/app/components/solidus_admin/ui/modal/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class SolidusAdmin::UI::Modal::Component < SolidusAdmin::BaseComponent
renders_one :actions

def initialize(title:, close_path: nil, open: true, **attributes)
def initialize(title:, close_path: nil, open: false, **attributes)
@title = title
@close_path = close_path
@attributes = attributes
Expand Down

0 comments on commit 1878496

Please sign in to comment.