Widen ref type, add back hotkey
This commit is contained in:
@@ -3,6 +3,7 @@ import {type TextInput, View} from 'react-native'
|
|||||||
import {useLingui} from '@lingui/react/macro'
|
import {useLingui} from '@lingui/react/macro'
|
||||||
|
|
||||||
import {HITSLOP_10} from '#/lib/constants'
|
import {HITSLOP_10} from '#/lib/constants'
|
||||||
|
import {mergeRefs} from '#/lib/merge-refs'
|
||||||
import {listenFocusSearch} from '#/state/events'
|
import {listenFocusSearch} from '#/state/events'
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {Button, ButtonIcon} from '#/components/Button'
|
import {Button, ButtonIcon} from '#/components/Button'
|
||||||
@@ -18,7 +19,7 @@ type Props = Omit<TextField.InputProps, 'label'> & {
|
|||||||
*/
|
*/
|
||||||
onClearText?: () => void
|
onClearText?: () => void
|
||||||
hotkey?: boolean
|
hotkey?: boolean
|
||||||
ref?: React.RefObject<TextInput | null>
|
ref?: React.Ref<TextInput>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SearchInput({
|
export function SearchInput({
|
||||||
@@ -33,21 +34,20 @@ export function SearchInput({
|
|||||||
const {t: l} = useLingui()
|
const {t: l} = useLingui()
|
||||||
const showClear = value && value.length > 0
|
const showClear = value && value.length > 0
|
||||||
const internalRef = useRef<TextInput>(null)
|
const internalRef = useRef<TextInput>(null)
|
||||||
const inputRef = ref ?? internalRef
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!hotkey) return
|
if (!hotkey) return
|
||||||
return listenFocusSearch(() => {
|
return listenFocusSearch(() => {
|
||||||
inputRef.current?.focus()
|
internalRef.current?.focus()
|
||||||
})
|
})
|
||||||
}, [hotkey, inputRef])
|
}, [hotkey])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[a.w_full, a.relative]}>
|
<View style={[a.w_full, a.relative]}>
|
||||||
<TextField.Root>
|
<TextField.Root>
|
||||||
<TextField.Icon icon={MagnifyingGlassIcon} />
|
<TextField.Icon icon={MagnifyingGlassIcon} />
|
||||||
<TextField.Input
|
<TextField.Input
|
||||||
inputRef={inputRef}
|
inputRef={mergeRefs([internalRef, ref])}
|
||||||
label={label || l`Search`}
|
label={label || l`Search`}
|
||||||
value={value}
|
value={value}
|
||||||
placeholder={l`Search`}
|
placeholder={l`Search`}
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ export function DesktopSearch() {
|
|||||||
return (
|
return (
|
||||||
<View collapsable={false} ref={sift.refs.setAnchor}>
|
<View collapsable={false} ref={sift.refs.setAnchor}>
|
||||||
<SearchInput
|
<SearchInput
|
||||||
|
hotkey
|
||||||
value={query}
|
value={query}
|
||||||
onFocus={onFocus}
|
onFocus={onFocus}
|
||||||
onChangeText={onChangeText}
|
onChangeText={onChangeText}
|
||||||
|
|||||||
Reference in New Issue
Block a user