-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tabs MVP - working but needs final touches
- Loading branch information
Showing
3 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
static targets = ["tab", "panel"] | ||
|
||
connect() { | ||
console.log("Tabs controller connected!") | ||
this.showTab(this.tabTargets[0]) | ||
} | ||
|
||
change(event) { | ||
event.preventDefault() | ||
console.log("Click event triggered") | ||
console.log("Current classes:", event.currentTarget.classList.toString()) | ||
this.showTab(event.currentTarget) | ||
} | ||
|
||
showTab(selectedTab) { | ||
console.log("showTab called with:", selectedTab.id) | ||
console.log("Classes before change:", selectedTab.classList.toString()) | ||
|
||
const activeTab = this.tabTargets.find(tab => | ||
tab.classList.contains("tab-active") | ||
) | ||
|
||
if (activeTab === selectedTab) { | ||
console.log("Same tab clicked, returning") | ||
return | ||
} | ||
|
||
if (activeTab) { | ||
console.log("Deactivating current tab:", activeTab.id) | ||
activeTab.classList.remove("tab-active") | ||
activeTab.classList.add("tab-inactive") | ||
|
||
const activePanelId = activeTab.id.replace('-tab', '-tab-panel') | ||
document.getElementById(activePanelId).hidden = true | ||
} | ||
|
||
console.log("Activating new tab:", selectedTab.id) | ||
selectedTab.classList.remove("tab-inactive") | ||
selectedTab.classList.add("tab-active") | ||
|
||
const selectedPanelId = selectedTab.id.replace('-tab', '-tab-panel') | ||
document.getElementById(selectedPanelId).hidden = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters