|
| 1 | +/* |
| 2 | + * Copyright 2024 Adobe. All rights reserved. |
| 3 | + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | + * of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | + * OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | + * governing permissions and limitations under the License. |
| 11 | + */ |
| 12 | + |
| 13 | +import {fireEvent, render} from '@react-spectrum/test-utils-internal'; |
| 14 | +import {type OverlayTriggerProps, useOverlayTriggerState} from '@react-stately/overlays'; |
| 15 | +import React, {useRef} from 'react'; |
| 16 | +import {useOverlayTrigger, usePopover} from '../'; |
| 17 | + |
| 18 | +function Example(props: OverlayTriggerProps) { |
| 19 | + const triggerRef = useRef(null); |
| 20 | + const popoverRef = useRef(null); |
| 21 | + const state = useOverlayTriggerState(props); |
| 22 | + useOverlayTrigger({type: 'listbox'}, state, triggerRef); |
| 23 | + const {popoverProps} = usePopover({triggerRef, popoverRef}, state); |
| 24 | + |
| 25 | + return ( |
| 26 | + <div> |
| 27 | + <div ref={triggerRef} /> |
| 28 | + <div {...popoverProps} ref={popoverRef} /> |
| 29 | + </div> |
| 30 | + ); |
| 31 | +} |
| 32 | + |
| 33 | +describe('usePopover', () => { |
| 34 | + it('should not close popover on scroll', () => { |
| 35 | + const onOpenChange = jest.fn(); |
| 36 | + render(<Example isOpen onOpenChange={onOpenChange} />); |
| 37 | + |
| 38 | + fireEvent.scroll(document.body); |
| 39 | + expect(onOpenChange).not.toHaveBeenCalled(); |
| 40 | + }); |
| 41 | +}); |
0 commit comments