Skip to content

Commit

Permalink
fix: aria-selected should not always set to false under combobox mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanlao11 committed Oct 11, 2024
1 parent fb2a981 commit 6bb66e9
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,26 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r

// https://github.com/ant-design/ant-design/issues/34975
const isSelected = React.useCallback(
(value: RawValueType) => rawValues.has(value) && mode !== 'combobox',
(value: RawValueType) => {
if (mode === 'combobox') {
return false;
}
return rawValues.has(value);
},
[mode, [...rawValues].toString(), rawValues.size],
);

// https://github.com/ant-design/ant-design/issues/48036
const isAriaSelected = React.useCallback(
(value: RawValueType) => {
if (mode === 'combobox') {
return String(value).toLowerCase() === searchValue.toLowerCase();
}
return rawValues.has(value);
},
[mode, searchValue, [...rawValues].toString(), rawValues.size],
);

// Auto scroll to item position in single mode
useEffect(() => {
/**
Expand Down Expand Up @@ -275,7 +291,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
{...attrs}
key={index}
{...getItemAriaProps(item, index)}
aria-selected={isSelected(value)}
aria-selected={isAriaSelected(value)}
>
{value}
</div>
Expand Down Expand Up @@ -360,7 +376,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
<div
{...pickAttrs(passedProps)}
{...(!virtual ? getItemAriaProps(item, itemIndex) : {})}
aria-selected={selected}
aria-selected={isAriaSelected(value)}
className={optionClassName}
title={optionTitle}
onMouseMove={() => {
Expand Down

0 comments on commit 6bb66e9

Please sign in to comment.