Skip to content

Commit

Permalink
[a11y] Search: Search Icon Label Logic Update (carbon-design-system#1…
Browse files Browse the repository at this point in the history
…3648)

* [a11y] Search: Search Icon Label Logic Update

With the currently implementation, an accessibility violation occurs when the Search Icon's container doesn't have a role.
The current implementation removes the `role` attribute when the `onExpand` property is undefined, but it should also remove the `aria-labelledby`.

This update will avoid the accessibility violation: https://www.w3.org/TR/wai-aria-1.1/#roles

---

The error can be see in the `@carbon/react` Storybook UI. Visit the [Search component](https://react.carbondesignsystem.com/?path=/story/components-search--default) and click on the 'Accessibility' tab

* fix(tests): snapshots updated after Search a11y update

---------

Co-authored-by: Francine Lucca <40550942+francinelucca@users.noreply.github.com>
Co-authored-by: Alison Joseph <alison.joseph@us.ibm.com>
Co-authored-by: Andrea N. Cardona <cardona.n.andrea@gmail.com>
  • Loading branch information
4 people authored and SunnyJohal committed May 23, 2023
1 parent 7b912b1 commit 3eed2fa
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ exports[`DataTable behaves as expected selection should render and match snapsho
role="search"
>
<div
aria-labelledby="custom-id"
class="cds--search-magnifier"
>
<svg
Expand Down Expand Up @@ -886,7 +885,6 @@ exports[`DataTable renders as expected - Component API should render and match s
role="search"
>
<div
aria-labelledby="custom-id"
class="cds--search-magnifier"
>
<svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exports[`TableToolbarSearch renders as expected - Component API should render 1`
role="search"
>
<div
aria-labelledby="custom-id"
class="cds--search-magnifier"
>
<svg
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const Search = React.forwardRef<HTMLInputElement, SearchProps>(function Search(
however, it does not need a keyboard event bc the input element gets focus on keyboard nav and expands that way*/}
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
<div
aria-labelledby={uniqueId}
aria-labelledby={onExpand ? uniqueId : undefined}
role={onExpand ? 'button' : undefined}
className={`${prefix}--search-magnifier`}
onClick={onExpand}>
Expand Down

0 comments on commit 3eed2fa

Please sign in to comment.