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

MultiSelect tagInputProps: How to avoid input focus when onRemove triggered? #3310

Open
MichaelLonin opened this issue Jan 22, 2019 · 7 comments

Comments

@MichaelLonin
Copy link

Environment

  • Package version(s): 2
  • Browser and OS versions:

Question

Is it possible to prevent input focus when onRemove triggered? Thanks in advance!

@tnrich
Copy link
Contributor

tnrich commented May 3, 2019

I think what MichaelLonin is maybe getting at here is that there seems to be no way currently to stop the select popover from opening when the tag X is clicked:

clickingRemoveOpensPopup

I definitely think that functionality should be optional. Unfortunately the onRemove handler signature looks like this:

handleTagRemove = (string, index) => {...}

So we can't manually stop event propagation/prevent default ourselves.

Thoughts @giladgray @adidahiya ?

@tsnevillecom
Copy link

Removing the tags should not open the popover. The intent is not to select new options when removing.

@grancalavera
Copy link
Contributor

@adidahiya I can think of two ways of fixing this:

  1. Always stopping the on click event propagation when a tag is removed
  2. Passing the original click event as an extra argument to handleTagRemove and letting consumers stop propagation if required.

I'm more than happy to implement any of those solutions, or any other solution that you may suggest.

@grancalavera
Copy link
Contributor

grancalavera commented Apr 1, 2020

@adidahiya ok I implemented solution 1 since it's the most straight forward and doesn't require API changes. Please take a look and let me know if you want any changes.

@grancalavera
Copy link
Contributor

grancalavera commented Apr 10, 2020

Moving my comments from #4034 here, this might be the right place to continue the conversation

@adidahiya what about this?

Another approach would be to pass the event to consumers of TagInput

Something else we could try is handling the event propagation in MultiSelect, and assuming we can know the identity of the event target, ignore click events originating from removing a tag. Not sure if that's even possible, but I'm happy to explore that path.

What do you think?

@adidahiya
Copy link
Contributor

@grancalavera I would still like to avoid "ignoring" clicks or stopping event propagation. Can you implement a new prop on TagInput which prevents the input from getting focus on tag remove (and enable that prop by default in MultiSelect)? I haven't looked into it deeply but there seems to be a fair amount of focus management in that component which could be tweaked.

@grancalavera
Copy link
Contributor

Cool, I'll start looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants