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

Pass event to onDismiss and prevent default on click

Changed files
+6 -5
src
+6 -5
src/useDismissable.ts
···
export function useDismissable<T extends HTMLElement>(
ref: Ref<T>,
-
onDismiss: () => void,
options?: DismissableOptions
) {
const focusLoss = !!(options && options.focusLoss);
···
!contains(element, relatedTarget)
) {
willLoseFocus = false;
-
onDismissRef.current();
}
}
function onFocusIn(event: FocusEvent) {
const { target } = event;
if (!event.defaultPrevented && !contains(element, target)) {
-
onDismissRef.current();
}
}
···
// The current dialog can be dismissed by pressing escape if it either has focus
// or it has priority
event.preventDefault();
-
onDismissRef.current();
} else if (event.code === 'Tab') {
willLoseFocus = true;
}
···
} else if (hasPriority.current) {
// The current dialog can be dismissed by pressing outside of it if it either has
// focus or it has priority
-
onDismissRef.current();
}
}
···
export function useDismissable<T extends HTMLElement>(
ref: Ref<T>,
+
onDismiss: (event: Event) => void,
options?: DismissableOptions
) {
const focusLoss = !!(options && options.focusLoss);
···
!contains(element, relatedTarget)
) {
willLoseFocus = false;
+
onDismissRef.current(event);
}
}
function onFocusIn(event: FocusEvent) {
const { target } = event;
if (!event.defaultPrevented && !contains(element, target)) {
+
onDismissRef.current(event);
}
}
···
// The current dialog can be dismissed by pressing escape if it either has focus
// or it has priority
event.preventDefault();
+
onDismissRef.current(event);
} else if (event.code === 'Tab') {
willLoseFocus = true;
}
···
} else if (hasPriority.current) {
// The current dialog can be dismissed by pressing outside of it if it either has
// focus or it has priority
+
event.preventDefault();
+
onDismissRef.current(event);
}
}