Skip to content

Commit

Permalink
fix(start): start options should ignore disable options
Browse files Browse the repository at this point in the history
Fixes gh-573
  • Loading branch information
timmywil committed Jun 28, 2021
1 parent 148dd6e commit 77b47b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/panzoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ function Panzoom(
let y = 0
let scale = 1
let isPanning = false
zoom(options.startScale, { animate: false })
zoom(options.startScale, { animate: false, force: true })
// Wait for scale to update
// for accurate dimensions
// to constrain initial values
setTimeout(() => {
setMinMax()
pan(options.startX, options.startY, { animate: false })
pan(options.startX, options.startY, { animate: false, force: true })
})

function trigger(eventName: PanzoomEvent, detail: PanzoomEventDetail, opts: PanzoomOptions) {
Expand Down
23 changes: 23 additions & 0 deletions test/unit/panzoom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,29 @@ describe('Panzoom', () => {
assert.strictEqual(scale, 1)
})
})
describe('start options', () => {
it('ignore disablePan and disableZoom', (done) => {
const div = document.createElement('div')
document.body.appendChild(div)
const panzoom = Panzoom(div, {
disablePan: true,
disableZoom: true,
startScale: 0.5,
startX: 10,
startY: 10
})
const scale = panzoom.getScale()
assert.strictEqual(scale, 0.5)

setTimeout(() => {
const pan = panzoom.getPan()
assert.strictEqual(pan.x, 10)
assert.strictEqual(pan.y, 10)
document.body.removeChild(div)
done()
})
})
})
describe('force option', () => {
it('ignores disablePan', () => {
const div = document.createElement('div')
Expand Down

0 comments on commit 77b47b7

Please sign in to comment.