-
Notifications
You must be signed in to change notification settings - Fork 30
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
Explain Firefox how numeric input should work #1600
Conversation
e4b734c
to
9e49bd3
Compare
In this video I'm trying to clear the field by hitting backspace but it doesn't clear the last 4 digits in the field Screencast.from.04-03-2024.10.04.52.AM.webm |
I'm trying to select the field and overwrite it with a single number but it doesn't let me Screencast.from.04-03-2024.10.06.28.AM.webm |
The case for the first behavior is the minimum allowed value for that librdkafka option |
I need to update this behavior to enable starting to write a new number even though it doesn't fit in the allowed range in the beginning |
Validation should be done at the end, not on every keystroke. |
I can't set it e.g., 1001 since it doesn't allow me to change the first digits inthe sequence |
It also feels more sluggish to me when I try this in the browser. How about we do the following: let users enter any values, including non-digit characters but highlight the form red when it's invalid and display what the error is similar to how the other form elements do it (e.g., table input or forms for connectors)? |
CHANGELOG.md
Outdated
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
### Fixed | |||
|
|||
- WebConsole: State shows InQueue when program is empty (#1443) | |||
- WebConsole: Fix behavior of numeric inputs in some browsers, including Firefox |
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.
- WebConsole: Fix behavior of numeric inputs in some browsers, including Firefox | |
- WebConsole: Fix behavior of numeric inputs in Firefox |
import { TextField, TextFieldProps } from '@mui/material' | ||
|
||
export const handleNumericKeyDown: KeyboardEventHandler<Element> = event => { | ||
if (/Key[ACVXYZ]/.test(event.code) && event.ctrlKey) { |
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.
what does this do why ACVXYZ
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.
maybe add a comment
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.
Will add a comment. Shortcuts like Ctrl + C, Ctrl + V etc.
return number | ||
} | ||
|
||
export const numberInputProps = ( |
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.
what does this function do? comment?
component={NumberInput as any} | ||
{...(([, min, max]) => { | ||
return { min: parseInt(min), max: parseInt(max) } | ||
})(fieldOptions[field].range.match(/(\d+) .. (\d+)/) ?? [])} |
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.
..
why are there two spaces?
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.
This is an implementation detail related to file librdkafkaOptions.ts
, I will move it to encapsulate it there, rather than expose at usage-time
...(({ min, max }) => ({ min: min.toNumber(), max: max.toNumber() }))(numericRange(columnType)), | ||
value: props.value === null ? '' : props.value, // Enable clearing of the input when setting value to null | ||
value: props.value as null | number, |
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.
I don't understand what this expression does? A cast and then bitwise or?
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.
A type cast (doesn't affect the runtime value) to a type "number or null"
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.
then you should write (null | number)
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.
Is there an Option type? That would be much better.
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.
Not a native one. A user-space wrapper class could be used, but the native null
works just as well - the typing is strong everywhere, so null-ability is explicit and can not be ignored
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.
The check for unguarded access to values that can be null
and undefined
is also enforced by typescript compiler, not just editor type highlight
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.
as (null | number)
gets reduced by the formatter to as null | number
b967b71
to
cb2c3ef
Compare
Thanks, looks like behavior works as intended now. I fear there is still some confusing behavior for a user:
Screencast.from.04-03-2024.04.39.47.PM.webm
|
01ed2f8
to
233003c
Compare
There is some odd behavior, the first time a form is filled out the min/max range is not displayed but the text cell becomes red, after I submit the form the ranges are displayed Screencast.from.04-05-2024.09.40.08.AM.webm |
Given how many pitfalls there were with this PR: lets add test-cases for these cases before we merge (I don't see any currently). We should get into the habit to have tests for it otherwise long term stability and evolution of it will suffer. |
b2b414e
to
ff2c691
Compare
Updated the PR. In some cases quickly typing up numbers gets laggy - that is due to implementation that depends on attempting to parse the input as a number on each keystroke. This is a tradeoff for a simpler and more robust implementation and can be optimized later if needed. |
ff2c691
to
c620e98
Compare
Signed-off-by: George <bulakh.96@gmail.com>
Add comments to implementation of NumberInput Signed-off-by: George <bulakh.96@gmail.com>
Add invalid range as a condition for a form failure Add error message when a number in a form is out of range Signed-off-by: George <bulakh.96@gmail.com>
Signed-off-by: George <bulakh.96@gmail.com>
Signed-off-by: George <bulakh.96@gmail.com>
Signed-off-by: George <bulakh.96@gmail.com>
Signed-off-by: George <bulakh.96@gmail.com>
55024c5
to
228eff0
Compare
Is this a user-visible change (yes/no): yes
Fix #1522 : WebConsole: numeric inputs allow arbitrary text input in Firefox
Fix #1748 : WebConsole: Invariant failed setting non nullable value to null