Skip to content

Commit

Permalink
fix(portal): Replace AbortController with removeEventListener to supp…
Browse files Browse the repository at this point in the history
…ort older browsers
  • Loading branch information
Dominik Dosoudil committed Nov 13, 2024
1 parent d13670b commit d912d6a
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/addons/Portal/Portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,23 @@ function Portal(props) {
if (!hideOnScroll) {
return
}
const abortController = new AbortController()

window.addEventListener(
'scroll',
(e) => {
debug('handleHideOnScroll()')
const handleScroll = (e) => {
debug('handleHideOnScroll()')

// Do not hide the popup when scroll comes from inside the popup
// https://github.com/Semantic-Org/Semantic-UI-React/issues/4305
if (_.isElement(e.target) && contentRef.current.contains(e.target)) {
return
}
// Do not hide the popup when scroll comes from inside the popup
// https://github.com/Semantic-Org/Semantic-UI-React/issues/4305
if (_.isElement(e.target) && contentRef.current.contains(e.target)) {
return
}

closePortal(e)
},
{ signal: abortController.signal, passive: true },
)
closePortal(e)
}

window.addEventListener('scroll', handleScroll, { passive: true })

return () => {
abortController.abort()
window.removeEventListener('scroll', handleScroll)
}
}, [closePortal, hideOnScroll])

Expand Down

0 comments on commit d912d6a

Please sign in to comment.