feat(UI): ensure that input autofocus works

pull/5926/head
Pavel Zavora 2022-06-07 10:09:43 +02:00
parent 7204e82c2f
commit ee7e555353
1 changed files with 10 additions and 2 deletions

View File

@ -54,6 +54,7 @@ class Input extends Component<Props> {
} }
private inputRef: RefObject<HTMLInputElement> private inputRef: RefObject<HTMLInputElement>
private timeoutHandle: ReturnType<typeof setTimeout> | undefined
constructor(props: Props) { constructor(props: Props) {
super(props) super(props)
@ -62,10 +63,17 @@ class Input extends Component<Props> {
public componentDidMount() { public componentDidMount() {
if (this.props.autoFocus) { if (this.props.autoFocus) {
setTimeout(() => this.inputRef.current.focus(), 10) this.timeoutHandle = setTimeout(() => {
this.inputRef.current.focus()
this.timeoutHandle = undefined
}, 50)
}
}
public componentWillUnmount() {
if (this.timeoutHandle) {
clearTimeout(this.timeoutHandle)
} }
} }
public render() { public render() {
const { const {
status, status,