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
+8 -3
View File
@@ -1,9 +1,14 @@
import type { NextPage } from "next";
import React from "react";
import React, { MutableRefObject } from "react";
import { commandCompletion, executeCommand } from "../../lib/commands";
import styles from "../../styles/REPL/REPLInput.module.css";
const REPLInput: NextPage<{historyCallback: CallableFunction}> = ({historyCallback}) => {
interface REPLInputParams {
historyCallback: CallableFunction;
inputRef: MutableRefObject<HTMLInputElement|undefined>;
}
const REPLInput: NextPage<REPLInputParams> = ({historyCallback, inputRef}) => {
const typed = React.createRef<HTMLSpanElement>();
const completion = React.createRef<HTMLSpanElement>();
const [currentCmd, setCurrentCmd] = React.useState<string[]>([]);
@@ -41,7 +46,7 @@ const REPLInput: NextPage<{historyCallback: CallableFunction}> = ({historyCallba
return <div className={styles.wrapperwrapper}>
<span className={styles.inputstart}>$&nbsp;</span>
<div className={styles.wrapper}>
<input className={styles.in} type={"text"} onChange={replinOnChange} onKeyDown={tabComplete} spellCheck={"false"} autoFocus />
<input ref={inputRef as MutableRefObject<HTMLInputElement>} className={styles.in} type={"text"} onChange={replinOnChange} onKeyDown={tabComplete} spellCheck={"false"} autoFocus />
<span className={styles.completionWrapper}><span ref={typed} className={styles.typed}></span><span ref={completion} className={styles.completion}></span></span>
</div>
</div>;