Skip to content

feat(dom): Add labels to buttons#1234

Merged
dhayab merged 6 commits intoalgolia:nextfrom
dishantkapoor:next
Feb 6, 2024
Merged

feat(dom): Add labels to buttons#1234
dhayab merged 6 commits intoalgolia:nextfrom
dishantkapoor:next

Conversation

@dishantkapoor
Copy link
Copy Markdown
Contributor

@dishantkapoor dishantkapoor commented Jan 16, 2024

Summary

fixes #1183

Result

image

@Haroenv
Copy link
Copy Markdown
Contributor

Haroenv commented Jan 16, 2024

That's weird, there's already textContent in both of those buttons:

I wonder if this is happening when the query is "" only? Maybe that title should be submitButtonTitle like it's the case outside of detached:

title: translations.submitButtonTitle,

@dishantkapoor
Copy link
Copy Markdown
Contributor Author

This is happening when we use detachedMediaQuery="" (blank) , If you write something then it replace button with form. I also passed translations but it not worked.

@Haroenv
Copy link
Copy Markdown
Contributor

Haroenv commented Jan 16, 2024

If only the textContent of the detachedSearchButtonQuery is changed (eg. to something static), does lighthouse work for you as well?

@dishantkapoor
Copy link
Copy Markdown
Contributor Author

dishantkapoor commented Jan 16, 2024

I passed it. We need some title here

image

To resolve the issue we need to pass title attribute in tag
image

image

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Jan 27, 2024

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 3665cff:

Sandbox Source
@algolia/autocomplete-example-github-repositories-custom-plugin Configuration
@algolia/autocomplete-example-instantsearch Configuration
@algolia/autocomplete-example-playground Configuration
@algolia/autocomplete-example-preview-panel-in-modal Configuration
@algolia/autocomplete-example-react-renderer Configuration
@algolia/autocomplete-example-starter-algolia Configuration
@algolia/autocomplete-example-starter Configuration
@algolia/autocomplete-example-reshape Configuration
@algolia/autocomplete-example-vue Configuration

@Haroenv Haroenv changed the title algolia #1183 feat(dom): Add labels to buttons Jan 29, 2024
@Haroenv Haroenv requested a review from dhayab January 29, 2024 11:08
@dhayab
Copy link
Copy Markdown
Member

dhayab commented Jan 29, 2024

Hi there, thanks for your contribution. I looked into it and it seems there are 2 related issues we could fix:

  1. The detached search button is indeed not accessible, because its text content cannot be read directly. I'd still prefer if we add a detachedSearchButtonTitle in the translations key, default it to "Search" and use it instead of having it hardcoded, typically:
const detachedSearchButton = createDomElement('button', {
  // ...
  title: translations.detachedSearchButtonTitle,
});
  1. The reason this change isn't enough to pass Lighthouse is because the main .aa-Autocomplete says its labelled by an element which is not mounted in detached mode. To fix this we can instead apply the autocomplete-X-label id to the Search button like so:
const detachedSearchButton = createDomElement('button', {
  // ...
  id: labelProps.id,
});

With these changes, screen reader should correctly read the button and link it to the Autocomplete role.

Copy link
Copy Markdown
Member

@dhayab dhayab left a comment

Choose a reason for hiding this comment

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

Just some final touches and it will be good to go for me. In addition to the suggestions, you'll need to set the default value for translations.detachedSearchButtonTitle, in getDefaultOptions.ts:

const defaultTranslations: AutocompleteTranslations = {
   clearButtonTitle: 'Clear',
   detachedCancelButtonText: 'Cancel',
+  detachedSearchButtonTitle: 'Search',
   submitButtonTitle: 'Submit',
};

@dishantkapoor dishantkapoor requested a review from dhayab February 6, 2024 14:29
Copy link
Copy Markdown
Member

@dhayab dhayab left a comment

Choose a reason for hiding this comment

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

Thanks again for your contribution, this passes tests locally.

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.

aria-labelledby on the input element fails WCAG checks because the target button has no text

3 participants