BUGFIX: Prompt does not reset text value (#1539)

This commit is contained in:
catloversg 2024-08-04 14:01:01 +07:00 committed by GitHub
parent 1ed47b4bc9
commit 7c7293b687
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -52,8 +52,9 @@ export function PromptManager({ hidden }: { hidden: boolean }): React.ReactEleme
};
let PromptContent = PromptMenuBoolean;
if (prompt?.options?.type && ["text", "select"].includes(prompt.options.type))
if (prompt?.options?.type && ["text", "select"].includes(prompt.options.type)) {
PromptContent = types[prompt.options.type];
}
const resolve = (value: boolean | string): void => {
prompt?.resolve(value);
setPrompt(null);
@ -94,10 +95,17 @@ function PromptMenuBoolean({ resolve }: IContentProps): React.ReactElement {
);
}
function PromptMenuText({ resolve }: IContentProps): React.ReactElement {
function PromptMenuText({ prompt, resolve }: IContentProps): React.ReactElement {
const [value, setValue] = useState("");
const submit = (): void => resolve(value);
const submit = (): void => {
resolve(value);
setValue("");
};
useEffect(() => {
setValue("");
}, [prompt]);
const onInput = (event: React.ChangeEvent<HTMLInputElement>): void => {
setValue(event.target.value);
@ -133,7 +141,14 @@ function PromptMenuText({ resolve }: IContentProps): React.ReactElement {
function PromptMenuSelect({ prompt, resolve }: IContentProps): React.ReactElement {
const [value, setValue] = useState("");
const submit = (): void => resolve(value);
const submit = (): void => {
resolve(value);
setValue("");
};
useEffect(() => {
setValue("");
}, [prompt]);
const onChange = (event: SelectChangeEvent): void => {
setValue(event.target.value);
@ -158,7 +173,11 @@ function PromptMenuSelect({ prompt, resolve }: IContentProps): React.ReactElemen
return (
<>
<div style={{ display: "flex", alignItems: "center", paddingTop: "10px" }}>
<Select onChange={onChange} value={value} style={{ flex: "1 0 auto" }}>
<Select
onChange={onChange}
value={prompt.options?.choices.includes(value) ? value : ""}
style={{ flex: "1 0 auto" }}
>
{getItems(prompt.options?.choices || [])}
</Select>
<Button onClick={submit} disabled={value === ""}>