-
-
Notifications
You must be signed in to change notification settings - Fork 362
feat(DateTimePicker): add IsButton parameter #6999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis PR introduces a new IsButton mode for DateTimePicker, allowing it to render as a styled button instead of the default input, and implements the necessary JS reset logic, unit tests, and sample updates to support and demonstrate this feature. Sequence diagram for DateTimePicker IsButton parameter change and JS resetsequenceDiagram
participant Blazor as "DateTimePicker (Blazor)"
participant JS as "DateTimePicker.razor.js"
Blazor->>Blazor: IsButton parameter changes
Blazor->>JS: InvokeVoidAsync("reset", Id)
JS->>JS: reset(id)
JS->>JS: disposeInput(input)
JS->>JS: Popover.dispose(popover)
JS->>JS: picker.popover = createPopover(...)
JS->>JS: picker.input = handlerInput(...)
JS->>Blazor: JS reset complete
Class diagram for updated DateTimePicker componentclassDiagram
class DateTimePicker {
+bool IsButton
+string? PickerButtonText
+Color ButtonColor
-string? ButtonClassString
-bool _isButton
+OnAfterRenderAsync(bool firstRender)
}
DateTimePicker --> DatePickerBody
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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 an IsButton parameter to the DateTimePicker component, allowing it to be rendered as a button instead of the default input field. When enabled, the picker displays as a button with configurable text and color.
Key Changes
- Added
IsButton,PickerButtonText, andButtonColorparameters to DateTimePicker - Implemented JavaScript
resetfunction to handle dynamic switching between button and input modes - Added localization support for the picker button text across all supported languages
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| DateTimePicker.razor | Added conditional rendering for button vs input display modes |
| DateTimePicker.razor.cs | Added new parameters and lifecycle logic to handle IsButton state changes |
| DateTimePicker.razor.js | Refactored to support dynamic mode switching with new reset function |
| DateTimePickerTest.cs | Added test coverage for IsButton parameter functionality |
| Localization files | Added PickerButtonText translations for all supported languages |
| DateTimePickers.razor | Updated demo page to showcase the new IsButton feature |
Comments suppressed due to low confidence (1)
src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor:1
- The 'IsButton' parameter binding is incorrect. It should use '@_isButton' instead of '_isButton' to properly bind the boolean value.
@namespace BootstrapBlazor.Components
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this 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 and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor:13-15` </location>
<code_context>
- disabled="@Disabled" data-bs-toggle="@Constants.DropdownToggleString" data-bs-placement="@PlacementString"
- data-bs-custom-class="@CustomClassString" @onblur="OnBlur" />
- @if (ShowIcon)
+ @if(IsButton)
{
- <i class="@DateTimePickerIconClassString"></i>
+ <button type="button" class="@ButtonClassString" disabled="@Disabled"
+ data-bs-toggle="@Constants.DropdownToggleString" data-bs-placement="@PlacementString"
+ data-bs-custom-class="@CustomClassString">@PickerButtonText</button>
</code_context>
<issue_to_address>
**suggestion:** Button element lacks accessibility attributes.
Add aria-label or aria-labelledby to ensure screen readers can identify the button's purpose, especially if the button text is missing or localized.
```suggestion
<button type="button" class="@ButtonClassString" disabled="@Disabled"
data-bs-toggle="@Constants.DropdownToggleString" data-bs-placement="@PlacementString"
data-bs-custom-class="@CustomClassString"
aria-label="@(!string.IsNullOrEmpty(PickerButtonText) ? PickerButtonText : "Open date time picker")">@PickerButtonText</button>
```
</issue_to_address>
### Comment 2
<location> `src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.js:16` </location>
<code_context>
+ Data.set(id, { el, input, invoke, options, popover });
+}
+
+const createPopover = (el, invoke, options) => {
const popover = Popover.init(el, {
dropdownSelector: el.getAttribute('data-bb-dropdown'),
</code_context>
<issue_to_address>
**issue (complexity):** Consider inlining helper functions into lifecycle methods to make the code flow more direct and readable.
Consider inlining the small helpers back into `init`/`reset`/`dispose` to remove a layer of indirection. For example:
```js
export function init(id, invoke, options) {
const el = document.getElementById(id);
if (!el) return;
const popover = Popover.init(el, {
dropdownSelector: el.getAttribute('data-bb-dropdown'),
isDisabled: () => el.classList.contains('disabled'),
hideCallback: () => {
if (invoke) invoke.invokeMethodAsync(options.triggerHideCallback);
}
});
const input = el.querySelector('.datetime-picker-input');
if (input) {
EventHandler.on(input, 'keydown', e => {
if (e.key === 'Tab' && popover.isShown()) popover.hide();
});
EventHandler.on(input, 'keyup', e => {
if (e.key === 'Escape') {
popover.hide();
input.blur();
} else if (e.key === 'Tab') {
popover.show();
}
});
}
Data.set(id, { el, popover, input, invoke, options });
}
```
Then in `reset` and `dispose` you can similarly inline off-calls:
```js
export function dispose(id) {
const data = Data.get(id);
Data.remove(id);
if (!data) return;
const { input, popover } = data;
if (input) {
EventHandler.off(input, 'keydown');
EventHandler.off(input, 'keyup');
}
Popover.dispose(popover);
}
```
This removes `createPopover`, `handlerInput`, `disposeInput` and makes the flow directly visible in each lifecycle method.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6999 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 741 741
Lines 32371 32397 +26
Branches 4481 4485 +4
=========================================
+ Hits 32371 32397 +26
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6998
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Introduce an IsButton mode for DateTimePicker that renders as a configurable button, refactor its JS interop to support dynamic resets, update the demo page and localization, and add a corresponding unit test
New Features:
Enhancements:
Documentation:
Tests: