mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-06 13:30:41 +02:00
fix: overwrites left and right arrow key behaviour in NumberComponent
The cursor position was not stored when moving the cursor without changing the number.
This commit is contained in:
parent
d6bad37233
commit
2b520834dc
@ -199,16 +199,8 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
|||||||
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
const { key, target } = event;
|
const { key, target } = event;
|
||||||
|
|
||||||
// Typecast
|
|
||||||
const inputTarget = target as HTMLInputElement;
|
const inputTarget = target as HTMLInputElement;
|
||||||
if (
|
if (key === "F1" || key === "F5" || key === "F12" || key === "Tab") {
|
||||||
key === "F1" ||
|
|
||||||
key === "F5" ||
|
|
||||||
key === "F12" ||
|
|
||||||
key === "Tab" ||
|
|
||||||
key === "ArrowRight" ||
|
|
||||||
key === "ArrowLeft"
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -223,6 +215,11 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
|
|||||||
// Select everything when pressing Ctrl + a
|
// Select everything when pressing Ctrl + a
|
||||||
inputTarget.setSelectionRange(0, value.length);
|
inputTarget.setSelectionRange(0, value.length);
|
||||||
return;
|
return;
|
||||||
|
} else if (key === "ArrowRight" || key === "ArrowLeft") {
|
||||||
|
// Move the cursor with the arrow keys and store its position
|
||||||
|
selectionStart = key === "ArrowRight" ? selectionStart + 1 : selectionStart - 1;
|
||||||
|
setCursorPosition(selectionStart);
|
||||||
|
return;
|
||||||
} else if ((key >= "0" && key <= "9") || key === "-") {
|
} else if ((key >= "0" && key <= "9") || key === "-") {
|
||||||
// Check if a number key or a decimal point key is pressed
|
// Check if a number key or a decimal point key is pressed
|
||||||
({ value: newValue, selectionStart } = handleNumericKey(
|
({ value: newValue, selectionStart } = handleNumericKey(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user