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

Ability to change element focus between type events #295

Closed
kayleighridd opened this issue May 21, 2020 · 5 comments
Closed

Ability to change element focus between type events #295

kayleighridd opened this issue May 21, 2020 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@kayleighridd
Copy link
Contributor

kayleighridd commented May 21, 2020

Currently all the keyUp, keyPress and keyDown events within type fire on the specified element, but it would be useful to be able to fire these on the currently active element so that focus can change between these events.

My use case is a multi input field where I change the focus as input reaches its max character length so that the value is added to the next input.
I do this by changing the input focus on the keyDown event so that the keyUp event fires in another input.
When I am testing, I'd like to specify a type event on one input, but confirm that the focus has moved and the value added to the next input.

Here is a quick sandbox to illustrate my use case:
https://codesandbox.io/s/userevents-type-events-firing-on-same-element-not-active-element-229sk
(Code sandbox doesn't seem to respect the jsdom-sixteen test env so the error isn't correct, but hopefully it gives some context)

@kentcdodds
Copy link
Member

Hi @kayleighridd,

I can visualize the kind of experience you're describing... What if instead of firing all the events on the element that's passed, we first focus that element and then reference the document.activeElement? That's actually more like what the user's doing when they type and it should support the situation you're describing. What do you think?

@kayleighridd
Copy link
Contributor Author

@kentcdodds yes, that would be ideal 🎉
I assumed this would be a feature that we can turn on through options so it's not a breaking change, but are you suggesting this should always be the behaviour?

@kentcdodds
Copy link
Member

I would expect this to be more of a bug fix than a breaking change. It probably should always have done this.

Would you be interested in making a pull request for this? I notice your github profile doesn't have public activity, so if this is new for you that's great! I'm happy to help you along as much as you'd like :)

@kentcdodds kentcdodds added bug Something isn't working good first issue Good for newcomers help wanted labels May 22, 2020
@kayleighridd
Copy link
Contributor Author

Okay great. Yeah, I'm happy to raise a pull request for this, thanks!

@kayleighridd kayleighridd changed the title [feature request] Ability to change element focus between type events Ability to change element focus between type events May 25, 2020
@kayleighridd
Copy link
Contributor Author

👋 I've raised a PR for this here: #299
I'm not sure how to link it to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants