algolia / instantsearch

⚡️ Libraries for building performant and instant search and recommend experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/
MIT License
3.73k stars 526 forks source link

fix(refinement-list): re-apply focus on facet checkbox after render #6392

Closed dhayab closed 1 month ago

dhayab commented 1 month ago

Summary

In InstantSearch.js, focus is lost when toggling a facet value in a refinement list. This is because the component is destroyed and re-created during re-render, and Preact does not explicitly refocus the newly created component (whereas React does it).

This PR adds code that stores the last refined value and applies focus to its DOM element on re-render.

CR-6976

codesandbox-ci[bot] commented 1 month ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7e5fbf58c0901cc70085c1e2476f2813283ecf4c:

Sandbox Source
example-instantsearch-getting-started Configuration
example-react-instantsearch-getting-started Configuration
example-react-instantsearch-next-app-dir-example Configuration
example-react-instantsearch-next-routing-example Configuration
example-vue-instantsearch-getting-started Configuration
Haroenv commented 1 month ago

I guess it won't matter if it happens anywhere else? focus can still be lost on a link right?

dhayab commented 1 month ago

is this happening anywhere else? What makes refinement list special that it doesn't need to be fixed somewhere else? no form elements in other components?

The loss of focus happens with all refinement widgets. I'm on the fence about adding this extra code to all widgets. It makes more sense for the refinement list as it allows proper toggling with the keyboard. Wdyt?