0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-01 13:24:25 +01:00

ref(tab): remove show from panels dependent-less they have .fade class or not (simplify checks) (#36622)

This commit is contained in:
GeoSot 2022-06-27 12:43:11 +03:00 committed by GitHub
parent 8de0488330
commit f14c58f494
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 14 deletions

View File

@ -109,13 +109,9 @@ class Tab extends BaseComponent {
this._activate(getElementFromSelector(element)) // Search and activate/show the proper section
const isAnimated = element.classList.contains(CLASS_NAME_FADE)
const complete = () => {
if (isAnimated) { // todo: maybe is redundant
element.classList.add(CLASS_NAME_SHOW)
}
if (element.getAttribute('role') !== 'tab') {
element.classList.add(CLASS_NAME_SHOW)
return
}
@ -128,7 +124,7 @@ class Tab extends BaseComponent {
})
}
this._queueCallback(complete, element, isAnimated)
this._queueCallback(complete, element, element.classList.contains(CLASS_NAME_FADE))
}
_deactivate(element, relatedElem) {
@ -141,13 +137,9 @@ class Tab extends BaseComponent {
this._deactivate(getElementFromSelector(element)) // Search and deactivate the shown section too
const isAnimated = element.classList.contains(CLASS_NAME_FADE)
const complete = () => {
if (isAnimated) { // todo maybe is redundant
element.classList.remove(CLASS_NAME_SHOW)
}
if (element.getAttribute('role') !== 'tab') {
element.classList.remove(CLASS_NAME_SHOW)
return
}
@ -157,7 +149,7 @@ class Tab extends BaseComponent {
EventHandler.trigger(element, EVENT_HIDDEN, { relatedTarget: relatedElem })
}
this._queueCallback(complete, element, isAnimated)
this._queueCallback(complete, element, element.classList.contains(CLASS_NAME_FADE))
}
_keydown(event) {

View File

@ -904,7 +904,7 @@ describe('Tab', () => {
})
})
it('should not add `show` class to tab panes if there is no `.fade` class', () => {
it('should add `show` class to tab panes if there is no `.fade` class', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = [
'<ul class="nav nav-tabs" role="tablist">',
@ -924,7 +924,7 @@ describe('Tab', () => {
const secondNavEl = fixtureEl.querySelector('#secondNav')
secondNavEl.addEventListener('shown.bs.tab', () => {
expect(fixtureEl.querySelectorAll('.show')).toHaveSize(0)
expect(fixtureEl.querySelectorAll('.tab-content .show')).toHaveSize(1)
resolve()
})