Skip to content

Commit 2819085

Browse files
committed
Fix type
- Fix onClick - Add showCheck prop
1 parent b8f0756 commit 2819085

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

packages/components/src/components/Select/ControlledCheckbox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function ControlledCheckbox() {
4646
value={subValue}
4747
>
4848
<SelectTrigger asChild>
49-
<SelectOption>
49+
<SelectOption showCheck={false}>
5050
<Flex alignItems="center" justifyContent="space-between" w="100%">
5151
Option 5<IconArrow />
5252
</Flex>

packages/components/src/components/Select/ControlledRadio.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export function ControlledRadio() {
1717
const handleChange = (value: string) => {
1818
setValue(value)
1919
}
20+
const [subValue, setSubValue] = useState('')
21+
const handleSubChange = (value: string) => {
22+
setSubValue(value)
23+
}
2024
return (
2125
<Select onValueChange={handleChange} type="radio" value={value}>
2226
<SelectTrigger>Select {value}</SelectTrigger>
@@ -26,9 +30,9 @@ export function ControlledRadio() {
2630
<SelectDivider />
2731
<SelectOption value="Option 3">Option 3</SelectOption>
2832
<SelectOption value="Option 4">Option 4</SelectOption>
29-
<Select type="radio">
33+
<Select onValueChange={handleSubChange} type="radio" value={subValue}>
3034
<SelectTrigger asChild>
31-
<SelectOption>
35+
<SelectOption showCheck={false}>
3236
<Flex alignItems="center" justifyContent="space-between" w="100%">
3337
Option 5<IconArrow />
3438
</Flex>
@@ -41,8 +45,26 @@ export function ControlledRadio() {
4145
transform: 'translateX(100%)',
4246
})}
4347
>
44-
<SelectOption value="Option 6">Option 6</SelectOption>
45-
<SelectOption value="Option 7">Option 7</SelectOption>
48+
<SelectOption
49+
onClick={(value) => {
50+
if (value) {
51+
setSubValue(value)
52+
}
53+
}}
54+
value="Option 6"
55+
>
56+
Option 6
57+
</SelectOption>
58+
<SelectOption
59+
onClick={(value) => {
60+
if (value) {
61+
setSubValue(value)
62+
}
63+
}}
64+
value="Option 7"
65+
>
66+
Option 7
67+
</SelectOption>
4668
</SelectContainer>
4769
</Select>
4870
</SelectContainer>

packages/components/src/components/Select/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,21 @@ export function SelectContainer({ children, ...props }: ComponentProps<'div'>) {
183183
}
184184

185185
interface SelectOptionProps extends Omit<ComponentProps<'div'>, 'onClick'> {
186-
onClick?: (value?: string, e?: React.MouseEvent<HTMLDivElement>) => void
186+
onClick?: (
187+
value: string | undefined,
188+
e?: React.MouseEvent<HTMLDivElement>,
189+
) => void
187190
disabled?: boolean
188191
value?: string
192+
showCheck?: boolean
189193
}
190194

191195
export function SelectOption({
192196
disabled,
193197
onClick,
194198
children,
195199
value,
200+
showCheck = true,
196201
...props
197202
}: SelectOptionProps) {
198203
const { setOpen, setValue, value: selectedValue, type } = useSelect()
@@ -202,7 +207,10 @@ export function SelectOption({
202207
setOpen(false)
203208
}
204209

205-
const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {
210+
const handleClick = (
211+
value: string | undefined,
212+
e: React.MouseEvent<HTMLDivElement>,
213+
) => {
206214
if (onClick) {
207215
onClick(value, e)
208216
return
@@ -239,14 +247,14 @@ export function SelectOption({
239247
}[type]
240248
}
241249
h="40px"
242-
onClick={disabled ? undefined : handleClick}
250+
onClick={disabled ? undefined : (e) => handleClick(value, e)}
243251
px="10px"
244252
styleOrder={1}
245253
transition="background-color 0.1s ease-in-out"
246254
typography={isSelected ? 'inputBold' : 'inputText'}
247255
{...props}
248256
>
249-
{
257+
{showCheck &&
250258
{
251259
checkbox: (
252260
<Box
@@ -291,8 +299,7 @@ export function SelectOption({
291299
</>
292300
),
293301
default: null,
294-
}[type]
295-
}
302+
}[type]}
296303
{children}
297304
</Flex>
298305
)

0 commit comments

Comments
 (0)