Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Oct 9, 2025

Link issues

fixes #6847

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 keyboard handling for Tab and Escape keys in DateTimePicker to improve popover interaction and ensure event listeners are cleaned up on disposal

New Features:

  • Support hiding the popover with Tab key on keydown when it is shown
  • Support hiding the popover and blurring the input on Escape key
  • Support showing the popover on Tab key on keyup

Enhancements:

  • Unregister keyboard event handlers when disposing the DateTimePicker

Copilot AI review requested due to automatic review settings October 9, 2025 04:05
@bb-auto bb-auto bot added the enhancement New feature or request label Oct 9, 2025
@bb-auto bb-auto bot added this to the 9.11.0 milestone Oct 9, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 9, 2025

Reviewer's Guide

This PR enhances the DateTimePicker component by integrating keyboard support for Tab and Escape keys through EventHandler, updating popover show/hide logic, and ensuring proper cleanup of event listeners upon disposal.

Sequence diagram for DateTimePicker Tab/Escape keyboard event handling

sequenceDiagram
participant User as actor User
participant Input as DateTimePicker Input
participant Popover as Popover
participant EventHandler as EventHandler
User->>Input: Press Tab (keydown)
Input->>Popover: isShown()
alt Popover is shown
Popover->>Popover: hide()
end
User->>Input: Press Escape (keyup)
Input->>Popover: hide()
Input->>Input: blur()
User->>Input: Press Tab (keyup)
Input->>Popover: show()
Loading

File-Level Changes

Change Details Files
Added Tab/Escape keyboard event handling in DateTimePicker
  • Imported EventHandler module
  • Selected the input element with querySelector
  • Extended data stored to include input reference
  • Registered keydown handler to hide popover on Tab when open
  • Registered keyup handler to hide on Escape (and blur) and show on Tab
src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.js
Enhanced disposal to unregister event handlers and dispose popover correctly
  • Destructured input and popover from stored data
  • Removed keydown and keyup listeners via EventHandler.off
  • Called Popover.dispose on the popover instance
src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#6847 Support Tab keyboard event in DateTimePicker component.
#6847 Support Esc (Escape) keyboard event in DateTimePicker component.

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 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 keyboard event support to the DateTimePicker component, specifically handling Tab and Escape key interactions to improve user experience and accessibility.

  • Added Tab key support to show/hide the popover based on key event type
  • Added Escape key support to hide the popover and blur the input field
  • Implemented proper event handler cleanup in the dispose function

Reviewed Changes

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

File Description
DateTimePicker.razor.js Added keyboard event handling for Tab/Esc keys with proper event cleanup
BootstrapBlazor.csproj Version bump from beta05 to beta06

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

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:

  • The Tab key logic currently hides the popover on keydown then shows it again on keyup, which might cause a flicker or unexpected behavior—consider consolidating this into a single event or adjusting the timing to ensure a smooth UX.
  • In dispose(), using EventHandler.off without a specific handler reference will remove all keydown/keyup listeners on the input; you should store each callback and pass it to off() to avoid unregistering unrelated handlers.
  • You may need to call e.preventDefault() or check focus state when handling Tab to avoid interfering with native tab navigation and ensure the popover only toggles when appropriate.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The Tab key logic currently hides the popover on keydown then shows it again on keyup, which might cause a flicker or unexpected behavior—consider consolidating this into a single event or adjusting the timing to ensure a smooth UX.
- In dispose(), using EventHandler.off without a specific handler reference will remove all keydown/keyup listeners on the input; you should store each callback and pass it to off() to avoid unregistering unrelated handlers.
- You may need to call e.preventDefault() or check focus state when handling Tab to avoid interfering with native tab navigation and ensure the popover only toggles when appropriate.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.js:22` </location>
<code_context>
             }
         }
     });
+    const input = el.querySelector('.datetime-picker-input');
     const dateTimePicker = {
-        el,
</code_context>

<issue_to_address>
**issue:** Consider handling the case where input is not found.

Without a check for a missing input, attaching event handlers may fail if the selector does not match. Adding error handling will make the code more robust to DOM changes.
</issue_to_address>

### Comment 2
<location> `src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.js:29` </location>
<code_context>
-    Data.set(id, dateTimePicker)
+    Data.set(id, dateTimePicker);
+
+    EventHandler.on(input, 'keydown', e => {
+        if (e.key === 'Tab' && popover.isShown()) {
+            popover.hide();
</code_context>

<issue_to_address>
**issue (complexity):** Consider replacing two EventHandler listeners with a single native keydown handler to simplify event management.

Here’s one way to collapse both listeners into a single native handler (no EventHandler wrapper) and still be able to clean it up on dispose:

```js
// init(...)
const input = el.querySelector('.datetime-picker-input');

function onKeydown(e) {
  switch (e.key) {
    case 'Escape':
      popover.hide();
      input.blur();
      break;
    case 'Tab':
      popover[popover.isShown() ? 'hide' : 'show']();
      break;
  }
}

input.addEventListener('keydown', onKeydown);

Data.set(id, { input, popover, onKeydown });
```

```js
// dispose(id)
const data = Data.get(id);
if (data) {
  const { input, popover, onKeydown } = data;
  input.removeEventListener('keydown', onKeydown);
  Popover.dispose(popover);
  Data.remove(id);
}
```

This:

- Uses a single `keydown` listener for both `Tab` and `Escape`  
- Eliminates the extra indirection of `EventHandler`  
- Stores the raw handler so you can clean it up properly in `dispose` without extra branching.
</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.

@codecov
Copy link

codecov bot commented Oct 9, 2025

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6848   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          739       739           
  Lines        31755     31755           
  Branches      4466      4466           
=========================================
  Hits         31755     31755           
Flag Coverage Δ
BB 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.

@ArgoZhang ArgoZhang merged commit b83f1fd into main Oct 9, 2025
7 checks passed
@ArgoZhang ArgoZhang deleted the fix-dtm branch October 9, 2025 04:08
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): support Tab/Esc keyboard event

2 participants