Skip to content

Commit

Permalink
fixed form switch card not using watch
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Oct 29, 2024
1 parent 74c6321 commit 11bd1a1
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions packages/stateless/components/inputs/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,25 @@ export const FormSwitchCard = <
BooleanFieldName extends BooleanFieldNames<FV>
>({
fieldName,
value,
value: _value,
watch,
setValue,
onToggle,
...props
}: FormSwitchWrapperProps<SwitchCardProps, FV, BooleanFieldName>) => (
<SwitchCard
enabled={!!value}
onClick={() => {
const newValue = !value
setValue(fieldName, newValue as any)
onToggle?.(newValue)
}}
sizing="sm"
tooltipIconSize="sm"
{...props}
/>
)
}: FormSwitchWrapperProps<SwitchCardProps, FV, BooleanFieldName>) => {
const value = _value ?? watch?.(fieldName)

return (
<SwitchCard
enabled={!!value}
onClick={() => {
const newValue = !value
setValue(fieldName, newValue as any)
onToggle?.(newValue)
}}
sizing="sm"
tooltipIconSize="sm"
{...props}
/>
)
}

0 comments on commit 11bd1a1

Please sign in to comment.