mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
remove handleKeyDown for NumberField (#166)
handleKeyDown was a method that filtered out specific keypresses if they weren't specific keycodes. This did not play well with all keyboards which made it impossible to enter port numbers. furthermore, handleInputChange should already filter out non-numeric characters, so the filtering still works properly with this removal.
This commit is contained in:
parent
112fda912f
commit
40af311e5b
@ -508,34 +508,10 @@ class NumberField extends TextField {
|
||||
}
|
||||
}
|
||||
|
||||
@boundMethod
|
||||
handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {
|
||||
// Allow backspace, delete, tab, escape, and enter
|
||||
if (
|
||||
[46, 8, 9, 27, 13].includes(event.keyCode) ||
|
||||
// Allow: Ctrl+A, Ctrl+C, Ctrl+X
|
||||
((event.keyCode === 65 || event.keyCode === 67 || event.keyCode === 88) && event.ctrlKey === true) ||
|
||||
// Allow: home, end, left, right
|
||||
(event.keyCode >= 35 && event.keyCode <= 39)
|
||||
) {
|
||||
return; // let it happen, don't do anything
|
||||
}
|
||||
// Ensure that it is a number and stop the keypress
|
||||
if (
|
||||
(event.shiftKey || event.keyCode < 48 || event.keyCode > 57) &&
|
||||
(event.keyCode < 96 || event.keyCode > 105)
|
||||
) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
// Use the render method from TextField but add the onKeyDown handler
|
||||
const renderedTextField = super.render();
|
||||
|
||||
return React.cloneElement(renderedTextField, {
|
||||
onKeyDown: this.handleKeyDown,
|
||||
});
|
||||
return React.cloneElement(renderedTextField);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user