File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed
Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 77 cursorPointer ,
88 elementSupportsDisabled ,
99 classNameToString ,
10- setUserSelectOnBody ,
10+ setUserSelectNone ,
11+ resetUserSelect ,
1112} from './utils' ;
1213import {
1314 PolymorphicForwardRefExoticComponent ,
@@ -666,8 +667,8 @@ const InteractiveNotMemoized: PolymorphicForwardRefExoticComponent<
666667 // because iOS will still select nearby text if it is only set on the element
667668 React . useEffect ( ( ) => {
668669 if ( inTouchActiveState && useExtendedTouchActive ) {
669- setUserSelectOnBody ( 'none' ) ;
670- return ( ) => setUserSelectOnBody ( '' ) ;
670+ setUserSelectNone ( ) ;
671+ return resetUserSelect ;
671672 }
672673 return ;
673674 } , [ inTouchActiveState , useExtendedTouchActive ] ) ;
Original file line number Diff line number Diff line change @@ -61,7 +61,22 @@ export const classNameToString = (className: any) =>
6161// to prevent the browser from selecting text on long touch
6262// note that it needs to be set on the body not the RI element
6363// because iOS will still select nearby text
64- export const setUserSelectOnBody = ( value : 'none' | '' ) : void => {
65- document . body . style . userSelect = value ;
66- document . body . style . webkitUserSelect = value ;
64+ let pendingUserSelectReset = false ;
65+
66+ export const setUserSelectNone = ( ) : void => {
67+ pendingUserSelectReset = false ;
68+ document . body . style . userSelect = 'none' ;
69+ document . body . style . webkitUserSelect = 'none' ;
70+ } ;
71+
72+ export const resetUserSelect = ( ) : void => {
73+ pendingUserSelectReset = true ;
74+ // use setTimeout delay for reset because iOS will select text shortly after touch end
75+ // when the touch end event occurs near the time that iOS would normally select text
76+ window . setTimeout ( ( ) => {
77+ if ( pendingUserSelectReset ) {
78+ document . body . style . userSelect = '' ;
79+ document . body . style . webkitUserSelect = '' ;
80+ }
81+ } , 250 ) ;
6782} ;
You can’t perform that action at this time.
0 commit comments