From a07e4c433c0a4722619c8300df9564a32ff68e5d Mon Sep 17 00:00:00 2001 From: gaber Date: Fri, 31 Mar 2023 20:53:39 +0200 Subject: [PATCH 1/2] fix cursor move to end when max length reached --- src/pages/iou/steps/IOUAmountPage.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/steps/IOUAmountPage.js b/src/pages/iou/steps/IOUAmountPage.js index 98112ff9d33d..ebb1f90fa438 100755 --- a/src/pages/iou/steps/IOUAmountPage.js +++ b/src/pages/iou/steps/IOUAmountPage.js @@ -124,7 +124,9 @@ class IOUAmountPage extends React.Component { */ getNewState(prevState, newAmount) { if (!this.validateAmount(newAmount)) { - return prevState; + // return prevState with shallow copy of selection object + // to set the cursor in the same position if move to end after maxLength reach. + return {...prevState, selection: {...prevState.selection}}; } const selection = this.getNewSelection(prevState.selection, prevState.amount.length, newAmount.length); return {amount: this.stripCommaFromAmount(newAmount), selection}; From 0f57d1a76ac37ddea729fc8965fb20d9e69c65ad Mon Sep 17 00:00:00 2001 From: gaber Date: Mon, 3 Apr 2023 20:37:40 +0200 Subject: [PATCH 2/2] add additional comments --- src/pages/iou/steps/IOUAmountPage.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/iou/steps/IOUAmountPage.js b/src/pages/iou/steps/IOUAmountPage.js index ebb1f90fa438..998ea89b3e8f 100755 --- a/src/pages/iou/steps/IOUAmountPage.js +++ b/src/pages/iou/steps/IOUAmountPage.js @@ -124,9 +124,9 @@ class IOUAmountPage extends React.Component { */ getNewState(prevState, newAmount) { if (!this.validateAmount(newAmount)) { - // return prevState with shallow copy of selection object - // to set the cursor in the same position if move to end after maxLength reach. - return {...prevState, selection: {...prevState.selection}}; + // Use a shallow copy of selection to trigger setSelection + // More info: https://github.com/Expensify/App/issues/16385 + return {amount: prevState.amount, selection: {...prevState.selection}}; } const selection = this.getNewSelection(prevState.selection, prevState.amount.length, newAmount.length); return {amount: this.stripCommaFromAmount(newAmount), selection};