diff --git a/src/components/SearchModal/SearchModal.tsx b/src/components/SearchModal/SearchModal.tsx index 6374efd6..b653bf3d 100644 --- a/src/components/SearchModal/SearchModal.tsx +++ b/src/components/SearchModal/SearchModal.tsx @@ -1,5 +1,5 @@ import React from 'react' -import Portal from '~utils/Portal' +import { createPortal } from 'react-dom' import api from '~utils/api' import Modal from '~components/Modal/Modal' @@ -24,7 +24,7 @@ interface State { } class SearchModal extends React.Component { - searchQuery + searchInput: React.RefObject constructor(props: Props) { super(props) @@ -35,6 +35,13 @@ class SearchModal extends React.Component { message: '', totalResults: 0 } + this.searchInput = React.createRef() + } + + componentDidMount() { + if (this.searchInput.current) { + this.searchInput.current.focus() + } } fetchResults = (query: string) => { @@ -89,28 +96,32 @@ class SearchModal extends React.Component { const { query, loading } = this.state return ( - - -
- -
+ createPortal( +
+ +
+ +
- { this.renderSearchResults() } - -
- - + { this.renderSearchResults() } + + + +
, + document.body + ) ) } }