react-component / react-component/select

OptionList accessibility doesn't work correctly?

Open
#473 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
938
Forks
482
Avg merge
15h 8m
Merged PRs (30d)
2

Description

Hello :)

I saw on the code, that the OptionList renders a "listbox" role for accessibility, and that function calls renderItem
https://github.com/react-component/select/blob/bdbcdf6b10a93b5a7e2568df81b5f44a53c52438/src/OptionList.tsx#L230-L238
but, the value always is the prop "value", and this prop doesn't contain the real description. I saw also that the list use "mergedLabel" conditional with childrenAsData to use the prop "children".
https://github.com/react-component/select/blob/bdbcdf6b10a93b5a7e2568df81b5f44a53c52438/src/OptionList.tsx#L291 https://github.com/react-component/select/blob/bdbcdf6b10a93b5a7e2568df81b5f44a53c52438/src/OptionList.tsx#L316

Why the renderItem for the listbox is not using that?

Changing the function like this works perfectly.

  function renderItem(index: number) {
    const item = memoFlattenOptions[index];
    const value = item && (item.data as OptionData).value;
+   const mergedLabel = childrenAsData ? item && item.data.children : item && item.data.label;
    return item ? (
      <div key={index} role="option" id={`${id}_list_${index}`} aria-selected={values.has(value)}>
-        {value}
+        {mergedLabel || value}
      </div>
    ) : null;
  }

Any thoughts?
Thanks,

Contributor guide

No contributing guide indexed for this repository

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 in src/OptionList.tsx at renderItem and compare its value usage with the mergedLabel logic around the cited lines. Confirm that each listbox option exposes the intended label or children text rather than only the option value, and verify the resulting accessibility output.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
accessibility, frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.