Files
3dealer/resources/js/stimulus/tabs-controller.js
T

22 lines
595 B
JavaScript

import { Controller } from '@hotwired/stimulus'
export default class extends Controller {
static targets = ['button', 'panel']
show(event) {
this.activate(event.currentTarget.dataset.panel)
}
activate(panelId) {
this.buttonTargets.forEach(btn => {
const active = btn.dataset.panel === panelId
btn.classList.toggle('is-active', active)
btn.setAttribute('aria-selected', String(active))
})
this.panelTargets.forEach(panel => {
panel.hidden = panel.id !== `tab-panel-${panelId}`
})
}
}