Skip to content
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

fix: Cursor jumps in NumberComponent when number is updated in the backend and frontend rerenders #201

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions frontend/src/components/NumberComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,8 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
const { key, target } = event;

// Typecast
const inputTarget = target as HTMLInputElement;
if (
key === "F1" ||
key === "F5" ||
key === "F12" ||
key === "Tab" ||
key === "ArrowRight" ||
key === "ArrowLeft"
) {
if (key === "F1" || key === "F5" || key === "F12" || key === "Tab") {
return;
}
event.preventDefault();
Expand All @@ -223,6 +215,11 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
// Select everything when pressing Ctrl + a
inputTarget.setSelectionRange(0, value.length);
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 === "-") {
// Check if a number key or a decimal point key is pressed
({ value: newValue, selectionStart } = handleNumericKey(
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/pydase/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site displaying a pydase UI." />
<script type="module" crossorigin src="/assets/index-BqF7l_R8.js"></script>
<script type="module" crossorigin src="/assets/index-B4RiTBEo.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-D2aktF3W.css">
</head>

Expand Down
Loading