Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Aug 22, 2025

Link issues

fixes #6669

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

Enable configurable time picking modes in DateTimePicker by adding PickTimeMode parameter and corresponding enum, implement dropdown-based time picker UI alongside existing clock picker, fix DateTimeRange end-of-day logic, and update demo sample.

New Features:

  • Add PickTimeMode parameter to DateTimePicker to toggle between clock and dropdown time picking
  • Introduce DateTimePickerTimeMode enum

Bug Fixes:

  • Fix DateTimeRange default end-of-day calculation to use milliseconds rather than seconds
  • Ensure end value resets to full day when start is after end

Enhancements:

  • Separate flags and handlers for clock and dropdown pickers and conditionally render them
  • Add dropdown time picker panel with SCSS styling and improved markup formatting

Documentation:

  • Update sample to include TimeFormat usage

@Copilot Copilot AI review requested due to automatic review settings August 22, 2025 08:05
@bb-auto bb-auto bot added the enhancement New feature or request label Aug 22, 2025
@bb-auto bb-auto bot added this to the 9.9.0 milestone Aug 22, 2025
Copy link
Contributor

sourcery-ai bot commented Aug 22, 2025

Reviewer's Guide

This PR implements a new PickTimeMode parameter in the DateTimePicker component, allowing users to choose between dropdown and clock-based time selection. It introduces internal flags to manage both picker modes, extends the markup and styling to support a dropdown time picker, updates toggle behaviors, adjusts date range defaults to use milliseconds precision, and includes minor formatting cleanups in the DatePicker and TimePicker components.

Class diagram for DateTimePicker and DatePickerBody with PickTimeMode

classDiagram
    class DateTimePickerTimeMode {
        <<enum>>
        PickTimeByDropdown
        PickTimeByClock
    }
    class DateTimePicker {
        +PickTimeMode: DateTimePickerTimeMode
    }
    class DatePickerBody {
        +PickTimeMode: DateTimePickerTimeMode
        -_showClockPicker: bool
        -_showTimePicker: bool
        +OnShowTimePicker()
        +OnConfirmTime(TimeSpan)
        +OnCloseTime()
        +SwitchTimeView()
        +SwitchDateView()
        +HasSeconds(): bool
    }
    DateTimePicker --> DatePickerBody : uses
    DatePickerBody --> DateTimePickerTimeMode : uses
Loading

Class diagram for DateTimeRange sidebar item changes

classDiagram
    class DateTimeRange {
        -SidebarItems: List<SidebarItem>
        +OnParametersSet()
        +UpdateValue(DateTime)
    }
    class SidebarItem {
        +Text: string
        +StartDateTime: DateTime
        +EndDateTime: DateTime
    }
    DateTimeRange --> SidebarItem : contains
Loading

Class diagram for new DateTimePickerTimeMode enum

classDiagram
    class DateTimePickerTimeMode {
        <<enum>>
        PickTimeByDropdown
        PickTimeByClock
    }
Loading

File-Level Changes

Change Details Files
Introduce PickTimeMode enum and parameter for DateTimePicker
  • Added DateTimePickerTimeMode enum file
  • Declared PickTimeMode parameter with default value
  • Conditionally render clock vs dropdown picker in Razor
src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs
src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor
src/BootstrapBlazor/Components/DateTimePicker/DateTimePickerTimeMode.cs
Implement dropdown-based time picker UI and logic
  • Added _showTimePicker flag and related Show/Close/Confirm handlers
  • Created TimePickerClassString builder
  • Inserted dropdown TimePicker markup and styles
src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs
src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor
src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.scss
Refactor clock picker toggle with _showClockPicker
  • Removed old ShowTimePicker property
  • Replaced class toggles and method resets with _showClockPicker
  • Updated SwitchTimeView, SwitchDateView, Clear, and Reset methods
src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs
Adjust default date range end calculations to milliseconds
  • Replaced AddSeconds(-1) with AddMilliseconds(-1) in range presets
  • Set SelectedValue.End to Start.AddDays(1).AddMilliseconds(-1)
src/BootstrapBlazor/Components/DateTimeRange/DateTimeRange.razor.cs
Minor UI and markup cleanups
  • Reformatted input attributes in DateTimePicker.razor
  • Removed empty @code block in TimePicker.razor
  • Updated sample usage to include TimeFormat setting
src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor
src/BootstrapBlazor/Components/TimePicker/TimePicker.razor
src/BootstrapBlazor.Server/Components/Samples/DateTimePickers.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#6669 Add a PickTimeMode parameter to the DateTimePicker component to allow selection between different time picking modes.

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

Copy link
Contributor

@Copilot 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 adds a new PickTimeMode parameter to the DateTimePicker component that allows users to choose between dropdown-style time selection and the existing clock-style time selection. The change also includes precision improvements for date range handling and some minor formatting updates.

  • Introduces DateTimePickerTimeMode enum with PickTimeByDropdown and PickTimeByClock options
  • Updates DateTimePicker to support both time selection modes with appropriate UI rendering
  • Improves date range precision by using milliseconds instead of seconds for end times

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
DateTimePickerTimeMode.cs New enum defining time selection modes
DatePickerBody.razor Adds conditional rendering for dropdown time picker UI
DatePickerBody.razor.cs Implements dropdown time picker functionality and state management
DatePickerBody.razor.scss Styles for the new dropdown time picker panel
DateTimePicker.razor Minor formatting improvement for input attributes
DateTimeRange.razor.cs Updates date range calculations to use milliseconds precision
TimePicker.razor Removes empty code block
DateTimePickers.razor Updates demo to use specific time format

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Aug 22, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Refactor the repeated _showTimePicker/_showClockPicker resets into a single helper method to reduce duplication and ensure consistent state resets when switching views.
  • Update the sample DateTimePickers.razor to demonstrate the new PickTimeMode parameter (both dropdown and clock modes) so users can see how to apply it.
  • In DateTimeRange, consider using AddTicks(-1) instead of AddMilliseconds(-1) for end-of-day calculations to capture the very last moment of the day more precisely.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Refactor the repeated _showTimePicker/_showClockPicker resets into a single helper method to reduce duplication and ensure consistent state resets when switching views.
- Update the sample DateTimePickers.razor to demonstrate the new PickTimeMode parameter (both dropdown and clock modes) so users can see how to apply it.
- In DateTimeRange, consider using AddTicks(-1) instead of AddMilliseconds(-1) for end-of-day calculations to capture the very last moment of the day more precisely.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor.cs:737` </location>
<code_context>
+        StateHasChanged();
+    }
+
+    private bool HasSeconds()
+    {
+        if (TimeFormat != null)
</code_context>

<issue_to_address>
TimeFormat.Contains('s') may not reliably detect seconds in all format strings.

Consider parsing the format string for valid time specifiers instead of relying on Contains('s'), which may not accurately detect seconds in all cases.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    private bool HasSeconds()
    {
        if (TimeFormat != null)
        {
            return TimeFormat.Contains('s');
        }

        return TimePickerOption.ShowSecond;
    }
=======
    private bool HasSeconds()
    {
        if (!string.IsNullOrEmpty(TimeFormat))
        {
            return ContainsSecondSpecifier(TimeFormat);
        }

        return TimePickerOption.ShowSecond;
    }

    /// <summary>
    /// Checks if the time format string contains a valid seconds specifier.
    /// </summary>
    /// <param name="format">The time format string.</param>
    /// <returns>True if seconds specifier is present; otherwise, false.</returns>
    private static bool ContainsSecondSpecifier(string format)
    {
        // Check for common .NET and custom format specifiers for seconds
        // "ss" (two-digit seconds), "s" (single-digit seconds), "S" (fractional seconds)
        // You can adjust this logic based on your supported formats
        return format.Contains("ss") || format.Contains("s") || format.Contains("S");
    }
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `src/BootstrapBlazor/Components/DateTimePicker/DatePickerBody.razor:168` </location>
<code_context>
             </div>
         </div>
     </div>
+    @if (IsDateTimeMode && PickTimeMode == DateTimePickerTimeMode.PickTimeByDropdown)
+    {
+        <div class="@TimePickerClassString">
</code_context>

<issue_to_address>
Consider accessibility and keyboard navigation for the new dropdown time picker.

Check if keyboard users and screen readers can interact with the time picker. Add ARIA attributes or keyboard event handlers as needed.

Suggested implementation:

```
            <input type="text"
                   autocomplete="off"
                   readonly
                   class="form-control"
                   value="@CurrentTime.ToString(TimeFormat)"
                   aria-haspopup="listbox"
                   aria-expanded="@IsTimePickerOpen"
                   aria-label="Select time"
                   tabindex="0"
                   @onclick="@OnShowTimePicker"
                   @onkeydown="@HandleTimePickerKeyDown" />

```

```
            <TimePicker Value="CurrentTime" HasSeconds="HasSeconds()"
                        ShowRequired="false" ShowLabel="false" SkipValidate="true"
                        OnClose="OnCloseTime" OnConfirm="OnConfirmTime"
                        role="listbox"
                        aria-label="Time options"></TimePicker>

```

You will need to implement the following in the code-behind or @code section of this Razor file:
1. Add a property `bool IsTimePickerOpen` to track if the dropdown is open (for `aria-expanded`).
2. Implement the method `HandleTimePickerKeyDown(KeyboardEventArgs e)` to handle Enter/Space keys to open the time picker.
3. Ensure that focus management and closing the dropdown with Escape are handled for full keyboard accessibility.
</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.

Copy link

codecov bot commented Aug 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d54014e) to head (556b7a1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6670   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          739       739           
  Lines        31674     31707   +33     
  Branches      4459      4460    +1     
=========================================
+ Hits         31674     31707   +33     
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 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.

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 PickTimeMode parameter
1 participant