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

Event: Fix delegated radio events when arrow keys are used #2617

Closed
wants to merge 2 commits into from

Conversation

dmethvin
Copy link
Member

Fixes gh-2343, gh-2410

This turned out to be trickier than I hoped. Click events that are fired by $.fn.trigger() don't have an event.button set at all. Also I couldn't figure out a way to test this, for similar reasons. I can set up a unit test that has a fake event with similar incorrect settings as Firefox gives us, but that seems like a bad idea. Ideally this would be a feature detect but that is also impossible since it requires a real user-initiated click and not a fake one.

@markelog
Copy link
Member

How about we create a test in https://github.com/jquery/jquery/tree/master/test/integration, right now, @timmywil checks this before the release and later, we will automate it - #2329

// Support: Firefox<=42+
// Avoid non-left-click in FF but don't block IE radio events (#3861, gh-2343)
if ( delegateCount && cur.nodeType &&
( event.type !== "click" || isNaN( event.button ) || event.button < 1 ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about … && !(event.type === "click" && event.button >= 1)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, the original !event.button handles both 0 and undefined but it's not obvious. The three conditions make it a bit clearer I think and the second two checks aren't reached except on click events, which are low frequency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true both ways, and there's no practical performance difference. It's just smaller without the isNaN, and the explanation is already handled pretty well by our support comment (which could become "Suppress clicks of non-primary mouse buttons" if you want to increase clarity a little more).

@dmethvin dmethvin closed this in c82a668 Oct 18, 2015
@timmywil timmywil deleted the 2343-delegated-radio branch October 18, 2015 17:30
dmethvin added a commit that referenced this pull request Oct 25, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants