Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docsearch-react): add aria-hidden to SearchIcon and add accessible label to SearchBox input #2193

Merged
merged 5 commits into from
Feb 28, 2024

Conversation

hbuchel
Copy link
Contributor

@hbuchel hbuchel commented Feb 26, 2024

There are 2 main changes in this PR:

  • Allows passing aria-hidden to the SearchIcon so it can be hidden to assistive tech users. The unlabelled SVG can be accessed by screenreaders and can also get caught by automated accessibility audits. Since it's decorative, we can safely hide it with aria-hidden="true" in <SearchBox /> and <SearchButton />
  • Adds an accessible label, searchInputLabel, to the search form's input. Currently the <input /> is associated with a <label> that does not have an accessible label, only an unlabelled SVG as a child element. This PR adds accessibly hidden text within the <label>. I opted to use visually hidden text (using CSS to hide the text but still make it available for assistive tech users) for the label text because it's generally a better practice than reaching for aria-label.

Additionally, this PR:

  • Updates test to check for the new label text and translation, as well as fixes some TS related linting errors in that file.
  • Updates the related docs to show the new translation option for searchInputLabel

Copy link

netlify bot commented Feb 26, 2024

👷 Deploy request for docsearch pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 7a710c4

@@ -34,20 +34,8 @@ function noResultSearch(_queries: any, _requestOptions?: any): Promise<any> {
}

describe('api', () => {
let container: HTMLDivElement;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't look like we're using container anywhere besides in the before/afterEach? So I removed them.

Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

awesome, thanks a lot for taking the time to improve DocSearch

cc @francoischalifour

packages/docsearch-css/src/modal.css Outdated Show resolved Hide resolved
packages/docsearch-react/src/icons/SearchIcon.tsx Outdated Show resolved Hide resolved
@hbuchel hbuchel changed the title fix: add aria-hidden to SearchIcon and add accessible label to SearchBox input fix(docsearch-react): add aria-hidden to SearchIcon and add accessible label to SearchBox input Feb 26, 2024
Copy link
Member

@francoischalifour francoischalifour left a comment

Choose a reason for hiding this comment

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

Thank you @hbuchel!

Could you please slightly increase the bundle size thresholds?

 {
   "files": [
     {
       "path": "packages/docsearch-css/dist/style.css",
-       "maxSize": "3 kB"
+       "maxSize": "3.25 kB"
     },
     {
       "path": "packages/docsearch-react/dist/umd/index.js",
-       "maxSize": "22.80 kB"
+       "maxSize": "23 kB"
     },
     {
       "path": "packages/docsearch-js/dist/umd/index.js",
-       "maxSize": "30.70 kB"
+       "maxSize": "31 kB"
     }
   ]
 }

@hbuchel
Copy link
Contributor Author

hbuchel commented Feb 27, 2024

Thank you @hbuchel!

Could you please slightly increase the bundle size thresholds?

Updated, thanks!

@francoischalifour francoischalifour merged commit df60b8e into algolia:main Feb 28, 2024
6 checks passed
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