Add DefaultValue parameter to BitInputBase (#8186)#12534
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough
ChangesDefaultValue centralization in BitInputBase
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/BlazorUI/Bit.BlazorUI/Components/Inputs/OtpInput/BitOtpInput.razor.cs (1)
166-179: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winRoute
DefaultValuethrough OTP normalization first.This path writes the raw default into
Valuebefore any OTP-specific sanitization runs. WithLength=4, aDefaultValueof"12345"leavesValue == "12345"while the rendered boxes show1234; numeric OTPs also bypass the existing digit-only checks here. Normalize the default with the same length/type rules used for user input, then syncValuefrom the normalized slots so the public value matches the UI.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/BlazorUI/Bit.BlazorUI/Components/Inputs/OtpInput/BitOtpInput.razor.cs` around lines 166 - 179, The OnInitialized flow in BitOtpInput is assigning DefaultValue directly through SetDefaultValue without applying the OTP normalization used for user input. Update the initialization path so the default value is first sanitized and truncated according to Length and OTP type rules, then use the normalized slots to populate Value and the input state. Keep the fix localized around SetDefaultValue, Value, and the initialization setup in BitOtpInput so the public value matches the rendered boxes.src/BlazorUI/Bit.BlazorUI/Components/Inputs/CircularTimePicker/BitCircularTimePicker.razor.cs (1)
330-341: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winNormalize
DefaultValuebefore seeding_hourand_minute.
SetDefaultValue()copies the rawTimeSpan?, but this component only rendersCurrentValue?.Hours/?.Minutesand later rebuildsValuefrom those fields. A default likenew TimeSpan(25, 30, 0)will render as01:30whileValuestill holds25:30:00, then silently change on the first interaction. Route the default through the same time-of-day normalization this component uses for user input before storing it.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/BlazorUI/Bit.BlazorUI/Components/Inputs/CircularTimePicker/BitCircularTimePicker.razor.cs` around lines 330 - 341, The initialization in BitCircularTimePicker.OnInitialized seeds _hour and _minute from CurrentValue after calling SetDefaultValue, but DefaultValue is not normalized to the component’s time-of-day representation. Update SetDefaultValue and/or the OnInitialized path so DefaultValue is routed through the same normalization used for user input before assigning CurrentValue, then let _hour and _minute derive from that normalized value. Use the BitCircularTimePicker component members SetDefaultValue, CurrentValue, _hour, and _minute to keep the rendered time and stored value consistent.
🧹 Nitpick comments (2)
src/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/DateRangePicker/BitDateRangePickerTests.cs (1)
1170-1172: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDon't couple this test to object identity.
Line 1170 only passes when the component keeps the exact same
BitDateRangePickerValueinstance around. The real contract here is the selected start/end dates, which you already assert on Lines 1171-1172, so the object-level equality check is overfitting the current implementation.Suggested cleanup
- Assert.AreEqual(defaultValue, component.Instance.Value); Assert.AreEqual(defaultValue.StartDate, component.Instance.Value!.StartDate); Assert.AreEqual(defaultValue.EndDate, component.Instance.Value!.EndDate);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/DateRangePicker/BitDateRangePickerTests.cs` around lines 1170 - 1172, The test in BitDateRangePickerTests is over-coupled to object identity by asserting the component’s Value is the exact same BitDateRangePickerValue instance as defaultValue. Remove the instance-equality assertion and keep the contract focused on the selected dates by relying on the StartDate and EndDate checks already present in the test.src/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/DatePicker/BitDatePickerTests.cs (1)
1037-1049: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd the
Value-wins-over-DefaultValuecase.This only covers the happy path. The regression-prone part of the new
BitInputBase.SetDefaultValue()contract is thatDefaultValuemust not overwrite an explicitValue, so please add an adjacent test that passes both parameters and assertsValuewins.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/DatePicker/BitDatePickerTests.cs` around lines 1037 - 1049, Add an adjacent test for BitDatePicker that covers the Value-over-DefaultValue behavior in the new BitInputBase.SetDefaultValue() contract. In BitDatePickerTests, render BitDatePicker with both Value and DefaultValue set, then assert the component.Instance.Value remains the explicitly provided Value and is not overwritten by DefaultValue. Use the existing BitDatePickerShouldRespectDefaultValue test as the nearby reference point and keep the new case focused on the Value-wins scenario.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/BlazorUI/Bit.BlazorUI/Components/Inputs/TextField/BitTextField.razor.cs`:
- Line 419: `BitTextField` is seeding `DefaultValue` without applying the
existing `Trim` behavior, so the uncontrolled initial value can keep surrounding
whitespace. Update `SetDefaultValue()` (or the path that assigns the initial
value in `BitTextField.razor.cs`) to normalize the seeded value the same way the
parsed path does when `Trim` is true, preserving the previous visible behavior.
In
`@src/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/TagsInput/BitTagsInputTests.cs`:
- Around line 423-424: The test in BitTagsInputTests is asserting the
List<string> reference instead of the tag contents, so it fails if BitTagsInput
makes a valid defensive copy. Update the assertion on com.Instance.Value to
compare the sequence items (and keep the count check) so the test verifies the
emitted tags by value rather than object identity.
---
Outside diff comments:
In
`@src/BlazorUI/Bit.BlazorUI/Components/Inputs/CircularTimePicker/BitCircularTimePicker.razor.cs`:
- Around line 330-341: The initialization in BitCircularTimePicker.OnInitialized
seeds _hour and _minute from CurrentValue after calling SetDefaultValue, but
DefaultValue is not normalized to the component’s time-of-day representation.
Update SetDefaultValue and/or the OnInitialized path so DefaultValue is routed
through the same normalization used for user input before assigning
CurrentValue, then let _hour and _minute derive from that normalized value. Use
the BitCircularTimePicker component members SetDefaultValue, CurrentValue,
_hour, and _minute to keep the rendered time and stored value consistent.
In `@src/BlazorUI/Bit.BlazorUI/Components/Inputs/OtpInput/BitOtpInput.razor.cs`:
- Around line 166-179: The OnInitialized flow in BitOtpInput is assigning
DefaultValue directly through SetDefaultValue without applying the OTP
normalization used for user input. Update the initialization path so the default
value is first sanitized and truncated according to Length and OTP type rules,
then use the normalized slots to populate Value and the input state. Keep the
fix localized around SetDefaultValue, Value, and the initialization setup in
BitOtpInput so the public value matches the rendered boxes.
---
Nitpick comments:
In
`@src/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/DatePicker/BitDatePickerTests.cs`:
- Around line 1037-1049: Add an adjacent test for BitDatePicker that covers the
Value-over-DefaultValue behavior in the new BitInputBase.SetDefaultValue()
contract. In BitDatePickerTests, render BitDatePicker with both Value and
DefaultValue set, then assert the component.Instance.Value remains the
explicitly provided Value and is not overwritten by DefaultValue. Use the
existing BitDatePickerShouldRespectDefaultValue test as the nearby reference
point and keep the new case focused on the Value-wins scenario.
In
`@src/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/DateRangePicker/BitDateRangePickerTests.cs`:
- Around line 1170-1172: The test in BitDateRangePickerTests is over-coupled to
object identity by asserting the component’s Value is the exact same
BitDateRangePickerValue instance as defaultValue. Remove the instance-equality
assertion and keep the contract focused on the selected dates by relying on the
StartDate and EndDate checks already present in the test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e1b55e57-f5db-49cf-95d1-0be5ec2c2783
📒 Files selected for processing (36)
src/BlazorUI/Bit.BlazorUI.Extras/Components/PhoneInput/BitPhoneInput.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/BitInputBase.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/Calendar/BitCalendar.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/Checkbox/BitCheckbox.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/ChoiceGroup/BitChoiceGroup.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/CircularTimePicker/BitCircularTimePicker.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/DatePicker/BitDatePicker.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/DateRangePicker/BitDateRangePicker.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/Dropdown/BitDropdown.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/NumberField/BitNumberField.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/OtpInput/BitOtpInput.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/Rating/BitRating.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/SearchBox/BitSearchBox.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/TagsInput/BitTagsInput.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/TextField/BitTextField.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/TimePicker/BitTimePicker.razor.cssrc/BlazorUI/Bit.BlazorUI/Components/Inputs/Toggle/BitToggle.razor.cssrc/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Components/DemoPage.razor.cssrc/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Checkbox/BitCheckboxDemo.razor.cssrc/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/ChoiceGroup/BitChoiceGroupDemo.razor.cssrc/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Dropdown/BitDropdownDemo.razor.cssrc/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/NumberField/BitNumberFieldDemo.razor.cssrc/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Rating/BitRatingDemo.razor.cssrc/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/SearchBox/BitSearchBoxDemo.razor.cssrc/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/TextField/BitTextFieldDemo.razor.cssrc/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Toggle/BitToggleDemo.razor.cssrc/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/Calendar/BitCalendarTests.cssrc/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/Checkbox/BitCheckboxValidationTest.razorsrc/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/CircularTimePicker/BitCircularTimePickerTests.cssrc/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/DatePicker/BitDatePickerTests.cssrc/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/DateRangePicker/BitDateRangePickerTests.cssrc/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/OtpInput/BitOtpInputTests.cssrc/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/SearchBox/BitSearchBoxTests.cssrc/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/TagsInput/BitTagsInputTests.cssrc/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/TextField/BitTextFieldTests.cssrc/BlazorUI/Tests/Bit.BlazorUI.Tests/Components/Inputs/TimePicker/BitTimePickerTests.cs
💤 Files with no reviewable changes (10)
- src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Rating/BitRatingDemo.razor.cs
- src/BlazorUI/Bit.BlazorUI/Components/Inputs/Dropdown/BitDropdown.razor.cs
- src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Dropdown/BitDropdownDemo.razor.cs
- src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/NumberField/BitNumberFieldDemo.razor.cs
- src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Toggle/BitToggleDemo.razor.cs
- src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Checkbox/BitCheckboxDemo.razor.cs
- src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/ChoiceGroup/BitChoiceGroupDemo.razor.cs
- src/BlazorUI/Bit.BlazorUI/Components/Inputs/ChoiceGroup/BitChoiceGroup.razor.cs
- src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/SearchBox/BitSearchBoxDemo.razor.cs
- src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/TextField/BitTextFieldDemo.razor.cs
|
@coderabbitai re-review |
|
✅ Action performedReview finished.
|
|
@coderabbitai re-review |
|
✅ Action performedReview finished.
|
closes #8186
Summary by CodeRabbit
New Features
DefaultValuesupport across input controls (applies whenValueisn’t bound), with updated demo parameter wiring.Bug Fixes
Documentation
Tests