Skip to content

Commit ad73434

Browse files
committed
Fix: Remove error message, when input is valid
1 parent 87007d6 commit ad73434

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

validation-output.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,27 @@ class ValidationOutput extends HTMLElement {
159159
return;
160160
}
161161

162-
// We don't remove the error message, we just remove the `has-error` state.
162+
// We don't remove the error message if there is a transition, we just remove the `has-error` state.
163+
// It will trigger the transition, and after the transition, the error message will be removed.
163164
// This makes it easier to style and animate the error message.
165+
if (!this.#internals.states.has("has-error")) return;
166+
167+
const transitionDuration = parseFloat(
168+
getComputedStyle(this).transitionDuration,
169+
);
164170
this.#internals.states.delete("has-error");
171+
if (transitionDuration === 0) {
172+
this.innerHTML = "";
173+
return;
174+
}
175+
176+
const handleTransitionEnd = () => {
177+
if (this.matches(":user-invalid")) return;
178+
this.innerHTML = "";
179+
};
180+
this.addEventListener("transitionend", handleTransitionEnd, {
181+
once: true,
182+
});
165183
}
166184

167185
#setErrorMessage(message: string | DocumentFragment) {

0 commit comments

Comments
 (0)