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

removed e.stopPropagation() from onKeyDown #2354

Merged
merged 7 commits into from
Oct 12, 2021

Conversation

Anuragtech02
Copy link
Contributor

Closes #2263

✅ Pull Request Checklist:

📝 Test Instructions:

In order to test the PR, you can go the this link and try accessing the select box with arrow keys on the keyboard. Keep the terminal open along with this to check if it logs any errors.
This PR fixes the error mentioned in the issue.

@Anuragtech02
Copy link
Contributor Author

Hey, @dannify I've simply deleted the stopPropagation function which in turn solves the issue for us! Let me know if I have to make any more changes.

@Anuragtech02
Copy link
Contributor Author

Hey @dannify please let me know if this is okay

@LFDanLu
Copy link
Member

LFDanLu commented Sep 28, 2021

@Anuragtech02 looks like one of the tests is failing (useMenuTrigger test). Mind mocking the isPropagationStopped call in that test to fix it?

    let isPropagationStopped = jest.fn();
     ....
    // triggers event if defaultPrevented is not true and it matches one of the keys
    menuTriggerProps.onKeyDown({
      pointerType: 'not keyboard',
      defaultPrevented: false,
      key: 'ArrowUp',
      preventDefault,
      stopPropagation,
      isPropagationStopped
    });
....

@Anuragtech02
Copy link
Contributor Author

Sure, I'll give it a try!

@Anuragtech02
Copy link
Contributor Author

Hey @LFDanLu, seems like some tests are still failing! I'm not able to understand what are they. Please let me know I'll fix those.

LFDanLu
LFDanLu previously approved these changes Oct 7, 2021
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

LGTM. @Anuragtech02 the tests are passing on the commit, what test failures are you running into?

@Anuragtech02
Copy link
Contributor Author

Surprisingly the tests passed! I don't know why but I did have one test which failed but now all are passing. Anyways, let me know if I have to make any more changes.

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

So I was just testing this out with yarn start:docs, I'm still seeing the warning. It seems to be because we spread the synthetic event into a new object https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/interactions/src/createEventHandler.ts#L27
this results in all getters on the event object being invoked, of which isPropagationStopped is one and it gets frozen as functionThatReturnsFalse
I think we just need one adjustment though.
Add this to the event in the createEventHandler

      isPropagationStopped(): boolean {
        return e.isPropagationStopped();
      }

UPDATE: Talked with Daniel some more, we've come to the conclusion that even with the change I requested here, it'll still have the same problem, due to the fact that we call stopPropagation AFTER the handler, meaning useMenuTrigger won't be able to check if propagation has been stopped yet. All that to say, let's just delete the two stopPropagation lines. Sorry for the confusion.

@Anuragtech02
Copy link
Contributor Author

@snowystinger I'm sorry but I didn't quite get it. Am I supposed to remove the e.stopPropagation() line completely and not even check if propagation is stopped?

@snowystinger
Copy link
Member

Correct. We're going to remove it. Reasoning being that you very likely need to usePress since we're passing press events around, and there are a few other things that just make it easier if you use it with react aria, so in all likelihood, we've already stopped propagation at this point. No need to check.

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

LGTM, tested locally and confirmed that the warning no long appears. Apologies for the back and forth regarding the fix, and thanks for working on this!

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

lgtm, and as @LFDanLu said, thanks for the patience!

@LFDanLu LFDanLu merged commit 04c224c into adobe:main Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stopPropagation error logs in useSelect
3 participants