JedWatson / JedWatson/react-select

Unable to Add data-testid Attribute to ReactSelect Component

Open
#6,018 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

issue/bug-unconfirmed
Dominant language
TypeScript
Stars
28k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

Unable to Add data-testid Attribute to ReactSelect Component
Hi team,

I'm trying to add the data-testid attribute to the Select component from react-select for testing purposes, but it doesn't seem to be rendered in the DOM.

Here is the code I'm using:

<Select data-testid='dashboard-supplier-widgets-date-filter-select' isMulti={false} required id='dateFilterDropdown' options={WidgetsDateFilterOptions} value={{ value: props.dateFilter, label: WidgetsDateFilterOptions.find((option) => option.value === props.dateFilter)?.label, }} onChange={(selectedOption) => props.onDateFilterChange(selectedOption.value)} placeholder={t('widget_filter_text')} formatOptionLabel={formatWidgetsOptionLabel} isSearchable={false} menuPortalTarget={document.body} menuPlacement='auto' />

Even though the data-testid is passed as a prop, I don't see it applied in the rendered HTML. Is there a recommended way to add custom attributes like data-testid to the Select component?

Any guidance would be greatly appreciated.

Thanks!

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 the Select component and the provided reproduction, then inspect how the data-testid prop is handled versus the rendered DOM. Confirm the supported way to expose this attribute and verify that the expected custom attribute appears in the rendered HTML.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.