Skip to content

Commit

Permalink
change 'onclick' method to config property
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed Apr 11, 2021
1 parent 05ca443 commit 522dfef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions js/src/util/backdrop.js
Expand Up @@ -11,13 +11,15 @@ import { emulateTransitionEnd, execute, getTransitionDurationFromElement, reflow
const Default = {
isVisible: true, // if false, we use the backdrop helper without adding any element to the dom
isAnimated: false,
rootElement: document.body // give the choice to place backdrop under different elements
rootElement: document.body, // give the choice to place backdrop under different elements
clickCallback: null
}

const DefaultType = {
isVisible: 'boolean',
isAnimated: 'boolean',
rootElement: 'element'
rootElement: 'element',
clickCallback: '(function|null)'
}
const NAME = 'backdrop'
const CLASS_NAME_BACKDROP = 'modal-backdrop'
Expand All @@ -33,10 +35,6 @@ class Backdrop {
this._element = null
}

onClick(callback) {
this._clickCallback = callback
}

show(callback) {
if (!this._config.isVisible) {
execute(callback)
Expand Down Expand Up @@ -103,7 +101,7 @@ class Backdrop {
this._config.rootElement.appendChild(this._getElement())

EventHandler.on(this._getElement(), EVENT_MOUSEDOWN, () => {
execute(this._clickCallback)
execute(this._config.clickCallback)
})

this._isAppended = true
Expand Down
4 changes: 2 additions & 2 deletions js/tests/unit/util/backdrop.spec.js
Expand Up @@ -164,9 +164,9 @@ describe('Backdrop', () => {

const instance = new Backdrop({
isVisible: true,
isAnimated: false
isAnimated: false,
clickCallback: () => spy()
})
instance.onClick(() => spy())
const endTest = () => {
setTimeout(() => {
expect(spy).toHaveBeenCalled()
Expand Down

0 comments on commit 522dfef

Please sign in to comment.