Set focus on input

This commit is contained in:
Daniel Kluge
2021-12-16 01:15:43 +01:00
parent 2403816461
commit f7bdff1653
3 changed files with 22 additions and 8 deletions
+10 -2
View File
@@ -1,8 +1,16 @@
import { NextPage } from "next";
import { MutableRefObject } from "react";
import styles from "../../styles/REPL/REPLHistory.module.css";
const REPLHistory: NextPage<{history: string[]}> = ({history}) => {
return <div className={styles.container}>
interface REPLHistoryParams {
history: string[];
inputRef: MutableRefObject<HTMLInputElement|undefined>;
}
const REPLHistory: NextPage<REPLHistoryParams> = ({history, inputRef}) => {
const focusInput = () => {if (inputRef.current) inputRef.current.focus();};
return <div className={styles.container} onClick={focusInput}>
{ history.map((value, idx) => <div className={styles.line} key={idx}>{value === "" ? "\u00A0" : value}</div>) }
</div>;
};