Skip to content

Commit

Permalink
Disable click-to-select on touch devices (use onTouchStart)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf committed Mar 21, 2024
1 parent 64c4967 commit be1856a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/dataviews/src/view-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ function TableRow( {
setIsHovered( false );
};

// Will be set to true if `onTouchStart` fires. This happens before
// `onClick` and can be used to exclude touchscreen devices from certain
// behaviours.
const isTouchDevice = useRef( false );

return (
<tr
className={ classnames( 'dataviews-view-table__row', {
Expand All @@ -258,8 +263,14 @@ function TableRow( {
} ) }
onMouseEnter={ handleMouseEnter }
onMouseLeave={ handleMouseLeave }
onTouchStart={ () => {
isTouchDevice.current = true;
} }
onClick={ () => {
if ( document.getSelection().type !== 'Range' ) {
if (
! isTouchDevice.current &&
document.getSelection().type !== 'Range'
) {
if ( ! isSelected ) {
onSelectionChange(
data.filter( ( _item ) => {
Expand Down

0 comments on commit be1856a

Please sign in to comment.