Skip to content

Commit d67c13f

Browse files
authored
fix search dropdown click (#3364)
* fix handling onBlur by using ref instead of state
1 parent 4cbdf18 commit d67c13f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

.changeset/lemon-snakes-exist.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'graphiql': patch
3+
'@graphiql/react': patch
4+
---
5+
6+
Fix search result bug on select, #33307

packages/graphiql-react/src/explorer/components/search.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ export function Search() {
6969
},
7070
[push],
7171
);
72-
const [isFocused, setIsFocused] = useState(false);
72+
const isFocused = useRef(false);
7373
const handleFocus: FocusEventHandler = useCallback(e => {
74-
setIsFocused(e.type === 'focus');
74+
isFocused.current = e.type === 'focus';
7575
}, []);
7676

7777
const shouldSearchBoxAppear =
@@ -110,8 +110,8 @@ export function Search() {
110110
/>
111111
</div>
112112

113-
{/* hide on blur */}
114-
{isFocused && (
113+
{/* display on focus */}
114+
{isFocused.current && (
115115
<Combobox.Options data-cy="doc-explorer-list">
116116
{results.within.length +
117117
results.types.length +

packages/graphiql/cypress/e2e/docs.cy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ describe('GraphiQL DocExplorer - search', () => {
4646
});
4747

4848
it('Closes popover when blurring input', () => {
49+
cy.dataCy('doc-explorer-input').focus();
50+
cy.dataCy('doc-explorer-input').type('list');
4951
cy.dataCy('doc-explorer-input').blur();
5052
cy.dataCy('doc-explorer-list').should('not.exist');
5153
});

0 commit comments

Comments
 (0)