Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoSot <geo.sotis@gmail.com>2021-06-10 01:42:46 +0300
committerXhmikosR <xhmikosr@gmail.com>2021-07-29 16:30:02 +0300
commit1947ca033e0ad29ea65d069db7662632d5c66477 (patch)
tree9358fb3a79fdaeee80a83f7a2581ca7ca4f270fb /js/src/collapse.js
parent5882d5dbe85edc5e6d9ca1cdbf1fc94a0698ae82 (diff)
Refactor internal function to use it in more cases.
Also, remove a few redundant checks since we already check for it in `_addAriaAndCollapsedClass()`.
Diffstat (limited to 'js/src/collapse.js')
-rw-r--r--js/src/collapse.js38
1 files changed, 13 insertions, 25 deletions
diff --git a/js/src/collapse.js b/js/src/collapse.js
index c15bffa84f..3618c9ee39 100644
--- a/js/src/collapse.js
+++ b/js/src/collapse.js
@@ -92,7 +92,7 @@ class Collapse extends BaseComponent {
this._parent = this._config.parent ? this._getParent() : null
if (!this._config.parent) {
- this._addAriaAndCollapsedClass(this._element, this._triggerArray)
+ this._addAriaAndCollapsedClass(this._triggerArray, this._isShown())
}
if (this._config.toggle) {
@@ -177,13 +177,7 @@ class Collapse extends BaseComponent {
this._element.style[dimension] = 0
- if (this._triggerArray.length) {
- this._triggerArray.forEach(element => {
- element.classList.remove(CLASS_NAME_COLLAPSED)
- element.setAttribute('aria-expanded', true)
- })
- }
-
+ this._addAriaAndCollapsedClass(this._triggerArray, true)
this._isTransitioning = true
const complete = () => {
@@ -224,15 +218,12 @@ class Collapse extends BaseComponent {
this._element.classList.remove(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW)
const triggerArrayLength = this._triggerArray.length
- if (triggerArrayLength > 0) {
- for (let i = 0; i < triggerArrayLength; i++) {
- const trigger = this._triggerArray[i]
- const elem = getElementFromSelector(trigger)
-
- if (elem && !this._isShown(elem)) {
- trigger.classList.add(CLASS_NAME_COLLAPSED)
- trigger.setAttribute('aria-expanded', false)
- }
+ for (let i = 0; i < triggerArrayLength; i++) {
+ const trigger = this._triggerArray[i]
+ const elem = getElementFromSelector(trigger)
+
+ if (elem && !this._isShown(elem)) {
+ this._addAriaAndCollapsedClass([trigger], false)
}
}
@@ -282,22 +273,19 @@ class Collapse extends BaseComponent {
.forEach(element => {
const selected = getElementFromSelector(element)
- this._addAriaAndCollapsedClass(
- selected,
- [element]
- )
+ if (selected) {
+ this._addAriaAndCollapsedClass([element], this._isShown(selected))
+ }
})
return parent
}
- _addAriaAndCollapsedClass(element, triggerArray) {
- if (!element || !triggerArray.length) {
+ _addAriaAndCollapsedClass(triggerArray, isOpen) {
+ if (!triggerArray.length) {
return
}
- const isOpen = this._isShown(element)
-
triggerArray.forEach(elem => {
if (isOpen) {
elem.classList.remove(CLASS_NAME_COLLAPSED)