Skip to content

Commit

Permalink
Fix(web-react): ClickOutside working with Dialog and Dropdown #DS-945
Browse files Browse the repository at this point in the history
- Moved logic for modal to modal callback from useClickOutside hook
  • Loading branch information
pavelklibani committed Oct 24, 2023
1 parent ab66984 commit ec1539c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/web-react/src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const Dialog = (props: DialogProps, ref: ForwardedRef<HTMLDialogElement | null>)
// handles toggling based on state
const { closeDialog } = useDialog(dialogElementRef as MutableRefObject<HTMLDialogElement | null>, isOpen);
const handleClickOutside = (event: Event) => {
if (closeOnBackdropClick) {
// check if it should be closed on backdrop click and if the click was on backdrop (dialog element, not on dialog content)
if (closeOnBackdropClick && event.target === dialogElementRef.current) {
closeDialog();
onClose(event);
}
Expand Down
2 changes: 0 additions & 2 deletions packages/web-react/src/hooks/useClickOutside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export const useClickOutside = ({ ref, callback }: UseClickOutsideProps): void =
// and the use the not clicked into the container,
// e. g. the user clicked outside of the Dialog (click on backdrop)
!ref.current.contains(event?.target as Node) &&
// and when the click was triggered inside of the element's parent
ref.current.parentNode?.contains(event?.target as Node) &&
// and callback should exits, of course
callback
) {
Expand Down

0 comments on commit ec1539c

Please sign in to comment.