Mirror: React hooks for accessible, common web interactions. UI super powers without the UI.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Pass event to onDismiss and prevent default on click

+6 -5
+6 -5
src/useDismissable.ts
··· 13 13 14 14 export function useDismissable<T extends HTMLElement>( 15 15 ref: Ref<T>, 16 - onDismiss: () => void, 16 + onDismiss: (event: Event) => void, 17 17 options?: DismissableOptions 18 18 ) { 19 19 const focusLoss = !!(options && options.focusLoss); ··· 40 40 !contains(element, relatedTarget) 41 41 ) { 42 42 willLoseFocus = false; 43 - onDismissRef.current(); 43 + onDismissRef.current(event); 44 44 } 45 45 } 46 46 47 47 function onFocusIn(event: FocusEvent) { 48 48 const { target } = event; 49 49 if (!event.defaultPrevented && !contains(element, target)) { 50 - onDismissRef.current(); 50 + onDismissRef.current(event); 51 51 } 52 52 } 53 53 ··· 60 60 // The current dialog can be dismissed by pressing escape if it either has focus 61 61 // or it has priority 62 62 event.preventDefault(); 63 - onDismissRef.current(); 63 + onDismissRef.current(event); 64 64 } else if (event.code === 'Tab') { 65 65 willLoseFocus = true; 66 66 } ··· 76 76 } else if (hasPriority.current) { 77 77 // The current dialog can be dismissed by pressing outside of it if it either has 78 78 // focus or it has priority 79 - onDismissRef.current(); 79 + event.preventDefault(); 80 + onDismissRef.current(event); 80 81 } 81 82 } 82 83