Skip to content

Commit

Permalink
make offcanvas to open on window load event
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed Mar 17, 2021
1 parent 6b95bb1 commit a5a7ffd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
{
"path": "./dist/js/bootstrap.js",
"maxSize": "29 kB"
"maxSize": "29.02 kB"
},
{
"path": "./dist/js/bootstrap.min.js",
Expand Down
2 changes: 1 addition & 1 deletion js/src/offcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (
})

EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
SelectorEngine.find(OPEN_SELECTOR).forEach(el => new Offcanvas(el).show())
SelectorEngine.find(OPEN_SELECTOR).forEach(el => (Data.get(el, DATA_KEY) || new Offcanvas(el)).show())
})

/**
Expand Down
17 changes: 17 additions & 0 deletions js/tests/unit/offcanvas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,23 @@ describe('Offcanvas', () => {

offCanvas.show()
})

it('on window load, should make visible an offcanvas element, if its markup contains class "show"', done => {
fixtureEl.innerHTML = '<div class="offcanvas show"></div>'

const offCanvasEl = fixtureEl.querySelector('div')
spyOn(Offcanvas.prototype, 'show').and.callThrough()

offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
done()
})

window.dispatchEvent(createEvent('load'))

const instance = Offcanvas.getInstance(offCanvasEl)
expect(instance).not.toBeNull()
expect(Offcanvas.prototype.show).toHaveBeenCalled()
})
})

describe('hide', () => {
Expand Down

0 comments on commit a5a7ffd

Please sign in to comment.