Skip to content

Commit

Permalink
feat: add List ScrollBar direction (#940)
Browse files Browse the repository at this point in the history
* feat: add List ScrollBar direction

* chore: update snapshots

* chore: empty test

* test: update test case

---------

Co-authored-by: 洋 <hetongyang@bytedance.com>
Co-authored-by: 二货机器人 <smith3816@gmail.com>
  • Loading branch information
3 people committed May 18, 2023
1 parent 9eed16b commit af6fcda
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -50,7 +50,7 @@
"rc-motion": "^2.0.1",
"rc-overflow": "^1.0.0",
"rc-util": "^5.16.1",
"rc-virtual-list": "^3.4.13"
"rc-virtual-list": "^3.5.2"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
Expand Down
2 changes: 2 additions & 0 deletions src/OptionList.tsx
Expand Up @@ -53,6 +53,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
rawValues,
fieldNames,
virtual,
direction,
listHeight,
listItemHeight,
} = React.useContext(SelectContext);
Expand Down Expand Up @@ -297,6 +298,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
onMouseDown={onListMouseDown}
onScroll={onPopupScroll}
virtual={virtual}
direction={direction}
innerProps={virtual ? null : a11yProps}
>
{(item, itemIndex) => {
Expand Down
5 changes: 5 additions & 0 deletions src/Select.tsx
Expand Up @@ -140,6 +140,7 @@ export interface SelectProps<ValueType = any, OptionType extends BaseOptionType
options?: OptionType[];
defaultActiveFirstOption?: boolean;
virtual?: boolean;
direction?: "ltr" | "rtl";
listHeight?: number;
listItemHeight?: number;

Expand Down Expand Up @@ -187,6 +188,7 @@ const Select = React.forwardRef(
defaultActiveFirstOption,
menuItemSelectedIcon,
virtual,
direction,
listHeight = 200,
listItemHeight = 20,

Expand Down Expand Up @@ -584,6 +586,7 @@ const Select = React.forwardRef(
rawValues,
fieldNames: mergedFieldNames,
virtual: realVirtual,
direction,
listHeight,
listItemHeight,
childrenAsData,
Expand Down Expand Up @@ -626,6 +629,8 @@ const Select = React.forwardRef(
// >>> Values
displayValues={displayValues}
onDisplayValuesChange={onDisplayValuesChange}
// >>> Trigger
direction={direction}
// >>> Search
searchValue={mergedSearchValue}
onSearch={onInternalSearch}
Expand Down
1 change: 1 addition & 0 deletions src/SelectContext.ts
Expand Up @@ -14,6 +14,7 @@ export interface SelectContextProps {
rawValues: Set<RawValueType>;
fieldNames?: FieldNames;
virtual?: boolean;
direction?: "ltr" | "rtl";
listHeight?: number;
listItemHeight?: number;
childrenAsData?: boolean;
Expand Down
7 changes: 7 additions & 0 deletions tests/Select.test.tsx
Expand Up @@ -1980,4 +1980,11 @@ describe('Select.Basic', () => {
expect(wrapper3.find('.rc-select').prop('title')).toBe('title');
expect(wrapper3.find('.rc-select-selection-item').prop('title')).toBe('title');
});

it('scrollbar should be left position with rtl direction', () => {
const options = new Array(10).fill(null).map((_, value) => ({ value }));

const { container } = testingRender(<Select open direction="rtl" options={options} />);
expect(container.querySelector('.rc-virtual-list-rtl')).toBeTruthy();
});
});

0 comments on commit af6fcda

Please sign in to comment.