Skip to content

Commit c278095

Browse files
authored
fix: dropdownMatchSelectWidth={false} not disable virtual (#699)
1 parent 53e09f9 commit c278095

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

src/Select.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ const Select = React.forwardRef(
161161
// Select
162162
onSelect,
163163
onDeselect,
164+
dropdownMatchSelectWidth,
164165

165166
// Options
166167
filterOption,
@@ -547,8 +548,9 @@ const Select = React.forwardRef(
547548
};
548549

549550
// ========================== Context ===========================
550-
const selectContext = React.useMemo(
551-
() => ({
551+
const selectContext = React.useMemo(() => {
552+
const realVirtual = virtual !== false && dropdownMatchSelectWidth !== false;
553+
return {
552554
...parsedOptions,
553555
flattenOptions: displayOptions,
554556
onActiveValue,
@@ -557,26 +559,26 @@ const Select = React.forwardRef(
557559
menuItemSelectedIcon,
558560
rawValues,
559561
fieldNames: mergedFieldNames,
560-
virtual,
561-
listHeight,
562-
listItemHeight,
563-
childrenAsData,
564-
}),
565-
[
566-
parsedOptions,
567-
displayOptions,
568-
onActiveValue,
569-
mergedDefaultActiveFirstOption,
570-
onInternalSelect,
571-
menuItemSelectedIcon,
572-
rawValues,
573-
mergedFieldNames,
574-
virtual,
562+
virtual: realVirtual,
575563
listHeight,
576564
listItemHeight,
577565
childrenAsData,
578-
],
579-
);
566+
};
567+
}, [
568+
parsedOptions,
569+
displayOptions,
570+
onActiveValue,
571+
mergedDefaultActiveFirstOption,
572+
onInternalSelect,
573+
menuItemSelectedIcon,
574+
rawValues,
575+
mergedFieldNames,
576+
virtual,
577+
dropdownMatchSelectWidth,
578+
listHeight,
579+
listItemHeight,
580+
childrenAsData,
581+
]);
580582

581583
// ========================== Warning ===========================
582584
if (process.env.NODE_ENV !== 'production') {
@@ -603,6 +605,7 @@ const Select = React.forwardRef(
603605
searchValue={mergedSearchValue}
604606
onSearch={onInternalSearch}
605607
onSearchSplit={onInternalSearchSplit}
608+
dropdownMatchSelectWidth={dropdownMatchSelectWidth}
606609
// >>> OptionList
607610
OptionList={OptionList}
608611
emptyOptions={!displayOptions.length}

tests/Select.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React from 'react';
44
import { act } from 'react-dom/test-utils';
55
import { resetWarned } from 'rc-util/lib/warning';
66
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
7+
import VirtualList from 'rc-virtual-list';
78
import type { SelectProps } from '../src';
89
import Select, { OptGroup, Option, useBaseProps } from '../src';
910
import focusTest from './shared/focusTest';
@@ -1273,6 +1274,7 @@ describe('Select.Basic', () => {
12731274

12741275
// dropdownMatchSelectWidth is false means close virtual scroll
12751276
expect(wrapper.find('.rc-select-item')).toHaveLength(options.length);
1277+
expect((wrapper.find(VirtualList).props() as any).virtual).toBe(false);
12761278
});
12771279

12781280
it('virtual false also no render virtual list', () => {

0 commit comments

Comments
 (0)