Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't fire click event if default is prevented on mousedown for a drag event #6697

Merged
merged 1 commit into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ui/bind_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function bindHandlers(map: Map, options: {interactive: boolean})
const el = map.getCanvasContainer();
let contextMenuEvent = null;
let mouseDown = false;
let startPos = null;

for (const name in handlers) {
(map: any)[name] = new handlers[name](map, options);
Expand Down Expand Up @@ -56,6 +57,7 @@ export default function bindHandlers(map: Map, options: {interactive: boolean})

function onMouseDown(e: MouseEvent) {
mouseDown = true;
startPos = DOM.mousePos(el, e);

const mapEvent = new MapMouseEvent('mousedown', map, e);
map.fire(mapEvent);
Expand Down Expand Up @@ -149,7 +151,10 @@ export default function bindHandlers(map: Map, options: {interactive: boolean})
}

function onClick(e: MouseEvent) {
map.fire(new MapMouseEvent('click', map, e));
const pos = DOM.mousePos(el, e);
if (pos.equals(startPos)) {
map.fire(new MapMouseEvent('click', map, e));
}
}

function onDblClick(e: MouseEvent) {
Expand Down
9 changes: 9 additions & 0 deletions test/node_modules/mapbox-gl-js-test/simulate_interaction.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions test/unit/ui/map_events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,19 @@ test(`Map#on mousedown can have default behavior prevented and still fire subseq
map.remove();
t.end();
});

test(`Map#on mousedown doesn't fire subsequent click event if mousepos changes`, (t) => {
const map = createMap();

map.on('mousedown', e => e.preventDefault());

const click = t.spy();
map.on('click', click);
const canvas = map.getCanvas();

simulate.drag(canvas, {}, {clientX: 100, clientY: 100});
t.ok(click.notCalled);

map.remove();
t.end();
});