visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.67k stars 687 forks source link

Incorrect fallback from event.which to event.button #545

Open jstanley0 opened 4 years ago

jstanley0 commented 4 years ago

This line of code is incorrect:

return null == e.which ? e.button : e.which;

because which returns 1 to mean the primary button, and button returns 0 to mean the same thing.

When calling clickHandler from a React onClick, a synthetic event is supplied which implements button but not which. As a result, _which returns 0 and the event handler skips the event because it was expecting 1.

alirezakazemeini commented 1 year ago

you can use:

return e.button !== undefined ? e.button : e.which;

With this modification, if e.button is available, it will be returned. Otherwise, if e.button is undefined, it will fall back to e.which. This way, you ensure consistent behavior for determining the primary button regardless of the event system being used.

I also edited this in the code and requested a pull request