Skip to content

refactor: conditionally inserting invalid message depending on validity#5850

Open
sarahbrng wants to merge 22 commits intomainfrom
5285-describe-required-fields-that-add-todo-placeholder-elements-when-omitted
Open

refactor: conditionally inserting invalid message depending on validity#5850
sarahbrng wants to merge 22 commits intomainfrom
5285-describe-required-fields-that-add-todo-placeholder-elements-when-omitted

Conversation

@sarahbrng
Copy link
Copy Markdown
Contributor

@sarahbrng sarahbrng commented Jan 21, 2026

Proposed changes

Fix Form Component Validation Message Display

Problem

Form components displayed placeholder validation messages ("TODO: Add an invalidMessage") even when validation wasn't active. Messages appeared with display: none (hidden but present in DOM), creating unnecessary DOM nodes and potential accessibility concerns.

Root Cause

Premature initialization of _invalidMessage in onMount() and redundant onUpdate() hooks caused validation messages to be computed and rendered before actual validation occurred.

Solution

  • Removed eager _invalidMessage initialization from onMount()
  • Eliminated redundant onUpdate() validation message hooks
  • Moved message computation to handleValidation() for lazy evaluation
  • Removed SCSS display: none workarounds

Validation messages now only appear when validation actually runs.

resolves #5285

Types of changes

  • Bugfix (non-breaking change that fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (improvements to existing components or architectural decisions)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Further comments

🔭🐙🐈 Test this branch here: https://design-system.deutschebahn.com/core-web/review/5285-describe-required-fields-that-add-todo-placeholder-elements-when-omitted

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 21, 2026

🦋 Changeset detected

Latest commit: cd130cc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@db-ux/ngx-core-components Patch
@db-ux/react-core-components Patch
@db-ux/wc-core-components Patch
@db-ux/v-core-components Patch
@db-ux/core-foundations Patch
@db-ux/core-components Patch
@db-ux/core-stylelint Patch
@db-ux/core-migration Patch
@db-ux/agent-cli Patch
@db-ux/core-eslint-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sarahbrng sarahbrng marked this pull request as ready for review January 21, 2026 12:53
@mfranzke
Copy link
Copy Markdown
Collaborator

mfranzke commented Jan 21, 2026

instead of introducing the condition, should we question the TODO message itself? Or in other words, if we introduce this condition, the TODO message wouldn't appear any more, would it? Than we could as well talk about that message itself.

that was a misunderstanding.

@mfranzke mfranzke changed the title 5285 describe required fields that add todo placeholder elements when omitted refactor: conditionally inserting invalid message depending on validity Jan 21, 2026
@mfranzke
Copy link
Copy Markdown
Collaborator

@sarahbrng is there CSS code that could get removed by this change ?

mfranzke and others added 5 commits January 22, 2026 21:23
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…placeholder-elements-when-omitted

Resolved merge conflicts:
- Accepted main's version of all custom-select screenshot files (6 files)
- Binary PNG files cannot be automatically merged
- Screenshots will be regenerated during next visual regression test run
github-actions bot and others added 2 commits January 27, 2026 11:04
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…d-fields-that-add-todo-placeholder-elements-when-omitted

# Conflicts:
#	__snapshots__/checkbox/patternhub/checkbox-properties-should-match-screenshot.png
#	__snapshots__/checkbox/showcase/mobile-chrome/DBCheckbox-should-match-screenshot-1/DBCheckbox-should-match-screenshot.png
#	__snapshots__/custom-select/showcase/chromium-highContrast/DBCustomSelect-should-match-screenshot-1/DBCustomSelect-should-match-screenshot.png
#	__snapshots__/custom-select/showcase/chromium/DBCustomSelect-should-match-screenshot-1/DBCustomSelect-should-match-screenshot.png
#	__snapshots__/custom-select/showcase/firefox/DBCustomSelect-should-match-screenshot-1/DBCustomSelect-should-match-screenshot.png
#	__snapshots__/custom-select/showcase/mobile-chrome/DBCustomSelect-should-match-screenshot-1/DBCustomSelect-should-match-screenshot.png
#	__snapshots__/input/showcase/chromium-highContrast/DBInput-should-match-screenshot-1/DBInput-should-match-screenshot.png
#	__snapshots__/input/showcase/chromium/DBInput-should-match-screenshot-1/DBInput-should-match-screenshot.png
#	__snapshots__/input/showcase/firefox/DBInput-should-match-screenshot-1/DBInput-should-match-screenshot.png
#	__snapshots__/input/showcase/mobile-chrome/DBInput-should-match-screenshot-1/DBInput-should-match-screenshot.png
#	__snapshots__/input/showcase/mobile-safari/DBInput-should-match-screenshot-1/DBInput-should-match-screenshot.png
#	__snapshots__/input/showcase/webkit/DBInput-should-match-screenshot-1/DBInput-should-match-screenshot.png
#	__snapshots__/select/showcase/chromium-highContrast/DBSelect-should-match-screenshot-1/DBSelect-should-match-screenshot.png
#	__snapshots__/select/showcase/chromium/DBSelect-should-match-screenshot-1/DBSelect-should-match-screenshot.png
#	__snapshots__/select/showcase/firefox/DBSelect-should-match-screenshot-1/DBSelect-should-match-screenshot.png
#	__snapshots__/select/showcase/mobile-chrome/DBSelect-should-match-screenshot-1/DBSelect-should-match-screenshot.png
#	__snapshots__/select/showcase/webkit/DBSelect-should-match-screenshot-1/DBSelect-should-match-screenshot.png
#	__snapshots__/switch/showcase/mobile-chrome/DBSwitch-should-match-screenshot-1/DBSwitch-should-match-screenshot.png
#	__snapshots__/textarea/showcase/chromium-highContrast/DBTextarea-should-match-screenshot-1/DBTextarea-should-match-screenshot.png
#	__snapshots__/textarea/showcase/chromium/DBTextarea-should-match-screenshot-1/DBTextarea-should-match-screenshot.png
#	__snapshots__/textarea/showcase/firefox/DBTextarea-should-match-screenshot-1/DBTextarea-should-match-screenshot.png
#	__snapshots__/textarea/showcase/mobile-chrome/DBTextarea-should-match-screenshot-1/DBTextarea-should-match-screenshot.png
#	__snapshots__/textarea/showcase/webkit/DBTextarea-should-match-screenshot-1/DBTextarea-should-match-screenshot.png
#	packages/components/src/components/checkbox/checkbox.lite.tsx
#	packages/components/src/components/input/input.lite.tsx
#	packages/components/src/components/select/select.lite.tsx
#	packages/components/src/components/switch/switch.lite.tsx
#	packages/components/src/components/textarea/textarea.lite.tsx
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@nmerget nmerget moved this from 🏗 In progress to 🎁 Ready for review in UX Engineering Team Backlog Feb 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes placeholder "TODO" validation messages from form components by conditionally rendering invalid messages only when validation is actually active.

Changes:

  • Removed DEFAULT_INVALID_MESSAGE and DEFAULT_VALID_MESSAGE constants that contained placeholder text
  • Added hasInvalidState() method to validation state types
  • Wrapped invalid message rendering in <Show when={state.hasInvalidState()}> conditionals across 6 components
  • Removed eager _invalidMessage initialization from onMount() and redundant onUpdate() hooks
  • Updated test snapshots to reflect removed placeholder text

Reviewed changes

Copilot reviewed 14 out of 23 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
packages/components/src/shared/model.ts Added hasInvalidState() method to FromValidState type
packages/components/src/shared/constants.ts Removed DEFAULT_INVALID_MESSAGE and DEFAULT_VALID_MESSAGE placeholder constants
packages/components/src/components/textarea/textarea.lite.tsx Refactored to conditionally render invalid messages, removed eager initialization
packages/components/src/components/input/input.lite.tsx Refactored to conditionally render invalid messages, removed eager initialization
packages/components/src/components/select/select.lite.tsx Refactored to conditionally render invalid messages, removed eager initialization
packages/components/src/components/checkbox/checkbox.lite.tsx Refactored to conditionally render invalid messages, removed eager initialization
packages/components/src/components/switch/switch.lite.tsx Refactored to conditionally render invalid messages, removed eager initialization
packages/components/src/components/custom-select/custom-select.lite.tsx Refactored to conditionally render invalid messages, removed eager initialization
snapshots/*.png Updated visual regression test snapshots
snapshots/*.yaml Updated accessibility tree snapshots removing placeholder text

@mfranzke mfranzke moved this from ⏰ready for release to 🎶 Waiting for feedback in UX Engineering Team Backlog Feb 27, 2026
@github-actions github-actions bot added the 📕documentation Improvements or additions to documentation label Mar 3, 2026
@nmerget nmerget moved this from 🎶 Waiting for feedback to ⏰ready for release in UX Engineering Team Backlog Mar 3, 2026
@nmerget nmerget enabled auto-merge (squash) March 3, 2026 09:46
@nmerget nmerget requested a review from michaelmkraus March 3, 2026 09:46
@nmerget nmerget moved this from ⏰ready for release to 🎁 Ready for review in UX Engineering Team Backlog Mar 3, 2026
@michaelmkraus michaelmkraus moved this from 🎁 Ready for review to 👀 Actively In Review in UX Engineering Team Backlog Mar 3, 2026
id={state._invalidMessageId}
size="small"
semantic="critical">
{state._invalidMessage}
Copy link
Copy Markdown
Contributor

@michaelmkraus michaelmkraus Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{state._invalidMessage}
{state._invalidMessage || props.invalidMessage}

state._invalidMessage was removed from onMount and onUpdate, therefore, it is initially undefined and if validation is initially invalid (prop validation="invalid"), we would see an empty error-box Therefore, we should fall back to props.invalidMessage if the state is still empty. (for all components)

{props.message}
</DBInfotext>
</Show>
<Show when={state.hasValidState()}>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Show when={state.hasValidState() && !!props.validMessage}>

Gets shown if props.validation === 'valid'. If the developer didn't set props.validMessage, we get an empty green box.

@@ -142,12 +143,10 @@ export default function DBCustomSelect(props: DBCustomSelectProps) {
if (!selectRef?.validity.valid || props.validation === 'invalid') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!selectRef?.validity.valid || props.validation === 'invalid') {
if (state.hasInvalidState()) {

In all other components we use state.hasInvalidState(). I think it has been forgotten to be replaced here.

@michaelmkraus michaelmkraus moved this from 👀 Actively In Review to 🎶 Waiting for feedback in UX Engineering Team Backlog Mar 4, 2026
nmerget added 2 commits March 12, 2026 13:59
…d-fields-that-add-todo-placeholder-elements-when-omitted

# Conflicts:
#	.config/cspellignorewords.txt
github-actions bot and others added 2 commits March 12, 2026 13:38
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@nmerget nmerget self-assigned this Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏘components 🛠️configuration 📕documentation Improvements or additions to documentation 📺showcases Changes to 1-n showcases

Projects

Status: No status
Status: 🎶 Waiting for feedback

Development

Successfully merging this pull request may close these issues.

Describe required fields that add TODO placeholder elements when omitted

5 participants