Skip to content

Commit

Permalink
NumberControl: Disable drag functionality on touch devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Infinite-Null committed Jan 7, 2025
1 parent 72a9996 commit 5360889
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/components/src/number-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';

const noop = () => {};

const isTouchDevice = () => {
return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
};

function UnforwardedNumberControl(
props: WordPressComponentProps< NumberControlProps, 'input', false >,
forwardedRef: ForwardedRef< any >
Expand Down Expand Up @@ -219,6 +223,8 @@ function UnforwardedNumberControl(
},
} );

const shouldEnableDrag = isDragEnabled && ! isTouchDevice();

return (
<Input
autoComplete={ autoComplete }
Expand All @@ -227,7 +233,7 @@ function UnforwardedNumberControl(
className={ classes }
dragDirection={ dragDirection }
hideHTMLArrows={ spinControls !== 'native' }
isDragEnabled={ isDragEnabled }
isDragEnabled={ shouldEnableDrag }
label={ label }
max={ max }
min={ min }
Expand Down

0 comments on commit 5360889

Please sign in to comment.