Skip to content

Commit 2434849

Browse files
committed
- memoize Value.tsx component
- Fix issue with special scenario: when openMenuOnClick = false and the device is touch-capable, the touch event triggered by the caret icon does not open the menu - Add new group "placeholder" to theme object that has "animation" key with a fade-in default - Related to new theme addition above, only apply that animation on renders after the first render/component mount
1 parent d061841 commit 2434849

20 files changed

+82
-38
lines changed

docs/asset-manifest.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"files": {
3-
"main.js": "./main.70591e57.iframe.bundle.js",
3+
"main.js": "./main.4df3933d.iframe.bundle.js",
44
"runtime~main.js": "./runtime~main.f398e60b.iframe.bundle.js",
5-
"vendors~main.js": "./vendors~main.0c4c3500.iframe.bundle.js",
6-
"vendors~main.js.map": "./vendors~main.0c4c3500.iframe.bundle.js.map",
5+
"vendors~main.js": "./vendors~main.96fe7a9f.iframe.bundle.js",
6+
"vendors~main.js.map": "./vendors~main.96fe7a9f.iframe.bundle.js.map",
77
"iframe.html": "./iframe.html",
8-
"vendors~main.0c4c3500.iframe.bundle.js.LICENSE.txt": "./vendors~main.0c4c3500.iframe.bundle.js.LICENSE.txt"
8+
"vendors~main.96fe7a9f.iframe.bundle.js.LICENSE.txt": "./vendors~main.96fe7a9f.iframe.bundle.js.LICENSE.txt"
99
},
1010
"entrypoints": [
1111
"runtime~main.f398e60b.iframe.bundle.js",
12-
"vendors~main.0c4c3500.iframe.bundle.js",
13-
"main.70591e57.iframe.bundle.js"
12+
"vendors~main.96fe7a9f.iframe.bundle.js",
13+
"main.4df3933d.iframe.bundle.js"
1414
]
1515
}

docs/iframe.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,4 @@
130130

131131

132132

133-
window['FRAMEWORK_OPTIONS'] = {"fastRefresh":true};</script><script src="runtime~main.f398e60b.iframe.bundle.js"></script><script src="vendors~main.0c4c3500.iframe.bundle.js"></script><script src="main.70591e57.iframe.bundle.js"></script></body></html>
133+
window['FRAMEWORK_OPTIONS'] = {"fastRefresh":true};</script><script src="runtime~main.f398e60b.iframe.bundle.js"></script><script src="vendors~main.96fe7a9f.iframe.bundle.js"></script><script src="main.4df3933d.iframe.bundle.js"></script></body></html>

docs/main.4df3933d.iframe.bundle.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/main.70591e57.iframe.bundle.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/vendors~main.0c4c3500.iframe.bundle.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/vendors~main.0c4c3500.iframe.bundle.js renamed to docs/vendors~main.96fe7a9f.iframe.bundle.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/vendors~main.0c4c3500.iframe.bundle.js.LICENSE.txt renamed to docs/vendors~main.96fe7a9f.iframe.bundle.js.LICENSE.txt

File renamed without changes.

docs/vendors~main.96fe7a9f.iframe.bundle.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Select.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,15 +695,15 @@ const Select = forwardRef<SelectRef, SelectProps>((
695695
}, [onInputChange]);
696696

697697
const handleOnClearMouseDown = useCallback((e: MouseOrTouchEvent<HTMLDivElement>): void => {
698-
suppressMouseOrTouchEvent(e);
699698
setSelectedOption(EMPTY_ARRAY);
699+
suppressMouseOrTouchEvent(e);
700700
focusInput();
701701
}, []);
702702

703703
const handleOnCaretMouseDown = useCallback((e: MouseOrTouchEvent<HTMLDivElement>): void => {
704-
suppressMouseOrTouchEvent(e, e.type === 'mousedown');
705704
focusInput();
706705
menuOpenRef.current ? setMenuOpen(false) : openMenuAndFocusOption(OptionIndexEnum.FIRST);
706+
suppressMouseOrTouchEvent(e);
707707
}, [openMenuAndFocusOption]);
708708

709709
const renderMenu = !lazyLoadMenu || (lazyLoadMenu && menuOpen);

src/components/value/Value.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import React, { Fragment } from 'react';
1+
import React, { memo, Fragment } from 'react';
22
import MultiValue from './MultiValue';
33
import { isArrayWithLength } from '../../utils';
44
import styled, { css } from 'styled-components';
5+
import { useFirstRenderState } from '../../hooks';
56

67
import type { MultiParams } from '../../Select';
8+
import type { ReactNode, ReactText } from 'react';
79
import type { OptionData, SelectedOption } from '../../types';
8-
import type { ReactNode, ReactText, FunctionComponent } from 'react';
10+
11+
type PlaceholderProps = Readonly<{
12+
isFirstRender: boolean;
13+
}>;
914

1015
export type ValueProps = Readonly<{
1116
isMulti?: boolean;
@@ -33,13 +38,13 @@ const SingleValue = styled.div`
3338
max-width: calc(100% - 0.5rem);
3439
`;
3540

36-
const Placeholder = styled.div<Pick<ValueProps, 'isMulti'>>`
41+
const Placeholder = styled.div<PlaceholderProps>`
3742
${_singleValueBaseStyle}
3843
color: ${({ theme }) => theme.color.placeholder};
39-
${({ theme, isMulti }) => isMulti && css`animation: ${theme.multiValue.animation};`}
44+
${({ theme, isFirstRender }) => !isFirstRender && css`animation: ${theme.placeholder.animation};`}
4045
`;
4146

42-
const Value: FunctionComponent<ValueProps> = ({
47+
const Value = memo<ValueProps>(({
4348
isMulti,
4449
inputValue,
4550
placeholder,
@@ -49,6 +54,9 @@ const Value: FunctionComponent<ValueProps> = ({
4954
renderMultiOptions,
5055
removeSelectedOption
5156
}) => {
57+
// Do not apply Placeholder animation on initial render/mount of component
58+
const isFirstRender = useFirstRenderState();
59+
5260
if (
5361
inputValue &&
5462
(!isMulti || (isMulti && (!isArrayWithLength(selectedOption) || renderMultiOptions)))
@@ -58,7 +66,7 @@ const Value: FunctionComponent<ValueProps> = ({
5866

5967
if (!isArrayWithLength(selectedOption)) {
6068
return (
61-
<Placeholder isMulti={isMulti}>
69+
<Placeholder isFirstRender={isFirstRender}>
6270
{placeholder}
6371
</Placeholder>
6472
);
@@ -88,6 +96,8 @@ const Value: FunctionComponent<ValueProps> = ({
8896
))}
8997
</Fragment>
9098
);
91-
};
99+
});
100+
101+
Value.displayName = 'Value';
92102

93103
export default Value;

0 commit comments

Comments
 (0)