diff --git a/web/components/feed-create.tsx b/web/components/feed-create.tsx index 88c3a211..2a2d291c 100644 --- a/web/components/feed-create.tsx +++ b/web/components/feed-create.tsx @@ -1,5 +1,6 @@ +import { SparklesIcon, XIcon } from '@heroicons/react/solid' import { Avatar } from './avatar' -import { useEffect, useRef, useState } from 'react' +import { useRef, useState } from 'react' import { Spacer } from './layout/spacer' import { NewContract } from '../pages/create' import { firebaseLogin, User } from '../lib/firebase/users' @@ -7,7 +8,6 @@ import { ContractsGrid } from './contracts-list' import { Contract } from '../../common/contract' import { Col } from './layout/col' import clsx from 'clsx' -import { SparklesIcon } from '@heroicons/react/solid' import { Row } from './layout/row' export function FeedPromo(props: { hotContracts: Contract[] }) { @@ -69,7 +69,8 @@ export default function FeedCreate(props: { }) { const { user, tag, className } = props const [question, setQuestion] = useState('') - const [focused, setFocused] = useState(false) + const [isExpanded, setIsExpanded] = useState(false) + const inputRef = useRef() const placeholders = [ 'Will anyone I know get engaged this year?', @@ -86,60 +87,60 @@ export default function FeedCreate(props: { ) const placeholder = props.placeholder ?? `e.g. ${placeholders[randIndex]}` - const panelRef = useRef() - const inputRef = useRef() - - useEffect(() => { - const onClick = () => { - if ( - panelRef.current && - document.activeElement && - !panelRef.current.contains(document.activeElement) - ) - setFocused(false) - } - window.addEventListener('click', onClick) - return () => window.removeEventListener('click', onClick) - }) - return (
!focused && !question && inputRef.current?.focus()} - ref={(elem) => (panelRef.current = elem)} + onClick={() => { + !isExpanded && inputRef.current?.focus() + }} >
- {/* TODO: Show focus, for accessibility */} -
+

Ask a question...

-
+ {isExpanded && ( + + )} +