Skip to content

Commit 4704924

Browse files
fix: prevent tab anchor from overriding non-tab URL hashes
1 parent 2ec77db commit 4704924

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/js/controllers/tabs_controller.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ export default class extends Controller {
55

66
connect() {
77
this.activeTabClasses = (this.data.get("activeTab") || "active").split(" ")
8-
this.inactiveTabClasses = (
9-
this.data.get("inactiveTab") || "inactive"
10-
).split(" ")
8+
this.inactiveTabClasses = (this.data.get("inactiveTab") || "inactive").split(" ")
119
if (this.anchor) {
12-
this.index = this.tabTargets.findIndex((tab) => tab.id === this.anchor)
13-
this.showTab()
10+
const index = this.tabTargets.findIndex((tab) => tab.id === this.anchor)
11+
if (index >= 0) {
12+
this.index = index
13+
this.showTab()
14+
}
1415
}
15-
}
16+
}
1617

1718
change(event) {
1819
event.preventDefault()

0 commit comments

Comments
 (0)