Skip to content

Commit 1df195d

Browse files
authored
fix: cursor move to last position (nervosnetwork#3318)
* fix: cursor move to last position * fix: comment
1 parent 0a2deb6 commit 1df195d

File tree

1 file changed

+15
-2
lines changed
  • packages/neuron-ui/src/components/DepositDialog

1 file changed

+15
-2
lines changed

packages/neuron-ui/src/components/DepositDialog/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useMemo } from 'react'
1+
import React, { useCallback, useMemo, useState } from 'react'
22
import { Slider } from 'office-ui-fabric-react'
33
import { Trans, useTranslation } from 'react-i18next'
44
import TextField from 'widgets/TextField'
@@ -66,6 +66,7 @@ const DepositDialog = ({
6666
}: DepositDialogProps) => {
6767
const [t, { language }] = useTranslation()
6868
const disabled = !isTxGenerated
69+
const [isTyping, setIsTyping] = useState(false)
6970
const { isBalanceReserved, onIsBalanceReservedChange, setIsBalanceReserved } = useBalanceReserved()
7071
const { depositValue, onChangeDepositValue, slidePercent, onSliderChange, resetDepositValue } = useDepositValue(
7172
balance,
@@ -108,6 +109,16 @@ const DepositDialog = ({
108109

109110
const isChinese = language === 'zh' || language.startsWith('zh-')
110111

112+
const handleBlur = useCallback(() => {
113+
setIsTyping(false)
114+
}, [setIsTyping])
115+
116+
const handleFocus = useCallback(() => {
117+
setIsTyping(true)
118+
}, [setIsTyping])
119+
120+
const inputValue = useMemo(() => maxDepositValue ?? depositValue, [maxDepositValue, depositValue])
121+
111122
return (
112123
<Dialog
113124
show={show}
@@ -151,8 +162,10 @@ const DepositDialog = ({
151162
className={styles.depositValue}
152163
width="100%"
153164
field="depositValue"
154-
value={localNumberFormatter(maxDepositValue ?? depositValue)}
165+
value={isTyping ? inputValue : localNumberFormatter(inputValue)}
155166
onChange={onChangeDepositValue}
167+
onBlur={handleBlur}
168+
onFocus={handleFocus}
156169
suffix="CKB"
157170
required
158171
error={errorMessage}

0 commit comments

Comments
 (0)