-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
MudTextField: Check if user is trying to enter negative number #11074
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
base: dev
Are you sure you want to change the base?
MudTextField: Check if user is trying to enter negative number #11074
Conversation
Check if user is trying to enter negative number. If they are, modify the text so that it allows them to do so.
I am unsure whether this is the best way to go about fixing this. I posted some more information in a comment in #11055 |
This is a change in MudTextField.razor.cs that gives the desired effect. I have not yet implemented this for MudNumericField. Does this look better? @vernou |
Would probably have to check for more types of Value, or maybe it would be possible to check if Value is |
@Lewis-Pitman, don't hesitate to commit and push. It's more pleasant to review instead of image. Consider to check |
Allow the user to type negative numbers correctly if bound to a numeric type
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #11074 +/- ##
==========================================
- Coverage 91.05% 90.98% -0.08%
==========================================
Files 429 431 +2
Lines 13965 14062 +97
Branches 2698 2732 +34
==========================================
+ Hits 12716 12794 +78
- Misses 646 651 +5
- Partials 603 617 +14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This code makes MudTextField work as expected. Checking if the value was INumber did not work. Happy to implement tests if this method is accepted. As for MudNumericField, I have been debugging the issue for hours with no luck. I think modifying MudBaseInput may be necessary to get it to work. Using SetTextAsync on MudNumericField doesn't change anything. I even tried intercepting the - key inside HandleKeyDownAsync but had no luck getting the desired outcome. I am unsure what to do here |
Seems like there is a seperate issue #11035 for MudNumericField specifically. Since the solution seems to be a bit more complex, it might be better for me to leave it for now and someone else can try this? |
Also just noticed that I'll need to add nullable types too like int? And float? For example |
|
- MudTextField allows a negative number to be entered on the first attempt when bound to a numeric type - Added test to check this works - Reverted MudBaseInput changes
.Add(p => p.Immediate, true) | ||
.Add(p => p.Value, 5)); | ||
|
||
comp.Find("input").Input("0-"); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
comp.Find("input").Input("0-"); | ||
|
||
comp.Instance.Text.Should().Be("-"); | ||
comp.Instance.Text.Should().NotBe("0"); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Reverted MudBaseInput to what it was before. This was not properly reverted before, causing a test to run infinitely Improved the test by checking if entering nothing changes the value of 5 to 0.
I realised that I hadn't reverted MudBaseInput properly after the initial changes I made to it, which caused one of the checks to fail. I have now properly reverted the code to how it was before and this has been fixed. As for the test, entering "" causes |
It's important to check |
.Add(p => p.Value, 5)); | ||
|
||
comp.Find("input").Input(""); | ||
comp.Find("input").Blur(); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Remove blur from test
comp.Find("input").Input("5"); | ||
comp.Find("input").Input("0-"); | ||
comp.Instance.Text.Should().Be("-"); | ||
comp.Instance.Value.Should().Be(5); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Added test to check entering a negative number
|
Description
Check if user is trying to enter negative number. If they are, modify the text so that it allows them to do so.
This seems like a hacky fix. May need guidance on an alternative fix
For issue #11055
How Has This Been Tested?
Visually
Type of Changes
Before:
https://github.com/user-attachments/assets/be2f42db-a9c4-4f5d-93bd-d68fb7f18289
After:
https://github.com/user-attachments/assets/21621dd6-ba74-4e99-b4f8-c2b0056671c1
Checklist
dev
).