Skip to content

Commit b39749e

Browse files
committed
feat: Add disableAutoScroll prop to control auto-scrolling behavior in the select component.
1 parent a3ffbcf commit b39749e

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/OptionList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
5252
flattenOptions,
5353
onActiveValue,
5454
defaultActiveFirstOption,
55+
disableAutoScroll,
5556
onSelect,
5657
menuItemSelectedIcon,
5758
rawValues,
@@ -157,7 +158,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
157158
*/
158159
let timeoutId: NodeJS.Timeout;
159160

160-
if (!multiple && open && rawValues.size === 1) {
161+
if (!disableAutoScroll && !multiple && open && rawValues.size === 1) {
161162
const value: RawValueType = Array.from(rawValues)[0];
162163
// Scroll to the option closest to the searchValue if searching.
163164
const index = memoFlattenOptions.findIndex(({ data }) =>

src/Select.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export interface SelectProps<
164164
info: { index: number },
165165
) => React.ReactNode;
166166
defaultActiveFirstOption?: boolean;
167+
disableAutoScroll?: boolean;
167168
virtual?: boolean;
168169
direction?: 'ltr' | 'rtl';
169170
listHeight?: number;
@@ -214,6 +215,7 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
214215
optionRender,
215216
children,
216217
defaultActiveFirstOption,
218+
disableAutoScroll,
217219
menuItemSelectedIcon,
218220
virtual,
219221
direction,
@@ -675,6 +677,7 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
675677
flattenOptions: displayOptions,
676678
onActiveValue,
677679
defaultActiveFirstOption: mergedDefaultActiveFirstOption,
680+
disableAutoScroll,
678681
onSelect: onInternalSelect,
679682
menuItemSelectedIcon,
680683
rawValues,
@@ -695,6 +698,7 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
695698
displayOptions,
696699
onActiveValue,
697700
mergedDefaultActiveFirstOption,
701+
disableAutoScroll,
698702
onInternalSelect,
699703
menuItemSelectedIcon,
700704
rawValues,

src/SelectContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface SelectContextProps {
3737
listItemHeight?: number;
3838
childrenAsData?: boolean;
3939
maxCount?: number;
40+
disableAutoScroll?: boolean;
4041
}
4142

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

0 commit comments

Comments
 (0)