mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-09 07:06:36 +02:00
Refactor internal function to use it in more cases.
Also, remove a few redundant checks since we already check for it in `_addAriaAndCollapsedClass()`.
This commit is contained in:
@@ -92,7 +92,7 @@ class Collapse extends BaseComponent {
|
|||||||
this._parent = this._config.parent ? this._getParent() : null
|
this._parent = this._config.parent ? this._getParent() : null
|
||||||
|
|
||||||
if (!this._config.parent) {
|
if (!this._config.parent) {
|
||||||
this._addAriaAndCollapsedClass(this._element, this._triggerArray)
|
this._addAriaAndCollapsedClass(this._triggerArray, this._isShown())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._config.toggle) {
|
if (this._config.toggle) {
|
||||||
@@ -177,13 +177,7 @@ class Collapse extends BaseComponent {
|
|||||||
|
|
||||||
this._element.style[dimension] = 0
|
this._element.style[dimension] = 0
|
||||||
|
|
||||||
if (this._triggerArray.length) {
|
this._addAriaAndCollapsedClass(this._triggerArray, true)
|
||||||
this._triggerArray.forEach(element => {
|
|
||||||
element.classList.remove(CLASS_NAME_COLLAPSED)
|
|
||||||
element.setAttribute('aria-expanded', true)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this._isTransitioning = true
|
this._isTransitioning = true
|
||||||
|
|
||||||
const complete = () => {
|
const complete = () => {
|
||||||
@@ -224,15 +218,12 @@ class Collapse extends BaseComponent {
|
|||||||
this._element.classList.remove(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW)
|
this._element.classList.remove(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW)
|
||||||
|
|
||||||
const triggerArrayLength = this._triggerArray.length
|
const triggerArrayLength = this._triggerArray.length
|
||||||
if (triggerArrayLength > 0) {
|
|
||||||
for (let i = 0; i < triggerArrayLength; i++) {
|
for (let i = 0; i < triggerArrayLength; i++) {
|
||||||
const trigger = this._triggerArray[i]
|
const trigger = this._triggerArray[i]
|
||||||
const elem = getElementFromSelector(trigger)
|
const elem = getElementFromSelector(trigger)
|
||||||
|
|
||||||
if (elem && !this._isShown(elem)) {
|
if (elem && !this._isShown(elem)) {
|
||||||
trigger.classList.add(CLASS_NAME_COLLAPSED)
|
this._addAriaAndCollapsedClass([trigger], false)
|
||||||
trigger.setAttribute('aria-expanded', false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,22 +273,19 @@ class Collapse extends BaseComponent {
|
|||||||
.forEach(element => {
|
.forEach(element => {
|
||||||
const selected = getElementFromSelector(element)
|
const selected = getElementFromSelector(element)
|
||||||
|
|
||||||
this._addAriaAndCollapsedClass(
|
if (selected) {
|
||||||
selected,
|
this._addAriaAndCollapsedClass([element], this._isShown(selected))
|
||||||
[element]
|
}
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return parent
|
return parent
|
||||||
}
|
}
|
||||||
|
|
||||||
_addAriaAndCollapsedClass(element, triggerArray) {
|
_addAriaAndCollapsedClass(triggerArray, isOpen) {
|
||||||
if (!element || !triggerArray.length) {
|
if (!triggerArray.length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const isOpen = this._isShown(element)
|
|
||||||
|
|
||||||
triggerArray.forEach(elem => {
|
triggerArray.forEach(elem => {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
elem.classList.remove(CLASS_NAME_COLLAPSED)
|
elem.classList.remove(CLASS_NAME_COLLAPSED)
|
||||||
|
Reference in New Issue
Block a user