Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ const Select = React.forwardRef(
// Select
onSelect,
onDeselect,
dropdownMatchSelectWidth,

// Options
filterOption,
Expand Down Expand Up @@ -547,8 +548,9 @@ const Select = React.forwardRef(
};

// ========================== Context ===========================
const selectContext = React.useMemo(
() => ({
const selectContext = React.useMemo(() => {
const realVirtual = virtual !== false && dropdownMatchSelectWidth !== false;
Copy link
Member Author

@afc163 afc163 Dec 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return {
...parsedOptions,
flattenOptions: displayOptions,
onActiveValue,
Expand All @@ -557,26 +559,26 @@ const Select = React.forwardRef(
menuItemSelectedIcon,
rawValues,
fieldNames: mergedFieldNames,
virtual,
listHeight,
listItemHeight,
childrenAsData,
}),
[
parsedOptions,
displayOptions,
onActiveValue,
mergedDefaultActiveFirstOption,
onInternalSelect,
menuItemSelectedIcon,
rawValues,
mergedFieldNames,
virtual,
virtual: realVirtual,
listHeight,
listItemHeight,
childrenAsData,
],
);
};
}, [
parsedOptions,
displayOptions,
onActiveValue,
mergedDefaultActiveFirstOption,
onInternalSelect,
menuItemSelectedIcon,
rawValues,
mergedFieldNames,
virtual,
dropdownMatchSelectWidth,
listHeight,
listItemHeight,
childrenAsData,
]);

// ========================== Warning ===========================
if (process.env.NODE_ENV !== 'production') {
Expand All @@ -603,6 +605,7 @@ const Select = React.forwardRef(
searchValue={mergedSearchValue}
onSearch={onInternalSearch}
onSearchSplit={onInternalSearchSplit}
dropdownMatchSelectWidth={dropdownMatchSelectWidth}
// >>> OptionList
OptionList={OptionList}
emptyOptions={!displayOptions.length}
Expand Down
2 changes: 2 additions & 0 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react';
import { act } from 'react-dom/test-utils';
import { resetWarned } from 'rc-util/lib/warning';
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
import VirtualList from 'rc-virtual-list';
import type { SelectProps } from '../src';
import Select, { OptGroup, Option, useBaseProps } from '../src';
import focusTest from './shared/focusTest';
Expand Down Expand Up @@ -1273,6 +1274,7 @@ describe('Select.Basic', () => {

// dropdownMatchSelectWidth is false means close virtual scroll
expect(wrapper.find('.rc-select-item')).toHaveLength(options.length);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这句断言在 jsdom 里测不出来,即使开启虚拟滚动 length 也始终是全量。

expect((wrapper.find(VirtualList).props() as any).virtual).toBe(false);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还是要检查传给 VirtualList 的属性。

});

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