Skip to content

fix(datebox): keep optional field valid after backspace clear#307

Merged
desmondinho merged 1 commit into
mainfrom
fix/datebox-invalid-state-on-clear
May 9, 2026
Merged

fix(datebox): keep optional field valid after backspace clear#307
desmondinho merged 1 commit into
mainfrom
fix/datebox-invalid-state-on-clear

Conversation

@desmondinho
Copy link
Copy Markdown
Contributor

@desmondinho desmondinho commented May 9, 2026

Description

Closes #301

When a LumexDatebox is bound to a nullable type with Required="false" and Clearable="true", pressing Backspace to clear the field puts it into an error state instead of the expected valid empty state.

The browser's native <input type="date"> is segmented (year/month/day). Backspacing one segment makes the value serialize to "" per the HTML spec, but the input also gains validity.badInput = true with a non-empty validationMessage ("Please enter a valid value."). The component was unconditionally surfacing that native message via LumexInputFieldBase.SetValidationMessageAsync, so the field flipped to invalid even though the bound value parsed cleanly to null.

What's been done?

  • In LumexInputFieldBase.SetValidationMessageAsync, skip the native validationMessage probe when the field is non-required and empty — an empty value on an optional field is valid by definition. This also benefits LumexNumbox and LumexTextbox, which share the same base.
  • Added a regression test (ShouldStayValidWhenClearedAndNotRequired) that simulates the browser returning a badInput message and asserts the cleared, non-required field stays valid (data-invalid="false") with Value == null.

Checklist

  • My code follows the project's coding style and guidelines.
  • I have included inline docs for my changes, where applicable.
  • I have added, updated or removed tests according to my changes.
  • All tests are passing.
  • There's an open issue for the PR that I am making.

Summary by CodeRabbit

Bug Fixes

  • Non-required input fields now correctly display as valid when cleared, instead of potentially showing validation errors
  • Improved validation handling for optional fields to properly recognize empty values as valid state

Review Change Stack

@desmondinho desmondinho linked an issue May 9, 2026 that may be closed by this pull request
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2d2a306b-7121-4b17-9b88-6727c0778134

📥 Commits

Reviewing files that changed from the base of the PR and between a859e5a and 59aad2b.

📒 Files selected for processing (2)
  • src/LumexUI/Components/Bases/LumexInputFieldBase.razor.cs
  • tests/LumexUI.Tests/Components/Datebox/DateboxTests.razor

📝 Walkthrough

Walkthrough

This PR addresses the invalid state issue when clearing a non-required LumexDatebox with backspace. The fix adds an early-exit condition in SetValidationMessageAsync that treats empty non-required fields as valid without consulting the browser validation API, and includes a test verifying the corrected behavior.

Changes

Non-Required Empty Field Validation Fix

Layer / File(s) Summary
Validation Logic
src/LumexUI/Components/Bases/LumexInputFieldBase.razor.cs
SetValidationMessageAsync now skips the JS validation call and sets ValidationMessage to null when the field is non-required and empty, avoiding false invalid states.
Test Infrastructure & Verification
tests/LumexUI.Tests/Components/Datebox/DateboxTests.razor
JS interop handler for validation messages is stored in a reusable field, and a new test ShouldStayValidWhenClearedAndNotRequired verifies that clearing a non-required LumexDatebox leaves it in a valid state.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A datebox once sad when cleared with care,
Now stays quite content in the empty air.
Not required, so when backspace was pressed,
Validation sleeps—no fuss, just rest!
hop hop 🌱

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: keeping optional datebox fields valid when cleared via backspace, which is the primary change in the PR.
Description check ✅ Passed The description comprehensively covers the issue, root cause, and all changes made, matching the required template structure with all sections properly filled out.
Linked Issues check ✅ Passed The code changes directly address issue #301 by modifying SetValidationMessageAsync to skip native validation messages for non-required empty fields and adding the regression test as specified.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the reported issue: the base class logic for empty optional fields and the test case validating the fix behavior.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/datebox-invalid-state-on-clear

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.11%. Comparing base (19b89dc) to head (59aad2b).
⚠️ Report is 178 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #307      +/-   ##
==========================================
- Coverage   96.95%   93.11%   -3.85%     
==========================================
  Files          70      166      +96     
  Lines        1542     2756    +1214     
  Branches      150      405     +255     
==========================================
+ Hits         1495     2566    +1071     
- Misses         28       98      +70     
- Partials       19       92      +73     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@desmondinho desmondinho merged commit d333222 into main May 9, 2026
4 checks passed
@desmondinho desmondinho deleted the fix/datebox-invalid-state-on-clear branch May 9, 2026 15:39
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.

LumexDatebox invalid state on backspace press

1 participant