Skip to content

Commit f56a47f

Browse files
fix(click): Fix outside click detection if there is only one page (#518)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent f18ed1f commit f56a47f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/region/RegionList.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ export function RegionList({ activeId, annotations, className, onSelect = noop }
3636
const rootElRef = React.createRef<HTMLDivElement>();
3737

3838
// Document-level event handlers for focus and pointer control
39-
useOutsideEvent('click', rootElRef, (): void => onSelect(null));
40-
useOutsideEvent('mousedown', rootElRef, (): void => setIsListening(false));
39+
useOutsideEvent('mousedown', rootElRef, (): void => {
40+
onSelect(null);
41+
setIsListening(false);
42+
});
4143
useOutsideEvent('mouseup', rootElRef, (): void => setIsListening(true));
4244

4345
return (

src/region/__tests__/RegionList-test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ describe('RegionList', () => {
3535

3636
getWrapper({ onSelect });
3737

38-
expect(onSelect).toHaveBeenCalledWith(null); // click
38+
expect(onSelect).toHaveBeenCalledWith(null); // mousedown
3939
expect(setIsListening).toHaveBeenNthCalledWith(1, false); // mousedown
4040
expect(setIsListening).toHaveBeenNthCalledWith(2, true); // mouseup
41-
expect(useOutsideEvent).toHaveBeenCalledTimes(3);
41+
expect(useOutsideEvent).toHaveBeenCalledTimes(2);
4242
});
4343
});
4444

0 commit comments

Comments
 (0)