diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8ba2b51..63a106f 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -133,23 +133,12 @@ const App = () => { /> ); - } else if (value.type === 'int') { - return ( -
- -
- ); - } else if (value.type === 'float') { + } else if (value.type === 'float' || value.type === 'int') { return (
{ - // Check if a number key or a decimal point key is pressed - if (key === '.' && value.includes('.')) { - // Check if value already contains a decimal. If so, ignore input. - // eslint-disable-next-line no-console - console.warn('Number already contains decimal! Ignoring...'); - return { value, selectionStart }; - } - // Add the new key at the cursor's position - const newValue = value.slice(0, selectionStart) + key + value.slice(selectionStart); - return { value: newValue, selectionStart: selectionStart + 1 }; -}; - // TODO: highlight the digit that is being changed by setting both selectionStart and // selectionEnd const handleArrowKey = ( @@ -116,7 +97,7 @@ const handleDeleteKey = ( return { value, selectionStart }; }; -export const NumberComponent = React.memo((props: ButtonComponentProps) => { +export const NumberComponent = React.memo((props: NumberComponentProps) => { const renderCount = useRef(0); // Create a state for the cursor position const [cursorPosition, setCursorPosition] = useState(null); @@ -139,6 +120,18 @@ export const NumberComponent = React.memo((props: ButtonComponentProps) => { const { name, parent_path, value, readOnly, docString } = props; + const handleNumericKey = (key: string, value: string, selectionStart: number) => { + // Check if a number key or a decimal point key is pressed + if (key === '.' && (value.includes('.') || props.type === 'int')) { + // Check if value already contains a decimal. If so, ignore input. + // eslint-disable-next-line no-console + console.warn('Invalid input! Ignoring...'); + return { value, selectionStart }; + } + // Add the new key at the cursor's position + const newValue = value.slice(0, selectionStart) + key + value.slice(selectionStart); + return { value: newValue, selectionStart: selectionStart + 1 }; + }; const handleKeyDown = (event) => { const { key, target } = event; if (key === 'F5' || key === 'ArrowRight' || key === 'ArrowLeft') {