Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow rendering all options inside list box for better screen reader experience #805

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, OptionListP
virtual,
listHeight,
listItemHeight,
renderFullOptionList,
} = React.useContext(SelectContext);

const itemPrefixCls = `${prefixCls}-item`;
Expand Down Expand Up @@ -271,9 +272,9 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, OptionListP
return (
<>
<div role="listbox" id={`${id}_list`} style={{ height: 0, width: 0, overflow: 'hidden' }}>
{renderItem(activeIndex - 1)}
{renderItem(activeIndex)}
{renderItem(activeIndex + 1)}
{renderFullOptionList
? [...Array(flattenOptions.length).keys()].map((index) => renderItem(index))
: [activeIndex - 1, activeIndex, activeIndex + 1].map((index) => renderItem(index))}
</div>
<List<FlattenOptionData<BaseOptionType>>
itemKey="key"
Expand Down
4 changes: 4 additions & 0 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export interface SelectProps<ValueType = any, OptionType extends BaseOptionType
virtual?: boolean;
listHeight?: number;
listItemHeight?: number;
renderFullOptionList?: boolean;

// >>> Icon
menuItemSelectedIcon?: RenderNode;
Expand Down Expand Up @@ -186,6 +187,7 @@ const Select = React.forwardRef(
virtual,
listHeight = 200,
listItemHeight = 20,
renderFullOptionList,

// Value
value,
Expand Down Expand Up @@ -580,6 +582,7 @@ const Select = React.forwardRef(
listHeight,
listItemHeight,
childrenAsData,
renderFullOptionList,
};
}, [
parsedOptions,
Expand All @@ -595,6 +598,7 @@ const Select = React.forwardRef(
listHeight,
listItemHeight,
childrenAsData,
renderFullOptionList,
]);

// ========================== Warning ===========================
Expand Down
1 change: 1 addition & 0 deletions src/SelectContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface SelectContextProps {
listHeight?: number;
listItemHeight?: number;
childrenAsData?: boolean;
renderFullOptionList?: boolean;
}

const SelectContext = React.createContext<SelectContextProps>(null);
Expand Down