Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/hooks/useCioAutocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ const useCioAutocomplete = (options: UseCioAutocompleteOptions) => {
const { index, sectionId } = getItemPosition({ item, items });
const sectionItemTestId = `cio-item-${sectionId?.replace(' ', '')}`;

// Products always have links, Search Suggestions with getSearchResultsUrl have links
const hasLink =
item.data?.url || (item.section === 'Search Suggestions' && getSearchResultsUrl) || false;

const nonInteractiveItemsProps = {
tabIndex: 0,
onKeyDown: (event: React.KeyboardEvent) => {
const { code, key } = event;
const isEnter = code === 'Enter' || key === 'Enter';

if (isEnter) {
event.preventDefault();
// Trigger default click behavior
getItemPropsDownShift({ item, index }).onClick(event);
}
},
};

return {
...getItemPropsDownShift({ item, index }),
// @deprecated `sectionItemTestId` will be removed as a className in the next major version
Expand All @@ -126,6 +144,7 @@ const useCioAutocomplete = (options: UseCioAutocompleteOptions) => {
'data-cnstrc-item-group': item.groupId,
'data-cnstrc-item-name': item.value,
'data-cnstrc-item-id': item.data?.id,
...(hasLink ? {} : nonInteractiveItemsProps),
};
},
getInputProps: () => ({
Expand Down
Loading