Skip to content

Commit 3efd79f

Browse files
rainerdemaelia
andcommitted
Add generic controller for closing details on outside click
Implemented a new Stimulus controller for `<details>` elements and applied it to the address form. This generic controller leverages the `useClickOutside` hook from `stimulus-use` to automatically close the `<details>` when a click is detected outside its boundaries. Co-Authored-By: Elia Schito <[email protected]>
1 parent 8b56fef commit 3efd79f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

admin/app/components/solidus_admin/orders/show/address/component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</h2>
1111

1212
<% if @user&.addresses&.any? %>
13-
<details class="text-black text-sm" data-<%= stimulus_id %>-target="addresses">
13+
<details data-controller="details" data-<%= stimulus_id %>-target="addresses" class="text-black text-sm">
1414
<summary
1515
class="text-left flex cursor-pointer select-none"
1616
data-action="keydown.esc-><%= stimulus_id %>#close"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Controller } from '@hotwired/stimulus'
2+
import { useClickOutside } from 'stimulus-use'
3+
4+
export default class extends Controller {
5+
connect() {
6+
useClickOutside(this)
7+
}
8+
9+
clickOutside(event) {
10+
this.element.removeAttribute('open')
11+
}
12+
}

0 commit comments

Comments
 (0)