Skip to content

fix(forms): colour a control that is already known to be invalid - #8215

Closed
talissoncosta wants to merge 1 commit into
mainfrom
fix/input-invalid-state-before-blur
Closed

fix(forms): colour a control that is already known to be invalid#8215
talissoncosta wants to merge 1 commit into
mainfrom
fix/input-invalid-state-before-blur

Conversation

@talissoncosta

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Split out of #8177, where it was scope creep.

A text field only turns red once it has been blurred. Submit a form with
Enter and you get the error message underneath a grey border, so nothing
points at the field that is wrong.

autoValidate already meant "do not wait for the field to be touched", but it
was copied into state at mount, so it could not react to an error arriving
later. Reading it live is the fix:

-const [shouldValidate, setShouldValidate] = useState(!!value || !!autoValidate)
+const [hasBeenTouched, setHasBeenTouched] = useState(!!value)
-const invalid = shouldValidate && !isValid
+const invalid = (hasBeenTouched || !!autoValidate) && !isValid

InputGroup already had an isInvalid prop, but it only put a class on the
wrapper and never reached the control. It now forwards to Input.

No new prop, and no call site has to change.

How did you test this code?

The behaviour is opt-in, so the 100-odd existing InputGroup call sites are
unaffected: isInvalid currently has no consumers on main, and autoValidate
has exactly one (RegexTester), which passes a static true and so behaves
identically either way.

  • Storybook, Components/Forms/InputGroup: the new InvalidBeforeBlur story should show a red border on an untouched field. On main the same story is grey.
  • The other InputGroup stories (WithError, MultipleErrors, Disabled, Sizes) should be unchanged.
  • Components/Forms/Input stories unchanged.
  • A form where a field validates on blur should still stay neutral until you leave it, i.e. no form goes red before you have typed.

Input only shows the invalid state after a blur, so a form submitted
with Enter shows the error text with a grey border. autoValidate already
meant "do not wait for a touch", it was just seeded into state at mount
and so could not react to an error arriving later. Reading it live fixes
that, and InputGroup's isInvalid prop now reaches the control instead of
only setting a class on the wrapper.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ready Ready Preview Aug 4, 2026 12:19pm
flagsmith-frontend-staging Ready Ready Preview Aug 4, 2026 12:19pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Aug 4, 2026 12:19pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5e8d6f6e-904a-4d75-b188-fa7a1c9e63aa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant