Skip to content

Commit e1007d1

Browse files
committed
Fix search focus on iOS
1 parent 98d8bc3 commit e1007d1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/components/search.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ export const Mobile = props => {
5151
const siteMetadata = useSiteMetadata()
5252
const {reset, results, isOpen: resultsOpen, getInputProps, getItemProps, getMenuProps, highlightedIndex} = props
5353

54+
// Fixes focus behavior on iOS where the input gets focus styles but not the
55+
// actual focus after animating open.
56+
const ref = React.useRef()
57+
React.useEffect(() => {
58+
if (open) {
59+
ref.current.focus()
60+
}
61+
}, [ref, open])
62+
5463
const handleDismiss = () => {
5564
reset()
5665
setOpen(false)
@@ -133,7 +142,7 @@ export const Mobile = props => {
133142
placeholder={`Search ${siteMetadata.title}`}
134143
aria-label={`Search ${siteMetadata.title}`}
135144
sx={{width: '100%'}}
136-
{...getInputProps()}
145+
{...getInputProps({ref})}
137146
/>
138147
</motion.div>
139148
<Box

0 commit comments

Comments
 (0)