fix: component ids adhere to html guidelines now

This commit is contained in:
Mose Müller
2023-10-30 14:05:39 +01:00
parent 7e5861ec22
commit b149c1b411
12 changed files with 55 additions and 34 deletions

View File

@@ -3,6 +3,7 @@ import { Form, InputGroup } from 'react-bootstrap';
import { emit_update } from '../socket';
import { DocStringComponent } from './DocStringComponent';
import '../App.css';
import { getIdFromFullAccessPath } from '../utils/stringUtils';
// TODO: add button functionality
@@ -131,14 +132,14 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
const [cursorPosition, setCursorPosition] = useState(null);
// Create a state for the input string
const [inputString, setInputString] = useState(props.value.toString());
const fullAccessPath = parentPath.concat('.' + name);
const id = getIdFromFullAccessPath(fullAccessPath);
useEffect(() => {
renderCount.current++;
// Set the cursor position after the component re-renders
const inputElement = document.getElementsByName(
parentPath.concat('.' + name)
)[0] as HTMLInputElement;
const inputElement = document.getElementsByName(id)[0] as HTMLInputElement;
if (inputElement && cursorPosition !== null) {
inputElement.setSelectionRange(cursorPosition, cursorPosition);
}
@@ -275,7 +276,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
};
return (
<div className="numberComponent" id={parentPath.concat('.' + name)}>
<div className="numberComponent" id={id}>
{process.env.NODE_ENV === 'development' && showName && (
<p>Render count: {renderCount.current}</p>
)}
@@ -287,7 +288,7 @@ export const NumberComponent = React.memo((props: NumberComponentProps) => {
type="text"
value={inputString}
disabled={readOnly}
name={parentPath.concat('.' + name)}
name={fullAccessPath}
onKeyDown={handleKeyDown}
onBlur={handleBlur}
className={isInstantUpdate && !readOnly ? 'instantUpdate' : ''}