Skip to content

Commit f887f40

Browse files
authored
Add toggle support to popover (excid3#142)
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.
1 parent 0f6fed2 commit f887f40

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/popover.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
// </div>
1515
// which shows you local search results before normal organic results.
1616
//</p>
17+
//
18+
// You can also toggle the popover using the click action.
19+
// <div class="popover inline-block" data-controller="popover" data-action="click->popover#toggle" data-action="mouseover->popover#mouseOver mouseout->popover#mouseOut">
1720

1821
import { Controller } from '@hotwired/stimulus'
1922

@@ -36,4 +39,12 @@ export default class extends Controller {
3639
mouseOut() {
3740
this.contentTarget.classList.add('hidden')
3841
}
42+
// Toggle the popover on demand
43+
toggle() {
44+
if (this.contentTarget.classList.contains('hidden')) {
45+
this.contentTarget.classList.remove('hidden')
46+
} else {
47+
this.contentTarget.classList.add('hidden')
48+
}
49+
}
3950
}

0 commit comments

Comments
 (0)