Skip to content

Conversation

@mocca102
Copy link
Contributor

@mocca102 mocca102 commented Nov 4, 2025

Overview

  • Search Suggestion items are not keyboard accessible via the tab key

Why this happen?

  • Search Suggestion items can be

    tags which are not interactive elements by default

  • This does not happen for Produc items since they have a nested tag that's interactive

What changed

  • return tabIndex: 0 for getItemProps so every item is keyboard accessible regardless of it's section
  • Remove default keyboard tab accessibility from nested tags to avoid duplicate focus
    • If you remove tabIndex={-1} the Product items will be visited twice when you click the tab key

@mocca102 mocca102 requested a review from Mudaafi as a code owner November 4, 2025 12:45
Copilot AI review requested due to automatic review settings November 4, 2025 12:45
@mocca102 mocca102 requested a review from esezen as a code owner November 4, 2025 12:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes keyboard accessibility for Search Suggestion items in the autocomplete component by ensuring all suggestion items are focusable via the Tab key. Previously, Search Suggestion items (rendered as <p> tags) were not keyboard accessible, while Product items were accessible due to their nested <a> tags.

Key Changes:

  • Added tabIndex: 0 to all autocomplete items via getItemProps to enable keyboard navigation
  • Set tabIndex={-1} on nested anchor tags to prevent duplicate focus events when tabbing through Product items

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/hooks/useCioAutocomplete.ts Added tabIndex: 0 to item props to make all autocomplete items keyboard accessible
src/components/Autocomplete/SectionItem/SectionItem.tsx Set tabIndex={-1} on anchor tags for Product and Search Suggestion items to prevent duplicate tab stops

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (isProduct(item)) {
defaultChildren = (
<a href={item.data?.url}>
<a href={item.data?.url} tabIndex={-1}>
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

Setting tabIndex={-1} removes keyboard accessibility from the anchor tag. While this prevents duplicate focus with the parent item, it also prevents users from following the link using Enter key when the item is focused. Consider using tabIndex={0} on the parent container and handling click/Enter events there instead, or ensure the anchor remains keyboard accessible through event delegation.

Copilot uses AI. Check for mistakes.
if (getSearchResultsUrl) {
defaultChildren = (
<a className='suggestion-link' href={getSearchResultsUrl(item)}>
<a className='suggestion-link' href={getSearchResultsUrl(item)} tabIndex={-1}>
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

Setting tabIndex={-1} removes keyboard accessibility from the anchor tag. This prevents keyboard users from activating the link with Enter key when focused. The same concern applies here as with the Product items - consider maintaining link accessibility through alternative patterns like event delegation on the parent element.

Copilot uses AI. Check for mistakes.
@mocca102 mocca102 requested a review from Copilot November 4, 2025 13:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 131 to 134
if (isEnter || isSpace) {
e.preventDefault();
// Trigger default click behavior
getItemPropsDownShift({ item, index }).onClick(e);
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The Space key handler prevents default behavior, which will break the ability to scroll the page when focus is on these items. Consider removing e.preventDefault() for the Space key case, or only preventing default if the element is already in focus and the action is intentional. Users expect Space to scroll the page when focused on non-button elements.

Suggested change
if (isEnter || isSpace) {
e.preventDefault();
// Trigger default click behavior
getItemPropsDownShift({ item, index }).onClick(e);
if (isEnter) {
e.preventDefault();
// Trigger default click behavior
getItemPropsDownShift({ item, index }).onClick(e);
} else if (isSpace) {
// Do not prevent default for Space, to allow scrolling
getItemPropsDownShift({ item, index }).onClick(e);

Copilot uses AI. Check for mistakes.
@mocca102 mocca102 requested a review from Copilot November 4, 2025 13:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@Mudaafi Mudaafi left a comment

Choose a reason for hiding this comment

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

lgtm, just some lints to consider

mocca102 and others added 3 commits November 6, 2025 15:08
Co-authored-by: Ahmad Mudaafi' <ahmad.mudaafi@constructor.io>
Co-authored-by: Ahmad Mudaafi' <ahmad.mudaafi@constructor.io>
@mocca102 mocca102 merged commit d9f791f into main Nov 12, 2025
7 of 10 checks passed
@mocca102 mocca102 deleted the cdx-307-add-visible-keyboard-focus-for-search-dropdown-and branch November 12, 2025 08:39
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.

3 participants