Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: close hintUl on unfocus #1837

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions src/components/marked/mini-graphiQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class QueryEditor extends Component {
},
hintOptions: {
schema: this.props.schema,
closeOnUnfocus: false,
closeOnUnfocus: true,
completeSingle: false,
},
extraKeys: {
Expand Down Expand Up @@ -529,18 +529,26 @@ function onHasCompletion(cm, data, onHintInformationRender) {
// removed from our wrapper and in turn remove the wrapper from the
// original container.
let onRemoveFn
wrapper.addEventListener(
"DOMNodeRemoved",
(onRemoveFn = event => {
if (event.target === hintsUl) {
wrapper.removeEventListener("DOMNodeRemoved", onRemoveFn)
wrapper.parentNode.removeChild(wrapper)
wrapper = null
information = null
onRemoveFn = null
const observer = new MutationObserver(mutationsList => {
for (const mutation of mutationsList) {
// Check if the hintsUl element was removed
if (mutation.removedNodes) {
mutation.removedNodes.forEach(node => {
if (node === hintsUl) {
// Cleanup logic
observer.disconnect() // Stop observing
wrapper.parentNode.removeChild(wrapper)
wrapper = null
information = null
onRemoveFn = null
}
})
}
}),
)
}
})

// Start observing the wrapper for child node removals
observer.observe(wrapper, { childList: true, subtree: false })
}

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