Skip to content

Commit cdab106

Browse files
committed
chore: fixup tests
1 parent 307155b commit cdab106

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

packages/sfui/frameworks/react/hooks/useDropdown/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { UsePopoverOptions } from '../usePopover';
33

44
export type UseDropdownOptions = Prettify<
55
UsePopoverOptions & {
6-
onClose: (event: KeyboardEvent) => void;
6+
onClose: (event: KeyboardEvent | PointerEvent | MouseEvent | TouchEvent) => void;
77
onCloseDeps?: unknown[];
88
}
99
>;

packages/sfui/frameworks/react/hooks/useDropdown/useDropdown.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ export function useDropdown(options: UseDropdownOptions) {
99
onCloseDeps,
1010
placement = 'bottom',
1111
middleware = [offset(8), shift(), flip()],
12+
isOpen,
1213
...popoverOptions
1314
} = options;
1415

15-
const { refs, style } = usePopover({ placement, middleware, ...popoverOptions });
16+
const { refs, style } = usePopover({ placement, middleware, isOpen, ...popoverOptions });
1617

17-
useClickAway(refs.reference, onClose);
18+
useClickAway<PointerEvent | MouseEvent | TouchEvent>(refs.reference, (e) => {
19+
if (isOpen) {
20+
onClose?.(e);
21+
}
22+
});
1823
useKey('Escape', onClose, { target: refs.reference.current }, onCloseDeps);
1924

2025
return { refs, style };

packages/tests/components/SfDropdown/SfDropdown.cy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('SfDropdown', () => {
9191

9292
describe('When click away', () => {
9393
it('Should call onClose', () => {
94-
const props = { onClose: cy.spy() };
94+
const props = { onClose: cy.spy(), modelValue: ref(true) };
9595
initializeComponent(props);
9696

9797
page().clickAway(props.onClose);

0 commit comments

Comments
 (0)