Skip to content

feat(DateTimePicker): add IsClearable parameter - #8296

Merged
ArgoZhang merged 3 commits into
mainfrom
dev-dtm
Aug 5, 2026
Merged

feat(DateTimePicker): add IsClearable parameter#8296
ArgoZhang merged 3 commits into
mainfrom
dev-dtm

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Aug 5, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #8293

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add configurable clear icon support to DateTimePicker and tighten initialization in ValidateForm JS.

New Features:

  • Expose an IsClearable parameter and customizable ClearIcon for DateTimePicker to optionally show a clear action when nullable values are allowed.

Bug Fixes:

  • Prevent ValidateForm JS initialization from proceeding when the target element is not found in the DOM to avoid null access.

Enhancements:

  • Adjust DateTimePicker styling and markup to support a hover-clearable state and align clear icon coloring with validation state.
  • Extend DateTimePicker tests to cover clear icon behavior and disabled/non-nullable edge cases.

@bb-auto bb-auto Bot added the enhancement New feature or request label Aug 5, 2026
@bb-auto bb-auto Bot added this to the v10.9.0 milestone Aug 5, 2026
@sourcery-ai

sourcery-ai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a clearable behavior and clear icon to DateTimePicker, including new parameters, styling, and tests, and hardens ValidateForm JS initialization against missing elements.

Sequence diagram for DateTimePicker clear icon clearing value

sequenceDiagram
    actor User
    participant DateTimePicker_TValue_ as DateTimePicker

    User->>DateTimePicker: OnClear
    DateTimePicker->>DateTimePicker: OnClear
Loading

File-Level Changes

Change Details Files
Introduce clearable behavior and clear icon support in DateTimePicker, including conditional rendering and CSS.
  • Extend root CSS class builder to append an is-clearable class when the picker is clearable and enabled.
  • Add ClearClassString builder to style the clear icon consistently with validation colors.
  • Add IsClearable and ClearIcon component parameters, with default ClearIcon resolved from IconTheme.
  • Implement GetClearable helper to centralize the conditions under which clear UI is displayed (nullable, not disabled, not a button).
  • Render a clear-icon span with click handler that invokes OnClear when clearable, and adjust SCSS so validation background icons are hidden on hover when clearable.
src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.cs
src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor
src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.scss
Add unit coverage for the new clear icon behavior in DateTimePicker.
  • Create ClearIcon_Ok test that verifies clear icon presence when IsClearable is true and TValue is nullable.
  • Verify clicking the clear icon nulls the bound value and clears the input DOM value.
  • Assert that clear icon is hidden when the picker is disabled, configured as a button, or uses non-nullable TValue.
test/UnitTest/Components/DateTimePickerTest.cs
Make ValidateForm JS initialization robust when the target element is missing.
  • Early-return from init if document.getElementById(id) returns null, avoiding subsequent operations.
  • Retain existing behavior for storing the element in Data and binding when data-bb-dissubmit is true.
src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#8293 Add an IsClearable parameter (and associated ClearIcon) to DateTimePicker that controls whether a clear icon is shown.
#8293 When the clear icon is shown and clicked on a nullable DateTimePicker, clear the current value (set it to null) and clear the input display, while not rendering the clear icon when the picker is disabled, used as a button, or non-nullable.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Auto approved by bb-auto

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've found 1 issue, and left some high level feedback:

  • In ClearClassString, Color and IsValid can both contribute a text-* class, which may result in conflicting color styles on the clear icon; consider prioritizing validation state or avoiding multiple text color classes at once.
  • The early return in ValidateForm.init when el is null prevents null access but hides potential wiring issues; consider at least a console.debug/console.warn to make missing target elements easier to diagnose during integration.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `ClearClassString`, `Color` and `IsValid` can both contribute a `text-*` class, which may result in conflicting color styles on the clear icon; consider prioritizing validation state or avoiding multiple text color classes at once.
- The early return in `ValidateForm.init` when `el` is null prevents null access but hides potential wiring issues; consider at least a `console.debug`/`console.warn` to make missing target elements easier to diagnose during integration.

## Individual Comments

### Comment 1
<location path="src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor" line_range="26-28" />
<code_context>
         {
             <i class="@DateTimePickerIconClassString"></i>
         }
+        @if (GetClearable())
+        {
+            <span class="@ClearClassString" @onclick:stopPropagation @onclick="OnClear"><i class="@ClearIcon"></i></span>
+        }
     }
</code_context>
<issue_to_address>
**suggestion:** Improve accessibility of the clear icon trigger

The clear icon is currently a `<span>` with only a click handler, so it can’t be focused or activated via keyboard and has no role/label for assistive tech. Please make it keyboard- and screen-reader-friendly, e.g. by adding `tabindex="0"`, `role="button"`, handling Enter/Space in `@onkeydown` to call `OnClear`, and adding an `aria-label` if no visible text describes the action.

Suggested implementation:

```
        @if (GetClearable())
        {
            <span class="@ClearClassString"
                  role="button"
                  tabindex="0"
                  aria-label="Clear value"
                  @onclick:stopPropagation
                  @onclick="OnClear"
                  @onkeydown="OnClearKeyDown">
                <i class="@ClearIcon"></i>
            </span>
        }

```

To fully implement the keyboard support, add a key handler method (in the same `.razor` file inside an `@code` block, or in the corresponding `.razor.cs`/code-behind, depending on your existing pattern):

```csharp
private void OnClearKeyDown(Microsoft.AspNetCore.Components.Web.KeyboardEventArgs e)
{
    if (e.Key == "Enter" || e.Key == " ")
    {
        OnClear();
    }
}
```

If `Microsoft.AspNetCore.Components.Web` is not already imported in this file or the project-wide `_Imports.razor`, you may also need:

```razor
@using Microsoft.AspNetCore.Components.Web
```

If your component already uses localization or shared resource strings for ARIA text, replace the hard-coded `aria-label="Clear value"` with your localized string, e.g. `aria-label="@Localizer["Clear"]"` or a dedicated property.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c80e003) to head (112f565).

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #8296   +/-   ##
========================================
  Coverage   99.99%   100.00%           
========================================
  Files         769       769           
  Lines       34478     34491   +13     
========================================
+ Hits        34475     34491   +16     
+ Misses          3         0    -3     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@ArgoZhang
ArgoZhang merged commit d6602d2 into main Aug 5, 2026
7 checks passed
@ArgoZhang
ArgoZhang deleted the dev-dtm branch August 5, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(DateTimePicker): add IsClearable parameter

1 participant