Skip to content

Commit a2ddd90

Browse files
committed
Refactor Select
- fix missing element name
1 parent f730b9b commit a2ddd90

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/Select.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useMount } from 'react-use';
33
import { css } from '@emotion/react';
44
import styled from '@emotion/styled';
55
import { useMergeRefs } from '@gilbarbara/hooks';
6-
import is from 'is-lite';
76

87
import { getTheme } from './modules/helpers';
98
import { appearanceStyles, baseStyles, getStyledOptions, inputStyles } from './modules/system';
@@ -92,10 +91,10 @@ export const StyledSelect = styled(
9291
});
9392

9493
export const Select = forwardRef<HTMLSelectElement, SelectProps>((props, ref) => {
95-
const { defaultValue, name, onChange, value, ...rest } = { ...defaultProps, ...props };
94+
const { onChange, ...rest } = { ...defaultProps, ...props };
9695
const localRef = useRef<HTMLSelectElement>(null);
9796
const mergedRefs = useMergeRefs(localRef, ref);
98-
const [isFilled, setFilled] = useState(!!defaultValue || !!value);
97+
const [isFilled, setFilled] = useState(!!rest.defaultValue || !!rest.value);
9998

10099
useMount(() => {
101100
setFilled(!!localRef.current?.value);
@@ -105,9 +104,7 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>((props, ref) =>
105104
(event: ChangeEvent<HTMLSelectElement>) => {
106105
setFilled(!!event.target.value);
107106

108-
if (is.function(onChange)) {
109-
onChange(event);
110-
}
107+
onChange?.(event);
111108
},
112109
[onChange],
113110
);
@@ -117,9 +114,9 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>((props, ref) =>
117114
ref={mergedRefs}
118115
data-component-name="Select"
119116
filled={isFilled}
120-
id={name}
121-
{...rest}
117+
id={rest.name}
122118
onChange={handleChange}
119+
{...rest}
123120
/>
124121
);
125122
});

0 commit comments

Comments
 (0)