Skip to content

Commit

Permalink
prevent navigating to area href when modal target. fixes #18796
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbeatty committed Aug 4, 2016
1 parent 0416f76 commit bfa714a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ const Modal = (($) => {
let config = $(target).data(DATA_KEY) ?
'toggle' : $.extend({}, $(target).data(), $(this).data())

if (this.tagName === 'A') {
if (this.tagName === 'A' || this.tagName === 'AREA') {
event.preventDefault()
}

Expand Down
22 changes: 22 additions & 0 deletions js/tests/unit/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,26 @@ $(function () {
})
.bootstrapModal('show')
})

QUnit.test('should not follow link in area tag', function (assert) {
assert.expect(2)
var done = assert.async()

$('<map><area id="test" shape="default" data-toggle="modal" data-target="#modal-test" href="demo.html"/></map>')
.appendTo('#qunit-fixture')

$('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div></div>')
.appendTo('#qunit-fixture')

$('#test')
.on('click.bs.modal.data-api', function (event) {
assert.notOk(event.isDefaultPrevented(), 'navigating to href will happen')

setTimeout(function () {
assert.ok(event.isDefaultPrevented(), 'model shown instead of navigating to href')
done()
}, 1)
})
.trigger('click')
})
})

0 comments on commit bfa714a

Please sign in to comment.