Skip to content

Connect: Improve focus management in search bar#24665

Merged
ravicious merged 1 commit intoravicious/error-handlingfrom
ravicious/search-focus
Apr 17, 2023
Merged

Connect: Improve focus management in search bar#24665
ravicious merged 1 commit intoravicious/error-handlingfrom
ravicious/search-focus

Conversation

@ravicious
Copy link
Copy Markdown
Member

This PR makes it so that after you open the resource search errors modal and close it using a mouse, the focus is brought back to the search input.

Arguably, just the call in lockOpen would have been enough but in theory the focus could be lost through other means (like a right click on a search result), so I left the focus calls in open too.

To reproduce the issue on the previous version of the search bar:

  1. Log in to a cluster.
  2. Make the cluster offline by either stopping it or disconnecting from the internet.
  3. Try to search for something using the search bar at the top.
  4. Click "Show details" next to an item about the errors in the results.
  5. Close the modal using a mouse.
  6. The list of results should stay open and the search input should have focus now.

Comment on lines 128 to 129
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I couldn't find a way to write a test for this part. I think it has to do with how the browser and React interact together so it might be hard to reproduce it in a non-browser environment like our tests.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, it can be possible.

@ravicious ravicious removed the request for review from kimlisa April 17, 2023 11:28
@ravicious ravicious force-pushed the ravicious/search-focus branch from 2319ff0 to 8df8e93 Compare April 17, 2023 11:30
@ravicious ravicious merged commit fae3091 into ravicious/error-handling Apr 17, 2023
@ravicious ravicious deleted the ravicious/search-focus branch April 17, 2023 12:39
ravicious added a commit that referenced this pull request Apr 17, 2023
* Move tshd test helpers to a better location

* Support passing no props to tshd test helpers

* Refactor ResourcesService getServerByHostname tests

* Move pluralize to shared package

* SearchContext: Rename `opened` to `isOpen`

* ActionPicker story: Show auxiliary items in a separate column

* ActionPicker: Split getClusterName into two functions

getClusterName used to not return the name of the cluster if there's only
a single cluster present. Some places needed to get the cluster name
no matter what, such as the modal with resource errors that will be added
to ActionPicker.

* Refactor resource search to use Promise.allSettled

* useSearchAttempts has been renamed to useActionAttempts
* useActionAttempts returns resourceSearchAttempt in order to supply errors
  from ResourcesService.searchResources to ActionPicker.

* SearchContext: Implement lockOpen

We'll want to display error details in a modal. While the user interacts
with the modal, we don't want to close the search bar and reset the results.

So instead, we are going to force the search bar to stay open until the
user closes the modal. This will use the lockOpen function from this commit.

* Add modal for showing resource search errors

* Refactor mockedSearchContext to not be a top-level mutable var

* Show an item in search bar with resource search errors

* ResourceSearchError: Add instanceof check to tests, include clusterUri in message

* Make isLockedOpen into a ref

* Use table tests for lockOpen tests

* Revert "Make isLockedOpen into a ref"

This reverts commit 07f4206.

* Move capitalization to ResourceSearchError.messageWithClusterName

* ResourceSearchError: Use `public` in constructor

* Connect: Improve focus management in search bar (#24665)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants