Skip to content

Commit 601a209

Browse files
nathanlaonathanlao11
and
nathanlao11
authored
fix: aria-selected should not always set to false under combobox mode (#1077)
Co-authored-by: nathanlao11 <[email protected]>
1 parent fb2a981 commit 601a209

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/OptionList.tsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,26 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
124124

125125
// https://github.com/ant-design/ant-design/issues/34975
126126
const isSelected = React.useCallback(
127-
(value: RawValueType) => rawValues.has(value) && mode !== 'combobox',
127+
(value: RawValueType) => {
128+
if (mode === 'combobox') {
129+
return false;
130+
}
131+
return rawValues.has(value);
132+
},
128133
[mode, [...rawValues].toString(), rawValues.size],
129134
);
130135

136+
// https://github.com/ant-design/ant-design/issues/48036
137+
const isAriaSelected = React.useCallback(
138+
(value: RawValueType) => {
139+
if (mode === 'combobox') {
140+
return String(value).toLowerCase() === searchValue.toLowerCase();
141+
}
142+
return rawValues.has(value);
143+
},
144+
[mode, searchValue, [...rawValues].toString(), rawValues.size],
145+
);
146+
131147
// Auto scroll to item position in single mode
132148
useEffect(() => {
133149
/**
@@ -275,7 +291,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
275291
{...attrs}
276292
key={index}
277293
{...getItemAriaProps(item, index)}
278-
aria-selected={isSelected(value)}
294+
aria-selected={isAriaSelected(value)}
279295
>
280296
{value}
281297
</div>
@@ -360,7 +376,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
360376
<div
361377
{...pickAttrs(passedProps)}
362378
{...(!virtual ? getItemAriaProps(item, itemIndex) : {})}
363-
aria-selected={selected}
379+
aria-selected={isAriaSelected(value)}
364380
className={optionClassName}
365381
title={optionTitle}
366382
onMouseMove={() => {

0 commit comments

Comments
 (0)