Skip to content

Commit

Permalink
For #5049: fix click tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
avernet committed Oct 23, 2024
1 parent 83d59b2 commit 394908e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions form-runner-web/src/main/scala/org/orbeon/xbl/Tabbable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,21 @@ object Tabbable {
// 2016-10-13: We use our own logic to show/hide tabs based on position as we want to be able to
// support dynamically repeated tabs.

eventListenerSupport.addListener(containerElem, "click", (e: dom.Event) =>
if (e.target.asInstanceOf[dom.Element].matches("[data-toggle = 'tabbable']")) {
eventListenerSupport.addListener(containerElem, "click", (e: dom.Event) => {
val targetElem = e.target.asInstanceOf[dom.Element]
val matchedElem = targetElem.closest("[data-toggle = 'tabbable']")
if (matchedElem != null && containerElem.contains(matchedElem)) {
e.preventDefault() // don't allow anchor navigation
e.stopPropagation() // prevent ancestor tab handlers from running

val newLi = $(containerElem).parent(ExcludeRepeatClassesSelector)
val newLi = $(matchedElem).parent(ExcludeRepeatClassesSelector)

if (! newLi.is(ActiveSelector)) {
val tabPosition = newLi.prevAll(ExcludeRepeatClassesSelector).length
selectTab(tabPosition)
}
}
)
})
}

override def destroy(): Unit = {
Expand Down

0 comments on commit 394908e

Please sign in to comment.