Skip to content

Commit 082be69

Browse files
committed
bump node dev deps; update README.md
1 parent 334fb58 commit 082be69

File tree

6 files changed

+36
-38
lines changed

6 files changed

+36
-38
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,16 @@ $ yarn add react-window styled-components react-functional-select
4646

4747
```jsx
4848
import { Select } from 'react-functional-select';
49-
import { useState, useEffect, useCallback } from 'react';
49+
import React, { useState, useEffect, useCallback } from 'react';
5050
import { Card, CardHeader, CardBody, Container, SelectContainer } from '../shared/components';
5151

52-
import type { FunctionComponent } from 'react';
53-
5452
type Option = Readonly<{
5553
id: number;
5654
city: string;
5755
state: string;
5856
}>;
5957

60-
type SingleSelectDemoProps = Readonly<{
58+
type SingleSelectProps = Readonly<{
6159
isDisabled: boolean;
6260
}>;
6361

@@ -69,7 +67,7 @@ const CITY_OPTIONS: Option[] = [
6967
{ id: 5, city: 'Houston', state: 'TX' }
7068
];
7169

72-
const SingleSelectDemo: FunctionComponent<SingleSelectDemoProps> = ({ isDisabled }) => {
70+
const SingleSelect: React.FC<SingleSelectProps> = ({ isDisabled }) => {
7371
const [isInvalid, setIsInvalid] = useState<boolean>(false);
7472
const [selectedOption, setSelectedOption] = useState<Option | null>(null);
7573

@@ -105,7 +103,7 @@ const SingleSelectDemo: FunctionComponent<SingleSelectDemoProps> = ({ isDisabled
105103
);
106104
};
107105

108-
export default SingleSelectDemo;
106+
export default SingleSelect;
109107
```
110108

111109
## Properties

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
"@types/react-dom": "^18.0.9",
7272
"@types/react-window": "^1.8.5",
7373
"@types/styled-components": "^5.1.26",
74-
"@typescript-eslint/eslint-plugin": "^5.43.0",
75-
"@typescript-eslint/parser": "^5.43.0",
74+
"@typescript-eslint/eslint-plugin": "^5.44.0",
75+
"@typescript-eslint/parser": "^5.44.0",
7676
"babel-jest": "^29.3.1",
7777
"babel-loader": "^9.1.0",
7878
"babel-plugin-styled-components": "^2.0.7",
@@ -95,7 +95,7 @@
9595
"react-toastify": "^9.1.1",
9696
"react-window": "^1.8.8",
9797
"rimraf": "^3.0.2",
98-
"rollup": "^3.3.0",
98+
"rollup": "^3.4.0",
9999
"rollup-plugin-terser": "^7.0.2",
100100
"styled-components": "^5.3.6",
101101
"typescript": "^4.9.3",

src/Select.tsx

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
EMPTY_ARRAY,
2323
DEFAULT_THEME,
2424
SELECT_WRAPPER_ATTRS,
25+
PAGE_SIZE_DEFAULT,
2526
PLACEHOLDER_DEFAULT,
2627
LOADING_MSG_DEFAULT,
2728
CONTROL_CONTAINER_CLS,
@@ -222,7 +223,6 @@ const Select = forwardRef<SelectRef, SelectProps>((
222223
hideSelectedOptions,
223224
getIsOptionDisabled,
224225
getFilterOptionString,
225-
pageSize = 5,
226226
isSearchable = true,
227227
memoOptions = false,
228228
lazyLoadMenu = false,
@@ -235,6 +235,7 @@ const Select = forwardRef<SelectRef, SelectProps>((
235235
filterMatchFrom = FilterMatchEnum.ANY,
236236
menuPosition = MenuPositionEnum.BOTTOM,
237237
options = EMPTY_ARRAY,
238+
pageSize = PAGE_SIZE_DEFAULT,
238239
loadingMsg = LOADING_MSG_DEFAULT,
239240
placeholder = PLACEHOLDER_DEFAULT,
240241
noOptionsMsg = NO_OPTIONS_MSG_DEFAULT,
@@ -333,12 +334,12 @@ const Select = forwardRef<SelectRef, SelectProps>((
333334
return;
334335
}
335336

336-
const selectedIndex = !isMulti
337+
const selectedIdx = !isMulti
337338
? menuOptions.findIndex((x) => x.isSelected)
338339
: -1;
339340

340-
const index = selectedIndex > -1
341-
? selectedIndex
341+
const index = selectedIdx > -1
342+
? selectedIdx
342343
: position === OptionIndexEnum.FIRST
343344
? 0
344345
: menuOptions.length - 1;
@@ -388,11 +389,12 @@ const Select = forwardRef<SelectRef, SelectProps>((
388389
setFocusedOption(FOCUSED_OPTION_DEFAULT);
389390
},
390391
setValue: (option?: OptionData) => {
391-
const normalizedOpts = normalizeValue(option, getOptionValueFn, getOptionLabelFn);
392-
setSelectedOption(normalizedOpts);
392+
setSelectedOption(
393+
normalizeValue(option, getOptionValueFn, getOptionLabelFn)
394+
);
393395
},
394396
toggleMenu: (state?: boolean) => {
395-
if (state === true || (state === undefined && !menuOpenRef.current)) {
397+
if (state || (state === undefined && !menuOpenRef.current)) {
396398
focusInput();
397399
openMenuAndFocusOption(OptionIndexEnum.FIRST);
398400
} else {
@@ -474,24 +476,24 @@ const Select = forwardRef<SelectRef, SelectProps>((
474476
const focusValueOnArrowKey = (key: string): void => {
475477
if (!hasSelectedOptions) return;
476478

477-
let nextFocusedIdx = -1;
479+
let focusedIdx = -1;
478480
const lastValueIdx = selectedOption.length - 1;
479481
const curFocusedIdx = focusedMultiValue ? selectedOption.findIndex((x) => x.value === focusedMultiValue) : -1;
480482

481483
if (key === 'ArrowRight') {
482-
nextFocusedIdx = (curFocusedIdx > -1 && curFocusedIdx < lastValueIdx)
484+
focusedIdx = (curFocusedIdx > -1 && curFocusedIdx < lastValueIdx)
483485
? curFocusedIdx + 1
484486
: -1;
485487
} else {
486-
nextFocusedIdx = curFocusedIdx !== 0
488+
focusedIdx = curFocusedIdx !== 0
487489
? curFocusedIdx === -1
488490
? lastValueIdx
489491
: curFocusedIdx - 1
490492
: 0;
491493
}
492494

493-
const nextFocusedVal = nextFocusedIdx >= 0
494-
? selectedOption[nextFocusedIdx].value!
495+
const nextFocusedVal = focusedIdx >= 0
496+
? selectedOption[focusedIdx].value!
495497
: null;
496498

497499
if (focusedOption.data) setFocusedOption(FOCUSED_OPTION_DEFAULT);
@@ -512,13 +514,13 @@ const Select = forwardRef<SelectRef, SelectProps>((
512514
break;
513515
}
514516
case OptionIndexEnum.PAGEUP: {
515-
const pageIndex = focusedOption.index - pageSize;
516-
index = (pageIndex < 0) ? 0 : pageIndex;
517+
const pageIdx = focusedOption.index - pageSize;
518+
index = (pageIdx < 0) ? 0 : pageIdx;
517519
break;
518520
}
519521
case OptionIndexEnum.PAGEDOWN: {
520-
const pageIndex = focusedOption.index + pageSize;
521-
index = (pageIndex > menuOptions.length - 1) ? menuOptions.length - 1 : pageIndex;
522+
const pageIdx = focusedOption.index + pageSize;
523+
index = (pageIdx > menuOptions.length - 1) ? menuOptions.length - 1 : pageIdx;
522524
break;
523525
}
524526
}
@@ -599,14 +601,13 @@ const Select = forwardRef<SelectRef, SelectProps>((
599601
if (inputValue) return;
600602

601603
if (focusedMultiValue) {
602-
const clearFocusedIndex = selectedOption.findIndex((x) => x.value === focusedMultiValue);
603-
const nexFocusedMultiValue =
604-
(clearFocusedIndex > -1 && (clearFocusedIndex < (selectedOption.length - 1)))
605-
? selectedOption[clearFocusedIndex + 1].value!
606-
: null;
604+
const focusedIdx = selectedOption.findIndex((x) => x.value === focusedMultiValue);
605+
const nextFocusedMultiValue = (focusedIdx > -1 && (focusedIdx < (selectedOption.length - 1)))
606+
? selectedOption[focusedIdx + 1].value!
607+
: null;
607608

608609
removeSelectedOption(focusedMultiValue);
609-
setFocusedMultiValue(nexFocusedMultiValue);
610+
setFocusedMultiValue(nextFocusedMultiValue);
610611
} else {
611612
if (!backspaceClearsValue) return;
612613
if (!hasSelectedOptions) break;
@@ -681,6 +682,7 @@ const Select = forwardRef<SelectRef, SelectProps>((
681682
menuOpenRef.current ? setMenuOpen(false) : openMenuAndFocusOption(OptionIndexEnum.FIRST);
682683
}, [isDisabled, openMenuOnClick, openMenuAndFocusOption]);
683684

685+
const flexValueWrapper = !!isMulti && hasSelectedOptions;
684686
const showClear = !!isClearable && !isDisabled && hasSelectedOptions;
685687
const inputReadOnly = isDisabled || !isSearchable || !!focusedMultiValue;
686688

@@ -702,7 +704,7 @@ const Select = forwardRef<SelectRef, SelectProps>((
702704
onMouseDown={handleOnControlMouseDown}
703705
data-testid={CONTROL_CONTAINER_TESTID}
704706
>
705-
<ValueWrapper flex={!!isMulti && hasSelectedOptions}>
707+
<ValueWrapper flex={flexValueWrapper}>
706708
<Value
707709
isMulti={isMulti}
708710
inputValue={inputValue}

src/components/IndicatorIcons/LoadingDots.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const StyledLoadingDots = styled.div`
1212
> div {
1313
border-radius: 100%;
1414
display: inline-block;
15-
1615
${({ theme }) => css`
1716
width: ${theme.loader.size};
1817
height: ${theme.loader.size};

src/constants/defaults.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import type {
66
OptionDisabledCallback
77
} from '../types';
88

9+
export const PAGE_SIZE_DEFAULT = 5;
910
export const MENU_ITEM_SIZE_DEFAULT = 35;
1011
export const MENU_MAX_HEIGHT_DEFAULT = 300;
1112
export const LOADING_MSG_DEFAULT = 'Loading..';
1213
export const NO_OPTIONS_MSG_DEFAULT = 'No options';
1314
export const PLACEHOLDER_DEFAULT = 'Select option..';
14-
export const FOCUSED_OPTION_DEFAULT: FocusedOption = { index: -1 };
1515

16-
// Default for options and selectedOption props
17-
export const EMPTY_ARRAY: any[] = [];
16+
export const EMPTY_ARRAY: any[] = []; // Default for options and selectedOption props
17+
export const FOCUSED_OPTION_DEFAULT: FocusedOption = { index: -1 };
1818

1919
export const FUNCTIONS = {
2020
optionLabel: ((x) => x.label) as OptionLabelCallback,

src/hooks/useMenuPositioner.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ const useMenuPositioner = (
2727
menuScrollDuration?: number,
2828
scrollMenuIntoView?: boolean
2929
): [string | undefined, number] => {
30-
const [menuHeight, setMenuHeight] = useState<number>(menuHeightDefault);
31-
3230
const isMenuTopPosition = useMemo<boolean>(() => {
3331
return menuPosition === MenuPositionEnum.TOP ||
3432
(menuPosition === MenuPositionEnum.AUTO && !menuFitsBelowControl(menuRef.current));
@@ -37,6 +35,7 @@ const useMenuPositioner = (
3735
const onMenuOpenRef = useCallbackRef(onMenuOpen);
3836
const onMenuCloseRef = useCallbackRef(onMenuClose);
3937
const resetMenuHeightRef = useRef<boolean>(false);
38+
const [menuHeight, setMenuHeight] = useState<number>(menuHeightDefault);
4039
const shouldScrollRef = useLatestRef<boolean>(!isMenuTopPosition && !isMenuPortaled);
4140

4241
useUpdateEffect(() => {

0 commit comments

Comments
 (0)