Skip to content

Conversation

dhayab
Copy link
Member

@dhayab dhayab commented Oct 15, 2025

Summary

This PR sets up a useAutocomplete() hook that:

  • generates props for autocomplete components
  • keeps an indexed items store

It centralizes keyboard support, accessibility and manages a basic state for the Autocomplete.

Keyboard navigation is based on the Editable Combobox with Grid Popup Example from WAI. This prepares us for horizontal navigation on item actions later.

Result

Preview sandbox ↗️

Copy link

codesandbox-ci bot commented Oct 15, 2025

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 f3ff03d:

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

@dhayab dhayab requested review from a team, Haroenv, aymeric-giraudet and shaejaz and removed request for a team October 15, 2025 09:26
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

I think this is good to go, although possibly a bit much focused on react and not on reuse of the code for js

getPanelProps,
getRootProps,
updateStore,
} = useAutocomplete();
Copy link
Contributor

Choose a reason for hiding this comment

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

if we'd use connectautocomplete at the level inside the index component, it could have the information and no need for a new store concept. The inconsistent part is then of course that the connector would know about the dom (unless there's a separate function that turns an autocomplete state into props. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm now using connectAutocomplete to create the items store and refine, and I'll migrate most of the state in the connector in a next PR, as well as move the prop getters to a shared part (probably ui components).

};
}, [rootRef]);

const getNextActiveDescendent = (key: string): string | undefined => {
Copy link
Contributor

Choose a reason for hiding this comment

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

this function could be declared outside of the bode of useAutocomplete if it received the state as a prop. Not sure if it would be better though.

@Haroenv Haroenv removed the request for review from aymeric-giraudet October 15, 2025 09:31
@dhayab dhayab requested a review from Haroenv October 16, 2025 15:00
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

overall good as this works, but probably can do with another refactor once js is ready

getItemProps,
getPanelProps,
getRootProps,
} = useAutocomplete({ indices });
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really get why we're using connectAutocomplete at this level and not inside the isolated index. now it seems to be scoped differently and we can't use the refine of this useautocomplete for the state of the search input

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

(itemsAcc, index) => {
const indexItems =
connectorIndices
.find(({ indexName }) => index.indexName === indexName)
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally this can be avoided if autocomplete connector is used inside the isolated index.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I'll switch this in a future PR to align JS + React implementations.

@dhayab dhayab enabled auto-merge (squash) October 17, 2025 13:42
@dhayab dhayab merged commit 14d7a4e into master Oct 17, 2025
14 checks passed
@dhayab dhayab deleted the feat/autocomplete-react-keyboard-navigation branch October 17, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants