Changeset View
Changeset View
Standalone View
Standalone View
lib/components/modal-overlay.react.js
// @flow | // @flow | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import css from './modal-overlay.css'; | import css from './modal-overlay.css'; | ||||
type ModalOverlayProps = { | type ModalOverlayProps = { | ||||
+onClose: () => void, | +onClose: () => void, | ||||
+children?: React.Node, | +children?: React.Node, | ||||
+disableTab?: boolean, | +disableTab?: boolean, | ||||
+disableAutoFocus?: boolean, | |||||
}; | }; | ||||
function ModalOverlay(props: ModalOverlayProps): React.Node { | function ModalOverlay(props: ModalOverlayProps): React.Node { | ||||
const { children, onClose, disableTab } = props; | const { children, onClose, disableTab, disableAutoFocus } = props; | ||||
const overlayRef = React.useRef(); | const overlayRef = React.useRef(); | ||||
const firstClickRef = React.useRef(null); | const firstClickRef = React.useRef(null); | ||||
React.useLayoutEffect(() => { | React.useLayoutEffect(() => { | ||||
if (overlayRef.current) { | if (!disableAutoFocus && overlayRef.current) { | ||||
overlayRef.current.focus(); | overlayRef.current.focus(); | ||||
} | } | ||||
}, []); | }, [disableAutoFocus]); | ||||
const onBackgroundMouseDown = React.useCallback(event => { | const onBackgroundMouseDown = React.useCallback(event => { | ||||
firstClickRef.current = event.target; | firstClickRef.current = event.target; | ||||
}, []); | }, []); | ||||
const onBackgroundMouseUp = React.useCallback( | const onBackgroundMouseUp = React.useCallback( | ||||
event => { | event => { | ||||
if ( | if ( | ||||
Show All 36 Lines |