Skip to content

feat(core/date-input): add clear method to reset value and validation…#2543

Draft
RamVinayMandal wants to merge 8 commits into
siemens:mainfrom
RamVinayMandal:fix-ix-3322-display-input-as-valid-when-value-is-empty-for-date
Draft

feat(core/date-input): add clear method to reset value and validation…#2543
RamVinayMandal wants to merge 8 commits into
siemens:mainfrom
RamVinayMandal:fix-ix-3322-display-input-as-valid-when-value-is-empty-for-date

Conversation

@RamVinayMandal
Copy link
Copy Markdown
Collaborator

@RamVinayMandal RamVinayMandal commented May 11, 2026

💡 What is the current behavior?

  • When a ix-date-input (not required) has an invalid value and the user clears the field, the component continues to display as invalid
  • When a ix-date-input is required and the user clears the field, the component should show as invalid but was not consistently doing
  • Additionally, when the component is placed inside a , the internal validation (red border, error message) was still being triggered despite the form opting out of browser/in-built validation.

JIRA Number: #2595

🆕 What is the new behavior?

  • An empty value in ix-date-input that is not required is now treated as valid — no is-invalid class is applied when the input is blank
  • When a required ix-date-input value is cleared, the field correctly shows as invalid
  • correctly suppresses all visual validation feedback (is-invalid class and error messages) for ix-date-input. Date parsing is still performed internally to keep the calendar picker state consistent — only the visual error indicators are suppressed
  • Validation correctly resumes when switching between required and non-required states
  • The clear() method resets both the value and the touched/validation state cleanly
  • focusInputIfKeyboardMode extracted to shared picker-input.util.ts for reuse across picker-based inputs
  • Min/max date bounds check fixed to use >=/<= operators (resolves SonarQube lint issue)

Note: The clear() method on ix-date-input is tagged with @since 5.1.0. Please verify this matches the actual target release version and we need to update the JSDoc tag if needed before merging.

🏁 Checklist

A pull request can only be merged if all of these conditions are met (where applicable):

  • 🦮 Accessibility (a11y) features were implemented
  • 🗺️ Internationalization (i18n) - no hard coded strings
  • 📲 Responsiveness - components handle viewport changes and content overflow gracefully
  • 📕 Add or update a Storybook story
  • 📄 Documentation was reviewed/updated siemens/ix-docs
  • 🧪 Unit tests were added/updated and pass (pnpm test)
  • 📸 Visual regression tests were added/updated and pass (Guide)
  • 🧐 Static code analysis passes (pnpm lint)
  • 🏗️ Successful compilation (pnpm build, changes pushed)

👨‍💻 Help & support

… state

Co-authored-by: Copilot <copilot@github.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 11, 2026

🦋 Changeset detected

Latest commit: 7db8833

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

This PR includes changesets to release 6 packages
Name Type
@siemens/ix Minor
@siemens/ix-aggrid Major
@siemens/ix-angular Minor
@siemens/ix-docs Minor
@siemens/ix-react Minor
@siemens/ix-vue Minor

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

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a clear() method to the ix-date-input component and refines its validation logic to better handle novalidate forms and programmatic value resets. The changes include a new utility for clearing inputs and extensive regression tests. Review feedback suggests that date parsing should still be performed even when visual validation is suppressed to avoid invalid internal states. Furthermore, the reviewer recommends explicitly synchronizing validation classes during programmatic clears and ensuring that asynchronous validation calls are correctly awaited in property watchers.

Comment thread packages/core/src/components/date-input/date-input.tsx Outdated
Comment thread packages/core/src/components/date-input/date-input.tsx
Comment thread packages/core/src/components/date-input/date-input.tsx Outdated
@RamVinayMandal RamVinayMandal self-assigned this May 12, 2026
@RamVinayMandal
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a clear() method to the ix-date-input component and refactors its validation logic to correctly handle novalidate forms and programmatic value resets. The changes include adding a syncValidationClasses method, updating the value watcher, and providing comprehensive regression tests. Feedback focuses on ensuring that asynchronous validation methods are properly awaited, stale validation classes are removed when validation is suppressed (e.g., in novalidate forms), and that accessibility coverage is maintained with an axe-based component test as per the repository style guide.

Comment on lines 99 to 105
@Watch('value') watchValuePropHandler(newValue: string) {
if (!newValue && this.required && !this.isClearing) {
this.touched = true;
this.syncValidationClasses();
}
this.onInput(newValue);
}
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.

medium

The syncValidationClasses method is asynchronous and should be awaited to ensure the visual state is updated correctly before proceeding. Additionally, syncValidationClasses should be called regardless of whether the new value is empty to ensure that the ix-invalid--required class is removed when a value is provided to a previously empty required field.

Suggested change
@Watch('value') watchValuePropHandler(newValue: string) {
if (!newValue && this.required && !this.isClearing) {
this.touched = true;
this.syncValidationClasses();
}
this.onInput(newValue);
}
@Watch('value')
async watchValuePropHandler(newValue: string) {
if (!newValue && this.required && !this.isClearing) {
this.touched = true;
}
await this.syncValidationClasses();
await this.onInput(newValue);
}

Comment on lines +370 to +385
private async syncValidationClasses(): Promise<void> {
const skipValidation = await shouldSuppressInternalValidation(this);
if (skipValidation) {
return;
}

const hasValue = !!this.value;
if (this.required) {
this.hostElement.classList.toggle(
'ix-invalid--required',
!hasValue && this.touched
);
} else {
this.hostElement.classList.remove('ix-invalid--required');
}
}
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.

medium

When skipValidation is true (e.g., in a novalidate form), the component should ensure that any existing validation classes are removed from the host element. The current implementation returns early, which might leave stale error indicators if the validation state changes dynamically.

  private async syncValidationClasses(): Promise<void> {
    const skipValidation = await shouldSuppressInternalValidation(this);
    const hasValue = !!this.value;

    const isInvalidRequired =
      !skipValidation && !!this.required && !hasValue && this.touched;
    this.hostElement.classList.toggle('ix-invalid--required', isInvalidRequired);
  }
References
  1. Maintain consistency with existing component patterns (e.g., using a generic customError for validation) over introducing more specific but inconsistent implementations.

});
});

regressionTest.describe('date-input validation scenarios', () => {
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.

medium

Per the repository style guide, component changes require accessibility coverage with an axe-based component test. Please add an automated accessibility check for the date-input component, especially covering the new validation states.

References
  1. For component changes, check that accessibility coverage exists with an axe-based component test. (link)

Comment on lines +58 to +61
const skipValidation = await shouldSuppressInternalValidation(comp);
if (skipValidation) {
return;
}
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.

medium

If validation is suppressed via novalidate, any existing visual validation classes (like ix-invalid--validity-invalid) should be removed to ensure the UI correctly reflects the suppressed state.

Suggested change
const skipValidation = await shouldSuppressInternalValidation(comp);
if (skipValidation) {
return;
}
const skipValidation = await shouldSuppressInternalValidation(comp);
if (skipValidation) {
comp.hostElement.classList.remove('ix-invalid--validity-invalid');
return;
}
References
  1. Maintain consistency with existing component patterns (e.g., using a generic customError for validation) over introducing more specific but inconsistent implementations.

@sonarqubecloud
Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant