Skip to content

Commit

Permalink
Fix turbo cache event handling for details dropdown
Browse files Browse the repository at this point in the history
Corrected the Stimulus controller event handling to ensure
dropdown <details> close on modal open/close.
Previously, the `turbo:before-cache` event was not properly connected to
the Stimulus controller, causing menus to remain open after a modal was triggered.

The 'closeMenus' method within the controller was attempting to call
'querySelectorAll' on 'this.event', which is undefined within the Stimulus context.

This update corrects the 'closeMenus' method to reference 'this.element',
ensuring that it correctly targets the controller's DOM element.
  • Loading branch information
rainerdema committed Nov 8, 2023
1 parent ae29975 commit 3a5daf8
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
closeMenus() {
this.event.querySelectorAll('details').forEach(details => details.removeAttribute('open'));
this.element.querySelectorAll('details').forEach(details => details.removeAttribute('open'));
}
}

0 comments on commit 3a5daf8

Please sign in to comment.