2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-17 19:21:23 +03:00

Variabilize backdrop class name (#34094)

This commit is contained in:
Romain
2021-05-31 19:14:54 +02:00
committed by GeoSot
parent 088ef62982
commit 93f1107ef5
5 changed files with 39 additions and 16 deletions
+3 -1
View File
@@ -61,6 +61,7 @@ const CLASS_NAME_OPEN = 'modal-open'
const CLASS_NAME_FADE = 'fade' const CLASS_NAME_FADE = 'fade'
const CLASS_NAME_SHOW = 'show' const CLASS_NAME_SHOW = 'show'
const CLASS_NAME_STATIC = 'modal-static' const CLASS_NAME_STATIC = 'modal-static'
const CLASS_NAME_BACKDROP = 'modal-backdrop'
const SELECTOR_DIALOG = '.modal-dialog' const SELECTOR_DIALOG = '.modal-dialog'
const SELECTOR_MODAL_BODY = '.modal-body' const SELECTOR_MODAL_BODY = '.modal-body'
@@ -202,7 +203,8 @@ class Modal extends BaseComponent {
_initializeBackDrop() { _initializeBackDrop() {
return new Backdrop({ return new Backdrop({
isVisible: Boolean(this._config.backdrop), // 'static' option will be translated to true, and booleans will keep their value isVisible: Boolean(this._config.backdrop), // 'static' option will be translated to true, and booleans will keep their value
isAnimated: this._isAnimated() isAnimated: this._isAnimated(),
backdropClassName: CLASS_NAME_BACKDROP
}) })
} }
+3
View File
@@ -45,6 +45,8 @@ const DefaultType = {
} }
const CLASS_NAME_SHOW = 'show' const CLASS_NAME_SHOW = 'show'
const CLASS_NAME_BACKDROP = 'offcanvas-backdrop'
const OPEN_SELECTOR = '.offcanvas.show' const OPEN_SELECTOR = '.offcanvas.show'
const EVENT_SHOW = `show${EVENT_KEY}` const EVENT_SHOW = `show${EVENT_KEY}`
@@ -180,6 +182,7 @@ class Offcanvas extends BaseComponent {
isVisible: this._config.backdrop, isVisible: this._config.backdrop,
isAnimated: true, isAnimated: true,
rootElement: this._element.parentNode, rootElement: this._element.parentNode,
backdropClassName: CLASS_NAME_BACKDROP,
clickCallback: () => this.hide() clickCallback: () => this.hide()
}) })
} }
+1 -2
View File
@@ -22,7 +22,6 @@ const DefaultType = {
clickCallback: '(function|null)' clickCallback: '(function|null)'
} }
const NAME = 'backdrop' const NAME = 'backdrop'
const CLASS_NAME_BACKDROP = 'modal-backdrop'
const CLASS_NAME_FADE = 'fade' const CLASS_NAME_FADE = 'fade'
const CLASS_NAME_SHOW = 'show' const CLASS_NAME_SHOW = 'show'
@@ -73,7 +72,7 @@ class Backdrop {
_getElement() { _getElement() {
if (!this._element) { if (!this._element) {
const backdrop = document.createElement('div') const backdrop = document.createElement('div')
backdrop.className = CLASS_NAME_BACKDROP backdrop.className = this._config.backdropClassName
if (this._config.isAnimated) { if (this._config.isAnimated) {
backdrop.classList.add(CLASS_NAME_FADE) backdrop.classList.add(CLASS_NAME_FADE)
} }
+28 -13
View File
@@ -3,6 +3,7 @@ import { getTransitionDurationFromElement } from '../../../src/util/index'
import { clearFixture, getFixture } from '../../helpers/fixture' import { clearFixture, getFixture } from '../../helpers/fixture'
const CLASS_BACKDROP = '.modal-backdrop' const CLASS_BACKDROP = '.modal-backdrop'
const CLASS_NAME_BACKDROP = 'modal-backdrop'
const CLASS_NAME_FADE = 'fade' const CLASS_NAME_FADE = 'fade'
const CLASS_NAME_SHOW = 'show' const CLASS_NAME_SHOW = 'show'
@@ -26,7 +27,8 @@ describe('Backdrop', () => {
it('if it is "shown", should append the backdrop html once, on show, and contain "show" class', done => { it('if it is "shown", should append the backdrop html once, on show, and contain "show" class', done => {
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: true, isVisible: true,
isAnimated: false isAnimated: false,
backdropClassName: CLASS_NAME_BACKDROP
}) })
const getElements = () => document.querySelectorAll(CLASS_BACKDROP) const getElements = () => document.querySelectorAll(CLASS_BACKDROP)
@@ -45,7 +47,8 @@ describe('Backdrop', () => {
it('if it is not "shown", should not append the backdrop html', done => { it('if it is not "shown", should not append the backdrop html', done => {
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: false, isVisible: false,
isAnimated: true isAnimated: true,
backdropClassName: CLASS_NAME_BACKDROP
}) })
const getElements = () => document.querySelectorAll(CLASS_BACKDROP) const getElements = () => document.querySelectorAll(CLASS_BACKDROP)
@@ -59,7 +62,8 @@ describe('Backdrop', () => {
it('if it is "shown" and "animated", should append the backdrop html once, and contain "fade" class', done => { it('if it is "shown" and "animated", should append the backdrop html once, and contain "fade" class', done => {
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: true, isVisible: true,
isAnimated: true isAnimated: true,
backdropClassName: CLASS_NAME_BACKDROP
}) })
const getElements = () => document.querySelectorAll(CLASS_BACKDROP) const getElements = () => document.querySelectorAll(CLASS_BACKDROP)
@@ -79,7 +83,8 @@ describe('Backdrop', () => {
it('should remove the backdrop html', done => { it('should remove the backdrop html', done => {
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: true, isVisible: true,
isAnimated: true isAnimated: true,
backdropClassName: CLASS_NAME_BACKDROP
}) })
const getElements = () => document.body.querySelectorAll(CLASS_BACKDROP) const getElements = () => document.body.querySelectorAll(CLASS_BACKDROP)
@@ -97,7 +102,8 @@ describe('Backdrop', () => {
it('should remove "show" class', done => { it('should remove "show" class', done => {
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: true, isVisible: true,
isAnimated: true isAnimated: true,
backdropClassName: CLASS_NAME_BACKDROP
}) })
const elem = instance._getElement() const elem = instance._getElement()
@@ -111,7 +117,8 @@ describe('Backdrop', () => {
it('if it is not "shown", should not try to remove Node on remove method', done => { it('if it is not "shown", should not try to remove Node on remove method', done => {
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: false, isVisible: false,
isAnimated: true isAnimated: true,
backdropClassName: CLASS_NAME_BACKDROP
}) })
const getElements = () => document.querySelectorAll(CLASS_BACKDROP) const getElements = () => document.querySelectorAll(CLASS_BACKDROP)
const spy = spyOn(instance, 'dispose').and.callThrough() const spy = spyOn(instance, 'dispose').and.callThrough()
@@ -135,7 +142,8 @@ describe('Backdrop', () => {
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: true, isVisible: true,
isAnimated: true, isAnimated: true,
rootElement: wrapper rootElement: wrapper,
backdropClassName: CLASS_NAME_BACKDROP
}) })
const getElements = () => document.querySelectorAll(CLASS_BACKDROP) const getElements = () => document.querySelectorAll(CLASS_BACKDROP)
@@ -157,6 +165,7 @@ describe('Backdrop', () => {
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: true, isVisible: true,
isAnimated: false, isAnimated: false,
backdropClassName: CLASS_NAME_BACKDROP,
clickCallback: () => spy() clickCallback: () => spy()
}) })
const endTest = () => { const endTest = () => {
@@ -179,7 +188,8 @@ describe('Backdrop', () => {
it('if it is animated, should show and hide backdrop after counting transition duration', done => { it('if it is animated, should show and hide backdrop after counting transition duration', done => {
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: true, isVisible: true,
isAnimated: true isAnimated: true,
backdropClassName: CLASS_NAME_BACKDROP
}) })
const spy2 = jasmine.createSpy('spy2') const spy2 = jasmine.createSpy('spy2')
@@ -202,7 +212,8 @@ describe('Backdrop', () => {
const spy = jasmine.createSpy('spy', getTransitionDurationFromElement) const spy = jasmine.createSpy('spy', getTransitionDurationFromElement)
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: true, isVisible: true,
isAnimated: false isAnimated: false,
backdropClassName: CLASS_NAME_BACKDROP
}) })
const spy2 = jasmine.createSpy('spy2') const spy2 = jasmine.createSpy('spy2')
@@ -219,7 +230,8 @@ describe('Backdrop', () => {
it('if it is not "shown", should not call delay callbacks', done => { it('if it is not "shown", should not call delay callbacks', done => {
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: false, isVisible: false,
isAnimated: true isAnimated: true,
backdropClassName: CLASS_NAME_BACKDROP
}) })
const spy = jasmine.createSpy('spy', getTransitionDurationFromElement) const spy = jasmine.createSpy('spy', getTransitionDurationFromElement)
@@ -234,7 +246,8 @@ describe('Backdrop', () => {
describe('rootElement initialization', () => { describe('rootElement initialization', () => {
it('Should be appended on "document.body" by default', done => { it('Should be appended on "document.body" by default', done => {
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: true isVisible: true,
backdropClassName: CLASS_NAME_BACKDROP
}) })
const getElement = () => document.querySelector(CLASS_BACKDROP) const getElement = () => document.querySelector(CLASS_BACKDROP)
instance.show(() => { instance.show(() => {
@@ -246,7 +259,8 @@ describe('Backdrop', () => {
it('Should find the rootElement if passed as a string', done => { it('Should find the rootElement if passed as a string', done => {
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: true, isVisible: true,
rootElement: 'body' rootElement: 'body',
backdropClassName: CLASS_NAME_BACKDROP
}) })
const getElement = () => document.querySelector(CLASS_BACKDROP) const getElement = () => document.querySelector(CLASS_BACKDROP)
instance.show(() => { instance.show(() => {
@@ -264,7 +278,8 @@ describe('Backdrop', () => {
const wrapper = fixtureEl.querySelector('#wrapper') const wrapper = fixtureEl.querySelector('#wrapper')
const instance = new Backdrop({ const instance = new Backdrop({
isVisible: true, isVisible: true,
rootElement: wrapper rootElement: wrapper,
backdropClassName: CLASS_NAME_BACKDROP
}) })
const getElement = () => document.querySelector(CLASS_BACKDROP) const getElement = () => document.querySelector(CLASS_BACKDROP)
instance.show(() => { instance.show(() => {
+4
View File
@@ -98,6 +98,10 @@
&.show { opacity: $modal-backdrop-opacity; } &.show { opacity: $modal-backdrop-opacity; }
} }
.offcanvas-backdrop {
@extend .modal-backdrop;
}
// Modal header // Modal header
// Top section of the modal w/ title and dismiss // Top section of the modal w/ title and dismiss
.modal-header { .modal-header {