Skip to content

Commit

Permalink
fix search dropdown click (#3364)
Browse files Browse the repository at this point in the history
* fix handling onBlur by using ref instead of state
  • Loading branch information
acao authored Jul 24, 2023
1 parent 4cbdf18 commit d67c13f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/lemon-snakes-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'graphiql': patch
'@graphiql/react': patch
---

Fix search result bug on select, #33307
8 changes: 4 additions & 4 deletions packages/graphiql-react/src/explorer/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ export function Search() {
},
[push],
);
const [isFocused, setIsFocused] = useState(false);
const isFocused = useRef(false);
const handleFocus: FocusEventHandler = useCallback(e => {
setIsFocused(e.type === 'focus');
isFocused.current = e.type === 'focus';
}, []);

const shouldSearchBoxAppear =
Expand Down Expand Up @@ -110,8 +110,8 @@ export function Search() {
/>
</div>

{/* hide on blur */}
{isFocused && (
{/* display on focus */}
{isFocused.current && (
<Combobox.Options data-cy="doc-explorer-list">
{results.within.length +
results.types.length +
Expand Down
2 changes: 2 additions & 0 deletions packages/graphiql/cypress/e2e/docs.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ describe('GraphiQL DocExplorer - search', () => {
});

it('Closes popover when blurring input', () => {
cy.dataCy('doc-explorer-input').focus();
cy.dataCy('doc-explorer-input').type('list');
cy.dataCy('doc-explorer-input').blur();
cy.dataCy('doc-explorer-list').should('not.exist');
});
Expand Down

0 comments on commit d67c13f

Please sign in to comment.