Skip to content

Commit 9abb12d

Browse files
committed
fix: Paste
1 parent c723a67 commit 9abb12d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/canonical-bridge/src/views/index.tsx

+16-1
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,27 @@ export const CanonicalBridge = (props: CanonicalBridgeProps) => {
4141

4242
useEffect(() => {
4343
if (typeof document !== 'undefined') {
44-
const inputElement = document.querySelector('.bccb-widget-transfer-input')
44+
const inputElement = document.querySelector('.bccb-widget-transfer-input') as HTMLInputElement | null
4545
if (inputElement) {
4646
inputElement.setAttribute('pattern', '^[0-9]*[.,]?[0-9]*$')
47+
48+
const handlePaste = (e: ClipboardEvent) => {
49+
const pastedValue = e?.clipboardData?.getData('Text')
50+
51+
if (!pastedValue || !/^[0-9]*[.,]?[0-9]*$/.test(pastedValue)) {
52+
e.preventDefault()
53+
}
54+
}
55+
56+
inputElement.addEventListener('paste', handlePaste)
4757
refresh()
58+
59+
return () => {
60+
inputElement.removeEventListener('paste', handlePaste)
61+
}
4862
}
4963
}
64+
return undefined
5065
}, [refresh])
5166

5267
const config = useMemo<ICanonicalBridgeConfig>(

0 commit comments

Comments
 (0)