Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,14 @@ module.exports = [
],
},
},
// Web-specific files
{
files: ['src/**/*.web.{ts,tsx}'],
languageOptions: {
globals: {
document: 'readonly',
Element: 'readonly',
},
},
},
];
15 changes: 11 additions & 4 deletions src/ModalView.web.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useMemo } from 'react';
import type { FC } from 'react';

import { createPortal } from 'react-dom';
import { StyleSheet, View, Pressable } from 'react-native';

import { useID } from './hooks/useID';
import { useModalRegistry } from './hooks/useModalRegistry';

import type { MouseEvent } from 'react';
import type { ModalViewProps } from './types';

export type ModalViewWebProps = Omit<
Expand All @@ -24,7 +25,7 @@ export enum DismissalSource {
Backdrop = 'Backdrop',
}

export const ModalView: FC<ModalViewWebProps> = ({
export const ModalView = ({
modalId,
children,
renderBackdrop,
Expand All @@ -33,7 +34,7 @@ export const ModalView: FC<ModalViewWebProps> = ({
BackdropPressableComponent = Pressable,
backdropColor = defaultBackdropColor,
animationType = 'none',
}) => {
}: ModalViewWebProps) => {
const currentModalId = useID(modalId);
const { modals, isBackdropVisible } = useModalRegistry(currentModalId);
const modalIsOpen = modals.has(currentModalId);
Expand Down Expand Up @@ -65,7 +66,13 @@ export const ModalView: FC<ModalViewWebProps> = ({
styles.backdropPressable,
!isBackdropVisible && styles.backdropHidden,
]}
onPress={() => onRequestDismiss?.(DismissalSource.Backdrop)}
onPress={(e) => {
const event = e as unknown as MouseEvent<Element>;

if (event.target === event.currentTarget) {
onRequestDismiss?.(DismissalSource.Backdrop);
}
}}
>
{renderBackdrop ? (
renderBackdrop()
Expand Down