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

feat(dom): Add labels to buttons #1234

Merged
merged 6 commits into from
Feb 6, 2024
Merged

feat(dom): Add labels to buttons #1234

merged 6 commits into from
Feb 6, 2024

Conversation

dishantkapoor
Copy link
Contributor

@dishantkapoor dishantkapoor commented Jan 16, 2024

Summary

fixes #1183

Result

image

@Haroenv
Copy link
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
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
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
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

Copy link

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
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
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
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