The library flowbite-svelte
has component Popover
with open
property. The property changing by click on button. In order to control external event listener (no in example) I need to know current value of open
property. How to get it?
I tried to use open=
and bind:open=
, but buth undefined
when button clicked.
<script>
import { onMount } from 'svelte'
import { Popover } from 'flowbite-svelte'
let popover
let isOpen
onMount(() => {
popover.$on('show', () => {
console.log(popover.open) // undefined
console.log(isOpen) // undefined
})
})
</script>
<button>Click</button>
<Popover
<!-- open={isOpen} or bind:open={isOpen} -->
bind:this={popover}
trigger="click">
Some content
</Popover>
2
Answers
I found solution via debugging. When
show
event occurs, callback hasthis
with popover instance. Insidethis.$$.ctx
stored values by index fromthis.$$.props
.There is no property for that, and there also is only a
show
event, no event for closing.That being the case, there currently is no proper way of getting the state. You could maybe query the DOM, but this functionality should be part of the component.
Maybe open an issue if there is none already.