Skip to content

Commit af6fcda

Browse files
BoyYangzai洋zombieJ
authored
feat: add List ScrollBar direction (#940)
* feat: add List ScrollBar direction * chore: update snapshots * chore: empty test * test: update test case --------- Co-authored-by: 洋 <[email protected]> Co-authored-by: 二货机器人 <[email protected]>
1 parent 9eed16b commit af6fcda

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"rc-motion": "^2.0.1",
5151
"rc-overflow": "^1.0.0",
5252
"rc-util": "^5.16.1",
53-
"rc-virtual-list": "^3.4.13"
53+
"rc-virtual-list": "^3.5.2"
5454
},
5555
"devDependencies": {
5656
"@testing-library/jest-dom": "^5.16.5",

src/OptionList.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
5353
rawValues,
5454
fieldNames,
5555
virtual,
56+
direction,
5657
listHeight,
5758
listItemHeight,
5859
} = React.useContext(SelectContext);
@@ -297,6 +298,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
297298
onMouseDown={onListMouseDown}
298299
onScroll={onPopupScroll}
299300
virtual={virtual}
301+
direction={direction}
300302
innerProps={virtual ? null : a11yProps}
301303
>
302304
{(item, itemIndex) => {

src/Select.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export interface SelectProps<ValueType = any, OptionType extends BaseOptionType
140140
options?: OptionType[];
141141
defaultActiveFirstOption?: boolean;
142142
virtual?: boolean;
143+
direction?: "ltr" | "rtl";
143144
listHeight?: number;
144145
listItemHeight?: number;
145146

@@ -187,6 +188,7 @@ const Select = React.forwardRef(
187188
defaultActiveFirstOption,
188189
menuItemSelectedIcon,
189190
virtual,
191+
direction,
190192
listHeight = 200,
191193
listItemHeight = 20,
192194

@@ -584,6 +586,7 @@ const Select = React.forwardRef(
584586
rawValues,
585587
fieldNames: mergedFieldNames,
586588
virtual: realVirtual,
589+
direction,
587590
listHeight,
588591
listItemHeight,
589592
childrenAsData,
@@ -626,6 +629,8 @@ const Select = React.forwardRef(
626629
// >>> Values
627630
displayValues={displayValues}
628631
onDisplayValuesChange={onDisplayValuesChange}
632+
// >>> Trigger
633+
direction={direction}
629634
// >>> Search
630635
searchValue={mergedSearchValue}
631636
onSearch={onInternalSearch}

src/SelectContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface SelectContextProps {
1414
rawValues: Set<RawValueType>;
1515
fieldNames?: FieldNames;
1616
virtual?: boolean;
17+
direction?: "ltr" | "rtl";
1718
listHeight?: number;
1819
listItemHeight?: number;
1920
childrenAsData?: boolean;

tests/Select.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,4 +1980,11 @@ describe('Select.Basic', () => {
19801980
expect(wrapper3.find('.rc-select').prop('title')).toBe('title');
19811981
expect(wrapper3.find('.rc-select-selection-item').prop('title')).toBe('title');
19821982
});
1983+
1984+
it('scrollbar should be left position with rtl direction', () => {
1985+
const options = new Array(10).fill(null).map((_, value) => ({ value }));
1986+
1987+
const { container } = testingRender(<Select open direction="rtl" options={options} />);
1988+
expect(container.querySelector('.rc-virtual-list-rtl')).toBeTruthy();
1989+
});
19831990
});

0 commit comments

Comments
 (0)