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

SearchBox input should receive focus after clearing #775

Closed
petermakowski opened this issue May 11, 2022 · 5 comments · Fixed by #830
Closed

SearchBox input should receive focus after clearing #775

petermakowski opened this issue May 11, 2022 · 5 comments · Fixed by #830

Comments

@petermakowski
Copy link
Contributor

petermakowski commented May 11, 2022

Related to canonical/maas.io#463

Steps to reproduce

  1. Open https://canonical.github.io/react-components/?path=/story/searchbox--external-state
  2. Focus the search field.
  3. Click the clear button.

What actually happens

Any text you start entering will be lost, because the search field is no longer focused.

What should happen

The text you enter appears in the search field because it's automatically focused.

@huwshimi
Copy link
Collaborator

I'm not sure if this is possible, but it might be nice if this only restored the focus to the input if the input had focus when the clear button was clicked. This might be better for MAAS and JAAS-dashboard where the clear button is more of a "clear current filters" action that can done somewhat independently of typing searches. This might be especially true for the search and filter pattern used in JAAS (and soon to be used in MAAS) where focusing on the search input opens up a panel.

petermakowski added a commit to petermakowski/react-components that referenced this issue Sep 13, 2022
@petermakowski
Copy link
Contributor Author

it might be nice if this only restored the focus to the input if the input had focus when the clear button was clicked.

This is possible, but I'm not sure it's a good idea - if you're using keyboard instead of mouse, the input field will never be focused while you press the clear button.

@bartaz
Copy link
Member

bartaz commented Sep 13, 2022

This is possible, but I'm not sure it's a good idea - if you're using keyboard instead of mouse, the input field will never be focused while you press the clear button.

Even if you are using a mouse I think as soon as you click focus will move to the button.

@bartaz
Copy link
Member

bartaz commented Sep 13, 2022

It seems it may have to be an optional prop? Because in cases when it is a purely text search box, you probably want to focus it after clearing. But if it is a search&filter pattern which has more interactive functionality on focus, clearing likely means "get rid of everything and close the dropdown" - so we don't want to focus back.

So SearchBox (meant for text search functionality) could have focus on clearing by default, but if it is reused in other components we may need an option for opt-out disabling of this.

@petermakowski
Copy link
Contributor Author

petermakowski commented Sep 13, 2022

It seems it may have to be an optional prop?

Good idea, updated the PR and added shouldRefocusAfterReset prop which has a false value by default.

ClementChaumel added a commit to petermakowski/react-components that referenced this issue Feb 14, 2023
ClementChaumel added a commit that referenced this issue Feb 14, 2023
…ring-#775

feat: focus SearchBox input after clearing #775
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.

3 participants