-
-
Notifications
You must be signed in to change notification settings - Fork 332
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
Number component #1155
Number component #1155
Conversation
- Prettier handles these, so we don't need them - I want to use some test case array blocks in my tests that break these rules
Define the low-level functions that we need to implement to create generalized input formatters.
Codecov Report
@@ Coverage Diff @@
## master #1155 +/- ##
=======================================
Coverage 93.39% 93.39%
=======================================
Files 113 113
Lines 4332 4332
=======================================
Hits 4046 4046
Misses 286 286
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
mathesar_ui/src/component-library/number-input/number-formatter/NumberFormatter.ts
Outdated
Show resolved
Hide resolved
- Handle high precision floats with StringifiedNumberFormatter. - Handle regular numbers with NumberFormatter. - Use AbstractNumberFormatter and makeUniversalNumberParser for shared logic.
Testing Library recommends this when dealing with user interactions. I'm installing the beta version because their [docs][1] say: > This is still a pre-release and might be subject to breaking changes if they should be deemed necessary in the light of feedback we receive for this version. All planned breaking changes are already implemented though. [1]: https://testing-library.com/docs/user-event/intro/
Safari doesn't support them
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.
@seancolsen Looks good to me! Nice work!
@seancolsen I assume you'll create tickets mentioned in the description. I'm going to mark #970 as closed. |
Thanks for the reminder. Here are the tickets: |
Summary
This PR alters the behavior or our
NumberInput
component, making it much more robust.Example changes in behavior to
NumberInput
e009..e
"e009..e"
(string)9
(number)e009..e
e009..e
9.
1234
1234
1,234
Within Mathesar,
NumberInput
is currently used only for the form that configures the DB settings on a text field. But we eventually want to it for editing cells, and potentially other places too.Additional context
Demo
Review tips
NumberInput
story. In particular, try fiddling withallowFloat
,allowNegative
andlocale
to see how the behavior of the input changes.Requirements from #970
-0.1
7..
8e9
Additional work completed
Make a generalized
FormattedInput
component that can be composed to build other kinds of specialized inputs.Allow input of numbers in other locales.
Use
NumberInput
fornumber
numbers andStringifiedNumberInput
for high precision numbers (stored asstring
).Disallow user input into
NumberInput
that will result in loss of precision.You cay try this out by pressing
9
repeatedly on the input. You'll notice it stops accepting input after fifteen digits. In any situation where we're usingNumberInput
, hitting the precision limit should be a very unlikely scenario. That said, an alternate behavior (that might be nice to add at some point) would be to round the input value to the nearest storable value (instead of preventing input). This would mean you could keep typing9
and when you get to sixteen digits, the value of the input would change to10000000000000000
. I could open a ticket for this, but I don't really think it's worth it. If someone needs this later we could address it. It wouldn't be too hard to add a prop onNumberInput
to configure this behavior.Set
allowFloat
andallowNegative
to false by default. (I figure better to be strict by default. We can discuss if necessary.)To handle later via tickets
Here are the templates to create the tickets
Support scientific notation
cat | gh issue create -F - -t 'Add support for scientific notation in number input components' -m '[Beta] Better Editing Experience' -l "status: ready" -l "type: enhancement" -l "work: frontend"
Retain cursor position
cat | gh issue create -F - -t 'Retain cursor position when changing text within FormattedInput' -m '[Beta] Better Editing Experience' -l "status: ready" -l "type: bug" -l "work: frontend"
Research possibility of setting inputmode when negative
cat | gh issue create -F - -t 'For numeric inputs, research the possibility of setting the inputmode attribute when allowing negative numbers' -m '[Beta] Better Editing Experience' -l "status: ready" -l "type: enhancement" -l "work: frontend"
Checklist
Update index.md
).master
branch of the repositoryDeveloper Certificate of Origin
Developer Certificate of Origin