Skip to content

Commit 4cc50e2

Browse files
authored
fix: close hintUl on unfocus (#1837)
* fix: close hintUl on unfocus * fix: prettier code style errors
1 parent 96e2503 commit 4cc50e2

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/components/marked/mini-graphiQL.tsx

+20-12
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class QueryEditor extends Component {
166166
},
167167
hintOptions: {
168168
schema: this.props.schema,
169-
closeOnUnfocus: false,
169+
closeOnUnfocus: true,
170170
completeSingle: false,
171171
},
172172
extraKeys: {
@@ -529,18 +529,26 @@ function onHasCompletion(cm, data, onHintInformationRender) {
529529
// removed from our wrapper and in turn remove the wrapper from the
530530
// original container.
531531
let onRemoveFn
532-
wrapper.addEventListener(
533-
"DOMNodeRemoved",
534-
(onRemoveFn = event => {
535-
if (event.target === hintsUl) {
536-
wrapper.removeEventListener("DOMNodeRemoved", onRemoveFn)
537-
wrapper.parentNode.removeChild(wrapper)
538-
wrapper = null
539-
information = null
540-
onRemoveFn = null
532+
const observer = new MutationObserver(mutationsList => {
533+
for (const mutation of mutationsList) {
534+
// Check if the hintsUl element was removed
535+
if (mutation.removedNodes) {
536+
mutation.removedNodes.forEach(node => {
537+
if (node === hintsUl) {
538+
// Cleanup logic
539+
observer.disconnect() // Stop observing
540+
wrapper.parentNode.removeChild(wrapper)
541+
wrapper = null
542+
information = null
543+
onRemoveFn = null
544+
}
545+
})
541546
}
542-
}),
543-
)
547+
}
548+
})
549+
550+
// Start observing the wrapper for child node removals
551+
observer.observe(wrapper, { childList: true, subtree: false })
544552
}
545553

546554
// Now that the UI has been set up, add info to information.

0 commit comments

Comments
 (0)