mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-23 07:09:39 +02:00
Allow event propagation to fix turbo frame update (#575)
* Allow event propagation to fix turbo frame update * Add setting to dropdown to manage close when open and clicking on it
This commit is contained in:
parent
f0c2d4ead0
commit
2181cdd118
2 changed files with 3 additions and 2 deletions
|
@ -3,6 +3,7 @@ import { Controller } from "@hotwired/stimulus"
|
||||||
// Connects to data-controller="dropdown"
|
// Connects to data-controller="dropdown"
|
||||||
export default class extends Controller {
|
export default class extends Controller {
|
||||||
static targets = ["menu"]
|
static targets = ["menu"]
|
||||||
|
static values = { closeOnClick: { type: Boolean, default: true } }
|
||||||
|
|
||||||
toggleMenu = (e) => {
|
toggleMenu = (e) => {
|
||||||
e.stopPropagation(); // Prevent event from closing the menu immediately
|
e.stopPropagation(); // Prevent event from closing the menu immediately
|
||||||
|
@ -24,7 +25,7 @@ export default class extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
onDocumentClick = (e) => {
|
onDocumentClick = (e) => {
|
||||||
if (this.menuTarget.contains(e.target)) {
|
if (this.menuTarget.contains(e.target) && !this.closeOnClickValue ) {
|
||||||
// user has clicked inside of the dropdown
|
// user has clicked inside of the dropdown
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<%# locals: (transaction:) %>
|
<%# locals: (transaction:) %>
|
||||||
<div class="relative" data-controller="dropdown">
|
<div class="relative" data-controller="dropdown" data-dropdown-close-on-click-value="false">
|
||||||
<div class="flex cursor-pointer" data-action="click->dropdown#toggleMenu">
|
<div class="flex cursor-pointer" data-action="click->dropdown#toggleMenu">
|
||||||
<%= render partial: "shared/category_badge", locals: transaction.category.nil? ? {} : { name: transaction.category.name, color: transaction.category.color } %>
|
<%= render partial: "shared/category_badge", locals: transaction.category.nil? ? {} : { name: transaction.category.name, color: transaction.category.color } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue