mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Extract/clarify methods in tabs_controller
This commit is contained in:
@@ -3,19 +3,28 @@ import { Controller } from "stimulus";
|
||||
export default class extends Controller {
|
||||
static targets = ["tab", "content"]
|
||||
|
||||
connect() {
|
||||
this.setCurrentTab()
|
||||
}
|
||||
|
||||
select(event) {
|
||||
this.setCurrentTab(this.tabTargets.indexOf(event.currentTarget))
|
||||
}
|
||||
|
||||
// private
|
||||
|
||||
connect() {
|
||||
this.setCurrentTab()
|
||||
}
|
||||
|
||||
setCurrentTab(tabIndex = 0) {
|
||||
this.showSelectedContent(tabIndex)
|
||||
this.setButtonActiveClass(tabIndex)
|
||||
}
|
||||
|
||||
showSelectedContent(tabIndex) {
|
||||
this.contentTargets.forEach((element, index) => {
|
||||
element.hidden = index !== tabIndex
|
||||
})
|
||||
}
|
||||
|
||||
setButtonActiveClass(tabIndex) {
|
||||
this.tabTargets.forEach((element, index) => {
|
||||
if(index === tabIndex) {
|
||||
element.classList.add("active")
|
||||
|
||||
Reference in New Issue
Block a user