Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Mouse events have key events rule #849

Merged

Conversation

lizzzp1
Copy link
Contributor

@lizzzp1 lizzzp1 commented Mar 14, 2019

PR checklist

Overview of change:

#279
Adds rule for Enforce that onMouseOver/onMouseOut are accompanied by onFocus/onBlur for keyboard-only users.
Planning on adding the next few, but starting here to make sure this is heading in the right direction.

Is there anything you'd like reviewers to focus on?

README.md Outdated Show resolved Hide resolved
@lizzzp1 lizzzp1 marked this pull request as ready for review March 16, 2019 19:05
Copy link

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Code looks great - just waiting on tests to capture a few edge cases. Thanks!

src/reactA11yMouseEventHasKeyEventRule.ts Outdated Show resolved Hide resolved
@JoshuaKGoldberg JoshuaKGoldberg added the PR: Waiting for Author Changes have been requested that the pull request author should address. label Mar 21, 2019
Copy link
Contributor

@IllusionMH IllusionMH left a comment

Choose a reason for hiding this comment

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

Only one note abotu function placement, otherwise looks good.

src/reactA11yMouseEventHasKeyEventRule.ts Outdated Show resolved Hide resolved
@JoshuaKGoldberg JoshuaKGoldberg added PR: Waiting for Reviewer A repository maintainer should take a look at the pull request soon! and removed PR: Waiting for Author Changes have been requested that the pull request author should address. labels Mar 23, 2019
<div onMouseOver={() => {}} {...props} />
<div onMouseOut={() => {}} {...props} />
<div />
<div {...props} />

Choose a reason for hiding this comment

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

These four cases, where the line starts with <, are invalid TypeScript. You'll need to store these in a variable as with the other cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh oops.
Ok, so

const foo = <div onMouseOver={() => {}} {...props} />
const bar = <div onMouseOut={() => {}} {...props} />

does complain, which makes sense. So do you just ignore elements with spread attributes?

Choose a reason for hiding this comment

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

I think so, yeah. Without a program's type checker there's no way to know if they're valid.

Copy link

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Almost! Just fixing up the test cases.

@JoshuaKGoldberg JoshuaKGoldberg added PR: Waiting for Author Changes have been requested that the pull request author should address. and removed PR: Waiting for Reviewer A repository maintainer should take a look at the pull request soon! labels Mar 24, 2019
const Foo = (<div onMouseOver={() => {}} {...props} />)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [onMouseOver must be accompanied by onFocus.]
const Bar = (<div onMouseOut={() => {}} {...props} />)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [onMouseOut must be accompanied by onBlur.]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Complains for now.

Choose a reason for hiding this comment

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

@lizzzp1 could you change it to not complain if there's a ..., actually? It would be annoying to have a ...props that includes the correct corresponding onBlue/onFocus and still have this complain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought that required the type checker that was a follow up? I'm really confused now.

Choose a reason for hiding this comment

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

The type checker is just required to know whether the ...props contains the corresponding onBlur/onFocus. Without the type checker, we have know way of knowing whether a JSX element that contains ...props violates the rule or not. Until the type checker logic is added, that leaves us with two options:

  • Ignore ...props _(pretend they aren't therE): the rule would give complaints in some places where it shouldn't
  • Assume ...props contains the right attributes: the rule wouldn't give complaints in some places where it should

In order to not irritate folks with false complaints, IMO we should err on the side of caution with the first option.

Does that seem reasonable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, if props are ignored then it would complain like the above wouldn't it? Wouldn't the 2nd option be better so it doesn't complain if it encounters spread props?

Choose a reason for hiding this comment

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

Oh agh sorry I meant to say the second option! You're absolutely correct 😅

const Foo = (<div onMouseOver={() => {}} {...props} />)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [onMouseOver must be accompanied by onFocus.]
const Bar = (<div onMouseOut={() => {}} {...props} />)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [onMouseOut must be accompanied by onBlur.]

Choose a reason for hiding this comment

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

@lizzzp1 could you change it to not complain if there's a ..., actually? It would be annoying to have a ...props that includes the correct corresponding onBlue/onFocus and still have this complain.

Copy link

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

This looks superb, thanks for working through reviews on this @lizzzp1! 🙌

@JoshuaKGoldberg JoshuaKGoldberg merged commit f3229e0 into microsoft:master Apr 22, 2019
@IllusionMH IllusionMH added this to the 6.2.0-beta milestone May 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
PR: Waiting for Author Changes have been requested that the pull request author should address.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

new a11y rule: mouse-events-have-key-events
3 participants