Skip to content

Commit 3fbc94d

Browse files
committed
fix: make input colors sync with confirmation text state
1 parent 261a5ef commit 3fbc94d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

site/src/components/Dialogs/DeleteDialog/DeleteDialog.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@ export const DeleteDialog: FC<PropsWithChildren<DeleteDialogProps>> = ({
3535
const [confirmationText, setConfirmationText] = useState("");
3636
const [isFocused, setIsFocused] = useState(false);
3737

38-
const onSubmit = (e: FormEvent) => {
39-
e.preventDefault();
38+
const deletionConfirmed = name === confirmationText;
39+
const onSubmit = (event: FormEvent) => {
40+
event.preventDefault();
4041
if (deletionConfirmed) {
4142
onConfirm();
4243
}
4344
};
4445

4546
const confirmationId = `${hookId}-${DeleteDialog.name}-confirm`;
46-
const deletionConfirmed = name === confirmationText;
47-
const hasError =
48-
!isFocused && !deletionConfirmed && confirmationText.length > 0;
47+
const hasError = !deletionConfirmed && confirmationText.length > 0;
48+
const displayErrorMessage = hasError && !isFocused;
49+
const color = hasError ? "error" : "primary";
4950

5051
return (
5152
<ConfirmDialog
@@ -85,11 +86,13 @@ export const DeleteDialog: FC<PropsWithChildren<DeleteDialogProps>> = ({
8586
onFocus={() => setIsFocused(true)}
8687
onBlur={() => setIsFocused(false)}
8788
label={`Name of the ${entity} to delete`}
88-
error={hasError}
89+
color={color}
90+
error={displayErrorMessage}
8991
helperText={
90-
hasError &&
92+
displayErrorMessage &&
9193
`${confirmationText} does not match the name of this ${entity}`
9294
}
95+
InputProps={{ color }}
9396
inputProps={{
9497
["data-testid"]: "delete-dialog-name-confirmation",
9598
}}

0 commit comments

Comments
 (0)