I am using the latest version of Alpine. I need to set focus on the input searchbox as soon as it become visible. Here is my code for reference.
<div x-data="{search: false}">
<button x-on:click="search = true">Click to open search box</button>
<div x-data="searchwidget" x-show="search">
<input type="search" x-model="term" x-ref="searchInput" />
</div>
</div>
Data handler for search input
document.addEventListener('alpine:init', () => {
Alpine.data('searchwidget', () => ({
term: "",
}));
});
I tried to put $refs.searchInput.focus() on button element, but its not working.