Skip to content

Commit

Permalink
fix(button): fix click on mobile devices
Browse files Browse the repository at this point in the history
  • Loading branch information
clementprevot committed Oct 12, 2023
1 parent b504339 commit 6c882dc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/fractal/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
props.onTouchEnd(event)
}

if ('ontouchstart' in document.documentElement) {
if (
'ontouchstart' in document.documentElement &&
!isFunction(props.onTouchStart) &&
isFunction(onClick)
) {
event.preventDefault()
}
}
Expand Down Expand Up @@ -89,7 +93,10 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
onTouchStart={handleTouchStart}
{...(isFunction(onClick) ? { onClick } : {})}
title={label}
{...omit(['className', 'dir', 'id'], props)}
{...omit(
['className', 'dir', 'id', 'onTouchEnd', 'onTouchStart'],
props,
)}
>
{icon && iconPosition === 'left' ? (
<div className={buttonIcon({ variant })}>{icon}</div>
Expand Down

0 comments on commit 6c882dc

Please sign in to comment.