Skip to content

Commit 9191111

Browse files
committed
Add debounce on claim input
1 parent e368d2c commit 9191111

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

frontend/package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"eslint-plugin-html": "^8.1.1",
2727
"eslint-plugin-import": "^2.29.1",
2828
"husky": "^9.0.11",
29+
"lodash": "^4.17.21",
2930
"react": "^18.2.0",
3031
"react-dom": "^18.2.0",
3132
"tw-colors": "^3.3.1",
@@ -34,6 +35,7 @@
3435
},
3536
"devDependencies": {
3637
"@types/dot-object": "^2.1.6",
38+
"@types/lodash": "^4.17.1",
3739
"@types/react": "^18.2.66",
3840
"@types/react-dom": "^18.2.22",
3941
"@typescript-eslint/eslint-plugin": "^7.2.0",

frontend/src/components/InputWithRightText.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { InputMessage, InputProps } from '@massalabs/react-ui-kit';
2+
import { debounce } from 'lodash';
23

34
export interface InputWithRightTextProps extends InputProps {
45
rightText: string;
56
}
67

78
export function InputWithRightText(props: InputWithRightTextProps) {
8-
const { error, warning, success, disable, customClass, rightText, ...rest } =
9-
props;
9+
const {
10+
error,
11+
warning,
12+
success,
13+
onChange,
14+
disable,
15+
customClass,
16+
rightText,
17+
...rest
18+
} = props;
1019

1120
const disabledClass = disable ? 'border-0' : '';
1221
const errorClass = error ? 'border-s-error' : '';
@@ -15,6 +24,10 @@ export function InputWithRightText(props: InputWithRightTextProps) {
1524
const messageClass =
1625
errorClass || warningClass || successClass || disabledClass;
1726

27+
let debouncedOnChange = onChange;
28+
if (onChange) {
29+
debouncedOnChange = debounce(onChange, 350);
30+
}
1831
return (
1932
<div className="flex-row">
2033
<div className="grid-cols-2">
@@ -24,6 +37,7 @@ export function InputWithRightText(props: InputWithRightTextProps) {
2437
className={`w-full default-input h-12 pl-3 pr-10 mb-1 ${messageClass} ${customClass}`}
2538
type="text"
2639
disabled={disable}
40+
onChange={debouncedOnChange}
2741
{...rest}
2842
/>
2943
</div>

0 commit comments

Comments
 (0)