Skip to content

Commit

Permalink
fix(Swap): prevent onclick from firing twice by moving from label to …
Browse files Browse the repository at this point in the history
…inner input
  • Loading branch information
benjitrosch committed Oct 5, 2023
1 parent c3ebfd4 commit 6478b1b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Swap/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { twMerge } from 'tailwind-merge'
import { IComponentBaseProps } from '../types'
import { wrapWithElementIfInvalid } from '../utils'

export type SwapProps = React.LabelHTMLAttributes<HTMLLabelElement> &
export type SwapProps = Omit<React.LabelHTMLAttributes<HTMLLabelElement>, 'onClick' | 'onChange'> &
IComponentBaseProps & {
onElement: ReactNode | ReactNode[]
offElement: ReactNode | ReactNode[]
active?: boolean
rotate?: boolean
flip?: boolean
onClick?: React.MouseEventHandler<HTMLInputElement>
onChange?: React.FormEventHandler<HTMLInputElement>
}

const Swap = React.forwardRef<HTMLLabelElement, SwapProps>(
Expand All @@ -24,6 +26,8 @@ const Swap = React.forwardRef<HTMLLabelElement, SwapProps>(
flip,
dataTheme,
className,
onClick,
onChange,
...props
},
ref
Expand Down Expand Up @@ -53,7 +57,7 @@ const Swap = React.forwardRef<HTMLLabelElement, SwapProps>(

return (
<label {...props} data-theme={dataTheme} className={classes} ref={ref}>
<input type="checkbox" />
<input type="checkbox" onClick={onClick} onChange={onChange} />
{onEl}
{offEl}
</label>
Expand Down

0 comments on commit 6478b1b

Please sign in to comment.