Skip to content

Commit

Permalink
window scroll to behave same as document
Browse files Browse the repository at this point in the history
  • Loading branch information
snowystinger committed Oct 27, 2021
1 parent 6e8d812 commit c246bed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/@react-aria/overlays/src/useCloseOnScroll.ts
Expand Up @@ -37,7 +37,8 @@ export function useCloseOnScroll(opts: CloseOnScrollOptions) {
let onScroll = (e: MouseEvent) => {
// Ignore if scrolling an scrollable region outside the trigger's tree.
let target = e.target;
if (!triggerRef.current || !(target instanceof Node) || !target.contains(triggerRef.current)) {
// window is not a Node and doesn't have contain, but window contains everything
if (!triggerRef.current || ((target instanceof Node) && !target.contains(triggerRef.current))) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/overlays/test/useOverlayPosition.test.js
Expand Up @@ -172,15 +172,15 @@ describe('useOverlayPosition', function () {
expect(onClose).toHaveBeenCalledTimes(1);
});

it('should not throw or close when target is window in a scroll event', function () {
it('should close the overlay when target is window in a scroll event', function () {
// Cypress triggers an artificial scroll event in `screenshot` command:
// https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/screenshot.ts#L106
// More info: https://github.com/adobe/react-spectrum/issues/2340
let onClose = jest.fn();
render(<Example isOpen onClose={onClose} />);

fireEvent.scroll(window);
expect(onClose).toHaveBeenCalledTimes(0);
expect(onClose).toHaveBeenCalledTimes(1);
});
});

Expand Down

0 comments on commit c246bed

Please sign in to comment.