Skip to content

Commit

Permalink
Add toggle support to popover (#142)
Browse files Browse the repository at this point in the history
I found it useful in my use case where I have a few buttons in the popover and the task can be a more repetitive one.
  • Loading branch information
adrianthedev authored Mar 3, 2022
1 parent 0f6fed2 commit f887f40
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// </div>
// which shows you local search results before normal organic results.
//</p>
//
// You can also toggle the popover using the click action.
// <div class="popover inline-block" data-controller="popover" data-action="click->popover#toggle" data-action="mouseover->popover#mouseOver mouseout->popover#mouseOut">

import { Controller } from '@hotwired/stimulus'

Expand All @@ -36,4 +39,12 @@ export default class extends Controller {
mouseOut() {
this.contentTarget.classList.add('hidden')
}
// Toggle the popover on demand
toggle() {
if (this.contentTarget.classList.contains('hidden')) {
this.contentTarget.classList.remove('hidden')
} else {
this.contentTarget.classList.add('hidden')
}
}
}

0 comments on commit f887f40

Please sign in to comment.