]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Change the way collapse handles its children on opening
authorGeoSot <geo.sotis@gmail.com>
Sun, 10 Oct 2021 11:35:52 +0000 (14:35 +0300)
committerXhmikosR <xhmikosr@gmail.com>
Wed, 13 Oct 2021 13:38:27 +0000 (16:38 +0300)
js/src/collapse.js

index f4fa11de405f5ab9bc256665f16e5a63f03ab9a1..642f7e840b1c02eadc754ef52be5794b2416df39 100644 (file)
@@ -13,7 +13,6 @@ import {
   reflow,
   typeCheckConfig
 } from './util/index'
-import Data from './dom/data'
 import EventHandler from './dom/event-handler'
 import Manipulator from './dom/manipulator'
 import SelectorEngine from './dom/selector-engine'
@@ -77,7 +76,6 @@ class Collapse extends BaseComponent {
         .filter(foundElem => foundElem === this._element)
 
       if (selector !== null && filterElement.length) {
-        this._selector = selector
         this._triggerArray.push(elem)
       }
     }
@@ -116,21 +114,17 @@ class Collapse extends BaseComponent {
       return
     }
 
-    let actives = []
-    let activesData
+    let activeChildren = []
 
+    // find active children
     if (this._config.parent) {
-      actives = this._getFirstLevelChildren(SELECTOR_ACTIVES)
+      activeChildren = this._getFirstLevelChildren(SELECTOR_ACTIVES)
+        .filter(element => element !== this._element)
+        .map(element => Collapse.getOrCreateInstance(element, { toggle: false }))
     }
 
-    const container = SelectorEngine.findOne(this._selector)
-    if (actives.length) {
-      const tempActiveData = actives.find(elem => container !== elem)
-      activesData = tempActiveData ? Collapse.getInstance(tempActiveData) : null
-
-      if (activesData && activesData._isTransitioning) {
-        return
-      }
+    if (activeChildren.length && activeChildren[0]._isTransitioning) {
+      return
     }
 
     const startEvent = EventHandler.trigger(this._element, EVENT_SHOW)
@@ -138,14 +132,8 @@ class Collapse extends BaseComponent {
       return
     }
 
-    for (const elemActive of actives) {
-      if (container !== elemActive) {
-        Collapse.getOrCreateInstance(elemActive, { toggle: false }).hide()
-      }
-
-      if (!activesData) {
-        Data.set(elemActive, DATA_KEY, null)
-      }
+    for (const activeInstance of activeChildren) {
+      activeInstance.hide()
     }
 
     const dimension = this._getDimension()