Skip to content

Commit

Permalink
fix: add onChange
Browse files Browse the repository at this point in the history
  • Loading branch information
lisalupi committed Nov 22, 2024
1 parent 9e9cb59 commit c9b5d71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .changeset/spotty-cups-approve.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"@ultraviolet/form": patch
"@ultraviolet/form": minor
---

New component `<SwitchButtonField />`
12 changes: 9 additions & 3 deletions packages/form/src/components/SwitchButtonField/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FieldPath, FieldValues } from '@ultraviolet/form'
import type { FieldPath, FieldValues, PathValue } from '@ultraviolet/form'
import { SwitchButton } from '@ultraviolet/ui'
import type { ComponentProps } from 'react'
import { useController } from 'react-hook-form'
Expand All @@ -8,7 +8,7 @@ type SwitchButtonFieldProps<
TFieldValues extends FieldValues,
TFieldName extends FieldPath<TFieldValues>,
> = BaseFieldProps<TFieldValues, TFieldName> &
Omit<ComponentProps<typeof SwitchButton>, 'value' | 'onChange' | 'name'> & {
Omit<ComponentProps<typeof SwitchButton>, 'value' | 'name'> & {
name: FieldPath<TFieldValues>
}

Expand All @@ -23,6 +23,7 @@ export const SwitchButtonField = <
control,
shouldUnregister,
onBlur,
onChange,
onFocus,
tooltip,
className,
Expand All @@ -40,7 +41,12 @@ export const SwitchButtonField = <
name={name}
leftButton={leftButton}
rightButton={rightButton}
onChange={field.onChange}
onChange={event => {
field.onChange(event)
onChange?.(
event.target as PathValue<TFieldValues, TFieldName> | undefined,
)
}}
value={field.value}
tooltip={tooltip}
size={size}
Expand Down

0 comments on commit c9b5d71

Please sign in to comment.