I have three tabs and three corresponding select options. When I click on a tab I select its corresponding option. I'd like to be able to select an option and focus its corresponding tab. Thanks in advance.
function tabs(){
return{
select: 'focus-a',
tabs:[
{
name: 'focus-a'
},
{
name: 'focus-b'
},
{
name: 'focus-c'
}
]
}
}
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js"></script>
<div
x-data="tabs()"
>
<div>
<template x-for="btn in tabs">
<input type="button" x-ref="btn.name" x-on:click="select = btn.name" :value="btn.name" />
</template>
</div>
<div>
<select name="test">
<template x-for="tab in tabs" x-on:change="buttons.focus()">
<option :selected="tab.name === select" :value="tab.name" x-text="tab.name"></option>
</template>
</select>
</div>
</div>
I got help over on Github. Working code is below with comments. I lost the trail of who actually fixed it for me. It may have been you Hugo?