Skip to content

Commit

Permalink
fix handling onBlur by using ref instead of state
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Jul 24, 2023
1 parent d5c4cd2 commit 58e657a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions packages/graphiql-react/src/explorer/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@ export function Search() {
},
[push],
);
const [isFocused, setIsFocused] = useState(false);
const handleFocus: FocusEventHandler = useCallback(
e => {
setIsFocused(e.type === 'focus');
},
[setIsFocused],
);
const isFocused = useRef(false);
const handleFocus: FocusEventHandler = useCallback(e => {
isFocused.current = e.type === 'focus';
}, []);

const shouldSearchBoxAppear =
explorerNavStack.length === 1 ||
Expand Down Expand Up @@ -105,7 +102,7 @@ export function Search() {
autoComplete="off"
onFocus={handleFocus}
// TODO: find a better way to handle onBlur
// onBlur={handleFocus}
onBlur={handleFocus}
onChange={event => setSearchValue(event.target.value)}
placeholder="⌘ K"
ref={inputRef}
Expand All @@ -115,7 +112,7 @@ export function Search() {
</div>

{/* display on focus */}
{isFocused && (
{isFocused.current && (
<Combobox.Options data-cy="doc-explorer-list">
{results.within.length +
results.types.length +
Expand Down

0 comments on commit 58e657a

Please sign in to comment.