diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/src/modal.js | 6 | ||||
-rw-r--r-- | js/tests/unit/modal.spec.js | 16 |
2 files changed, 10 insertions, 12 deletions
diff --git a/js/src/modal.js b/js/src/modal.js index ca77359cab..d5f1c8c9ae 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -60,7 +60,6 @@ const EVENT_MOUSEUP_DISMISS = `mouseup.dismiss${EVENT_KEY}` const EVENT_MOUSEDOWN_DISMISS = `mousedown.dismiss${EVENT_KEY}` const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}` -const CLASS_NAME_SCROLLABLE = 'modal-dialog-scrollable' const CLASS_NAME_SCROLLBAR_MEASURER = 'modal-scrollbar-measure' const CLASS_NAME_BACKDROP = 'modal-backdrop' const CLASS_NAME_OPEN = 'modal-open' @@ -249,11 +248,10 @@ class Modal { this._element.style.display = 'block' this._element.removeAttribute('aria-hidden') this._element.setAttribute('aria-modal', true) + this._element.scrollTop = 0 - if (this._dialog.classList.contains(CLASS_NAME_SCROLLABLE) && modalBody) { + if (modalBody) { modalBody.scrollTop = 0 - } else { - this._element.scrollTop = 0 } if (transition) { diff --git a/js/tests/unit/modal.spec.js b/js/tests/unit/modal.spec.js index c5fbc3a273..52676844f4 100644 --- a/js/tests/unit/modal.spec.js +++ b/js/tests/unit/modal.spec.js @@ -382,40 +382,40 @@ describe('Modal', () => { modal.show() }) - it('should set modal body scroll top to 0 if .modal-dialog-scrollable', done => { + it('should set .modal\'s scroll top to 0', done => { fixtureEl.innerHTML = [ '<div class="modal fade">', - ' <div class="modal-dialog modal-dialog-scrollable">', - ' <div class="modal-body"></div>', + ' <div class="modal-dialog">', ' </div>', '</div>' ].join('') const modalEl = fixtureEl.querySelector('.modal') - const modalBody = modalEl.querySelector('.modal-body') const modal = new Modal(modalEl) modalEl.addEventListener('shown.bs.modal', () => { - expect(modalBody.scrollTop).toEqual(0) + expect(modalEl.scrollTop).toEqual(0) done() }) modal.show() }) - it('should set .modal\'s scroll top to 0 if .modal-dialog-scrollable and modal body do not exists', done => { + it('should set modal body scroll top to 0 if modal body do not exists', done => { fixtureEl.innerHTML = [ '<div class="modal fade">', - ' <div class="modal-dialog modal-dialog-scrollable">', + ' <div class="modal-dialog">', + ' <div class="modal-body"></div>', ' </div>', '</div>' ].join('') const modalEl = fixtureEl.querySelector('.modal') + const modalBody = modalEl.querySelector('.modal-body') const modal = new Modal(modalEl) modalEl.addEventListener('shown.bs.modal', () => { - expect(modalEl.scrollTop).toEqual(0) + expect(modalBody.scrollTop).toEqual(0) done() }) |