File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
packages/x-date-pickers/src/internals/hooks/useField Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ export const addPositionPropertiesToSections = <TSection extends FieldSection>(
7777export const useFieldV6TextField : UseFieldTextField < false > = ( params ) => {
7878 const isRtl = useRtl ( ) ;
7979 const focusTimeoutRef = React . useRef < ReturnType < typeof setTimeout > > ( ) ;
80+ const selectionSyncTimeoutRef = React . useRef < ReturnType < typeof setTimeout > > ( ) ;
8081
8182 const {
8283 forwardedProps : {
@@ -162,12 +163,16 @@ export const useFieldV6TextField: UseFieldTextField<false> = (params) => {
162163 inputRef . current . setSelectionRange ( selectionStart , selectionEnd ) ;
163164 }
164165 }
165- setTimeout ( ( ) => {
166+ clearTimeout ( selectionSyncTimeoutRef . current ) ;
167+ selectionSyncTimeoutRef . current = setTimeout ( ( ) => {
166168 // handle case when the selection is not updated correctly
167169 // could happen on Android
168170 if (
169171 inputRef . current &&
170172 inputRef . current === getActiveElement ( document ) &&
173+ // The section might loose all selection, where `selectionStart === selectionEnd`
174+ // https://github.com/mui/mui-x/pull/13652
175+ inputRef . current . selectionStart === inputRef . current . selectionEnd &&
171176 ( inputRef . current . selectionStart !== selectionStart ||
172177 inputRef . current . selectionEnd !== selectionEnd )
173178 ) {
@@ -428,6 +433,7 @@ export const useFieldV6TextField: UseFieldTextField<false> = (params) => {
428433
429434 return ( ) => {
430435 clearTimeout ( focusTimeoutRef . current ) ;
436+ clearTimeout ( selectionSyncTimeoutRef . current ) ;
431437 } ;
432438 } , [ ] ) ; // eslint-disable-line react-hooks/exhaustive-deps
433439
You can’t perform that action at this time.
0 commit comments