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

Support complex aria-labelledby queries #1281

Closed
jossmac-plenti opened this issue Dec 18, 2023 · 1 comment
Closed

Support complex aria-labelledby queries #1281

jossmac-plenti opened this issue Dec 18, 2023 · 1 comment

Comments

@jossmac-plenti
Copy link

Describe the feature you'd like:

I'd like getByLabelText to resolve the contents of aria-labelledby and associated elements. As I'm writing this it occurs to me that this might be too costly and perhaps better suited to something like axe.

Describe alternatives you've considered:

I've resorted to a combination of getByRole + getByText and checking IDs.

Teachability, Documentation, Adoption, Migration Strategy:

The summarised/pseudo code looks something like:

let contentId = 'content-id';
let spinnerId = 'spinner-id';

return (
  <button
    aria-disabled={props.pending ? true : undefined}
    aria-labelledby={props.pending ? `${contentId} ${spinnerId}` : undefined}
  >
    <span id={contentId}>{props.children}</span>
    {props.pending && (
      <span id={spinnerId} aria-label="pending" aria-hidden>
        ...
      </span>
    )}
  </button>
);

The desired test would look something like:

it('supports "pending" prop', () => {
  let buttonText = 'Submit';
  let { getByLabelText } = render(<Button pending>{buttonText}</Button>);

  expect(getByLabelText(`${buttonText} pending`)).toHaveAttribute("aria-disabled", true);
});
@jossmac-plenti
Copy link
Author

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

No branches or pull requests

1 participant