Skip to content

Commit fe05ea1

Browse files
committed
Merge branch 'improvement/selector-list-size' into q/1.0
2 parents f795de5 + e7a0294 commit fe05ea1

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/lib/components/selectv2/SelectStyle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ const SelectStyle = styled(Select)`
156156
isDefault
157157
? `
158158
max-height: calc(${spacing.r32} * ${(props) =>
159-
props.ITEMS_PER_SCROLL_WINDOW} + ${spacing.r32} / 2);`
159+
props.itemsPerScrollWindow} + ${spacing.r32} / 2);`
160160
: `
161161
max-height: calc(${spacing.r24} * ${(props) =>
162-
props.ITEMS_PER_SCROLL_WINDOW} + ${spacing.r24} / 2);`}
162+
props.itemsPerScrollWindow} + ${spacing.r24} / 2);`}
163163
164164
.sc-select__menu-notice {
165165
color: ${({ isDefault }) =>

src/lib/components/selectv2/Selectv2.component.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { convertSizeToRem } from '../inputv2/inputv2';
2929
import { ConstrainedText } from '../constrainedtext/Constrainedtext.component';
3030
import ReactSelect from 'react-select/src/Select';
3131

32-
const ITEMS_PER_SCROLL_WINDOW = 4;
3332
// more/equal than NOPT_SEARCH options enable search
3433
const NOPT_SEARCH = 8;
3534
export type OptionProps = {
@@ -236,6 +235,7 @@ const MenuList = (props) => {
236235
const listRef = useRef<FixedSizeList<any> | null>(null);
237236
const { children, getValue } = props;
238237
const [selectedOption] = getValue();
238+
const { itemsPerScrollWindow } = props.selectProps;
239239
const optionHeight =
240240
convertRemToPixels(
241241
parseFloat(props.selectProps.isDefault ? spacing.r40 : spacing.r24),
@@ -253,7 +253,7 @@ const MenuList = (props) => {
253253
}
254254

255255
const initialOffset =
256-
selectedIndex * optionHeight - (ITEMS_PER_SCROLL_WINDOW - 1) * optionHeight;
256+
selectedIndex * optionHeight - (itemsPerScrollWindow - 1) * optionHeight;
257257
useEffect(() => {
258258
if (listRef && listRef.current) {
259259
listRef.current.scrollTo(
@@ -267,13 +267,13 @@ const MenuList = (props) => {
267267
}
268268
}, [children.length, focusedIndex, optionHeight, listRef]);
269269

270-
if (children.length > ITEMS_PER_SCROLL_WINDOW) {
270+
if (children.length > itemsPerScrollWindow) {
271271
return (
272272
// @ts-ignore
273273
<List
274274
ref={listRef}
275275
className="sc-select__menu-list"
276-
height={optionHeight * ITEMS_PER_SCROLL_WINDOW + optionHeight / 2}
276+
height={optionHeight * itemsPerScrollWindow + optionHeight / 2}
277277
itemCount={children.length}
278278
itemSize={optionHeight}
279279
initialScrollOffset={initialOffset}
@@ -349,6 +349,10 @@ export type SelectProps = {
349349
className?: string;
350350
/** use menuPositon='fixed' inside modal to avoid display issue */
351351
menuPosition?: 'fixed' | 'absolute';
352+
/** number of items visible before the option list becomes scrollable
353+
* @default 4
354+
*/
355+
itemsPerScrollWindow?: number;
352356
};
353357

354358
type SelectOptionProps = {
@@ -390,6 +394,7 @@ function SelectBox<
390394
size = '1',
391395
id,
392396
selectRef,
397+
itemsPerScrollWindow = 4,
393398
...rest
394399
}: SelectProps & {
395400
selectRef?: Ref<SelectRef<OptionType, IsMulti, GroupType>>;
@@ -526,7 +531,7 @@ function SelectBox<
526531
IndicatorSeparator: null,
527532
}}
528533
isDefault={isDefaultVariant}
529-
ITEMS_PER_SCROLL_WINDOW={ITEMS_PER_SCROLL_WINDOW}
534+
itemsPerScrollWindow={itemsPerScrollWindow}
530535
onChange={handleChange}
531536
onInputChange={handleSearchInput}
532537
ref={internalSelectRef}

stories/Select/selectv2.stories.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ export const WithScrollbar: SelectStory = {
9898
},
9999
};
100100

101+
export const WithCustomItemsPerScrollWindow: SelectStory = {
102+
name: 'Custom items per scroll window (8)',
103+
args: {
104+
children: optionsWithSearchBar,
105+
itemsPerScrollWindow: 8,
106+
},
107+
};
108+
101109
export const WithSearchBar: SelectStory = {
102110
args: {
103111
children: optionsWithSearchBar,

0 commit comments

Comments
 (0)