Skip to content

Commit

Permalink
Merge pull request #1774 from Avaiga/bug/#1772-change_delay-does-not-…
Browse files Browse the repository at this point in the history
…work-for-input

Fix change_delay in input
  • Loading branch information
namnguyen20999 authored Sep 11, 2024
2 parents aae5778 + 72b9dc7 commit 2e5c422
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions frontend/taipy-gui/src/components/Taipy/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,23 @@ const Input = (props: TaipyInputProps) => {
(e: React.ChangeEvent<HTMLInputElement>) => {
const val = e.target.value;
setValue(val);
dispatch(createSendUpdateAction(updateVarName, val, module, onChange, propagate));
if (changeDelay === -1) {
return;
}
if (changeDelay === 0) {
Promise.resolve().then(() => {
dispatch(createSendUpdateAction(updateVarName, val, module, onChange, propagate));
});
}
if (delayCall.current > 0) {
clearTimeout(delayCall.current);
}
delayCall.current = window.setTimeout(() => {
delayCall.current = -1;
dispatch(createSendUpdateAction(updateVarName, val, module, onChange, propagate));
}, changeDelay);
},
[updateVarName, dispatch, propagate, onChange, module]
[changeDelay, dispatch, updateVarName, module, onChange, propagate]
);

const handleAction = useCallback(
Expand Down Expand Up @@ -148,7 +162,9 @@ const Input = (props: TaipyInputProps) => {
evt.preventDefault();
}
} else if (!evt.shiftKey && !evt.ctrlKey && !evt.altKey && actionKeys.includes(evt.key)) {
const val = multiline ? evt.currentTarget.querySelector("textarea")?.value : evt.currentTarget.querySelector("input")?.value;
const val = multiline
? evt.currentTarget.querySelector("textarea")?.value
: evt.currentTarget.querySelector("input")?.value;
if (changeDelay > 0 && delayCall.current > 0) {
clearTimeout(delayCall.current);
delayCall.current = -1;
Expand Down Expand Up @@ -321,8 +337,10 @@ const Input = (props: TaipyInputProps) => {
className={className}
type={showPassword && type == "password" ? "text" : type}
id={id}
inputProps={inputProps}
InputProps={muiInputProps}
slotProps={{
htmlInput: inputProps,
input: muiInputProps,
}}
label={props.label}
onChange={handleInput}
disabled={!active}
Expand Down

0 comments on commit 2e5c422

Please sign in to comment.