Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert backdrop utilization, handling clicks over modal #36324

Merged
merged 2 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
},
{
"path": "./dist/js/bootstrap.bundle.js",
"maxSize": "42.75 kB"
"maxSize": "43.0 kB"
},
{
"path": "./dist/js/bootstrap.bundle.min.js",
"maxSize": "22.75 kB"
},
{
"path": "./dist/js/bootstrap.esm.js",
"maxSize": "27.5 kB"
"maxSize": "27.75 kB"
},
{
"path": "./dist/js/bootstrap.esm.min.js",
Expand Down
33 changes: 18 additions & 15 deletions js/src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const EVENT_HIDDEN = `hidden${EVENT_KEY}`
const EVENT_SHOW = `show${EVENT_KEY}`
const EVENT_SHOWN = `shown${EVENT_KEY}`
const EVENT_RESIZE = `resize${EVENT_KEY}`
const EVENT_CLICK_DISMISS = `click.dismiss${EVENT_KEY}`
const EVENT_KEYDOWN_DISMISS = `keydown.dismiss${EVENT_KEY}`
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`

Expand Down Expand Up @@ -152,22 +153,9 @@ class Modal extends BaseComponent {

// Private
_initializeBackDrop() {
const clickCallback = () => {
if (this._config.backdrop === 'static') {
this._triggerBackdropTransition()
return
}

this.hide()
}

// 'static' option will be translated to true, and booleans will keep their value
const isVisible = Boolean(this._config.backdrop)

return new Backdrop({
isVisible,
isAnimated: this._isAnimated(),
clickCallback: isVisible ? clickCallback : null
isVisible: Boolean(this._config.backdrop), // 'static' option will be translated to true, and booleans will keep their value,
isAnimated: this._isAnimated()
})
}

Expand Down Expand Up @@ -232,6 +220,21 @@ class Modal extends BaseComponent {
this._adjustDialog()
}
})

EventHandler.on(this._element, EVENT_CLICK_DISMISS, event => {
if (event.target !== event.currentTarget) { // click is inside modal-dialog
return
}

if (this._config.backdrop === 'static') {
this._triggerBackdropTransition()
return
}

if (this._config.backdrop) {
this.hide()
}
})
}

_hideModal() {
Expand Down
10 changes: 3 additions & 7 deletions js/tests/unit/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,8 @@ describe('Modal', () => {
modalEl.addEventListener('shown.bs.modal', () => {
const spy = spyOn(modal, '_queueCallback').and.callThrough()

const mouseOverEvent = createEvent('mousedown')
const backdrop = document.querySelector('.modal-backdrop')

backdrop.dispatchEvent(mouseOverEvent)
backdrop.dispatchEvent(mouseOverEvent)
modalEl.click()
modalEl.click()

setTimeout(() => {
expect(spy).toHaveBeenCalledTimes(1)
Expand Down Expand Up @@ -714,8 +711,7 @@ describe('Modal', () => {
const modalEl = fixtureEl.querySelector('.modal')
const modal = new Modal(modalEl)
modalEl.addEventListener('shown.bs.modal', () => {
const mouseOverEvent = createEvent('mousedown')
document.querySelector('.modal-backdrop').dispatchEvent(mouseOverEvent)
modalEl.click()
})

modalEl.addEventListener('hidden.bs.modal', () => {
Expand Down
1 change: 0 additions & 1 deletion scss/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
height: 100%;
overflow-x: hidden;
overflow-y: auto;
pointer-events: none;
// Prevent Chrome on Windows from adding a focus outline. For details, see
// https://github.com/twbs/bootstrap/pull/10951.
outline: 0;
Expand Down