diff --git a/frontend/src/AddSeries/AddNewSeries/AddNewSeries.tsx b/frontend/src/AddSeries/AddNewSeries/AddNewSeries.tsx index ef53bbb2e..581023798 100644 --- a/frontend/src/AddSeries/AddNewSeries/AddNewSeries.tsx +++ b/frontend/src/AddSeries/AddNewSeries/AddNewSeries.tsx @@ -1,6 +1,6 @@ import React, { useCallback, useEffect, useRef, useState } from 'react'; import Alert from 'Components/Alert'; -import TextInput, { TextInputHandle } from 'Components/Form/TextInput'; +import TextInput from 'Components/Form/TextInput'; import Icon from 'Components/Icon'; import Button from 'Components/Link/Button'; import Link from 'Components/Link/Link'; @@ -22,7 +22,7 @@ function AddNewSeries() { const { term: initialTerm = '' } = useQueryParams<{ term: string }>(); const hasSeries = useHasSeries(); const [term, setTerm] = useState(initialTerm); - const searchInputRef = useRef(null); + const searchInputRef = useRef(null); const [isFetching, setIsFetching] = useState(false); const query = useDebounce(term, term ? 300 : 0); diff --git a/frontend/src/Components/Form/TextInput.tsx b/frontend/src/Components/Form/TextInput.tsx index 4e220cc89..435cdb80c 100644 --- a/frontend/src/Components/Form/TextInput.tsx +++ b/frontend/src/Components/Form/TextInput.tsx @@ -6,7 +6,6 @@ import React, { SyntheticEvent, useCallback, useEffect, - useImperativeHandle, useRef, } from 'react'; import { FileInputChanged, InputChanged } from 'typings/inputs'; @@ -41,11 +40,7 @@ export interface FileInputProps extends CommonTextInputProps { onChange: (change: FileInputChanged) => void; } -export interface TextInputHandle { - focus: () => void; -} - -const TextInput = forwardRef( +const TextInput = forwardRef( ( { className = styles.input, @@ -71,12 +66,18 @@ const TextInput = forwardRef( ) => { const inputRef = useRef(null); - useImperativeHandle( - ref, - () => ({ - focus: () => inputRef.current?.focus(), - }), - [] + const setRef = useCallback( + (node: HTMLInputElement | null) => { + (inputRef as React.MutableRefObject).current = + node; + if (typeof ref === 'function') { + ref(node); + } else if (ref) { + (ref as React.MutableRefObject).current = + node; + } + }, + [ref] ); const selectionTimeout = useRef>(); @@ -171,7 +172,7 @@ const TextInput = forwardRef( return (