testing-library / testing-library/user-event

selectOptions could use the aria-label to find the value too

Open
#1,142 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement needs assessment
Dominant language
TypeScript
Stars
2.3k
Forks
258
PR merge metrics
No merged PRs in 30d

Description

Problem description

Hi,

I am using the library to test a component built with headlessUI's combobox and I am using the selectOptions method to select an option from the displayed listbox.

I have noticed that it's required that the value you provide matches exactly with the HTML value according to these lines of code . Would you accept a PR in which a check to the aria-label of the option is added?

Suggested solution

I was thinking about adding an additional check along the lines like:

var element = select.querySelector([aria-label=${option}]);

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/utility/selectOptions.ts at the linked option-matching logic. Check how selectOptions resolves the requested option and determine how aria-label matching should behave alongside the existing HTML value match. Done means the method can find the intended option by its aria-label without breaking existing selection behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, testing
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.