Skip to content

Commit

Permalink
Merge pull request #143 from jkcs/main
Browse files Browse the repository at this point in the history
feat: add autoFocus prop
  • Loading branch information
praveenn77 committed May 8, 2024
2 parents d43506f + 26b093a commit 1afb5ab
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/theme/SearchBar/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useCallback, useState } from "react";
import React, { useRef, useCallback, useState, useEffect } from "react";
import clsx from "clsx";
import { useHistory } from "@docusaurus/router";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
Expand Down Expand Up @@ -104,6 +104,13 @@ const Search = props => {
'Search ⌘+K' : 'Search Ctrl+K'
}

// auto focus search bar on page load
useEffect(() => {
if (props.autoFocus && indexReady) {
searchBarRef.current.focus();
}
}, [indexReady]);

return (
<div className="navbar__search" key="search-box">
<span
Expand Down

0 comments on commit 1afb5ab

Please sign in to comment.