Skip to content

Commit 5bd7277

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

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

apps/preview/next/pages/showcases/MegaMenu/MegaMenuNavigation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ export default function MegaMenuNavigation() {
402402
const { close, open, isOpen } = useDisclosure();
403403
const { refs, style } = useDropdown({
404404
isOpen,
405-
onClose: (event: KeyboardEvent) => {
406-
if (event.key === 'Escape') {
405+
onClose: (event) => {
406+
if ('key' in event && event.key === 'Escape') {
407407
refsByKey[activeNode[0]]?.current?.focus();
408408
}
409409
close();

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)