From 2813a35bf6b4c44ec59b7c2b4910cc8dec6fc227 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Tue, 10 Dec 2019 20:17:54 +0000 Subject: [PATCH] `react-modal`: add `portal` instance property (#40714) * `react-modal`: add `portal` instance property * Improve example --- types/react-modal/index.d.ts | 5 +++++ types/react-modal/react-modal-tests.tsx | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/types/react-modal/index.d.ts b/types/react-modal/index.d.ts index f60d586c74..66d24a87e6 100644 --- a/types/react-modal/index.d.ts +++ b/types/react-modal/index.d.ts @@ -126,4 +126,9 @@ declare class ReactModal extends React.Component { * and other assistive technologies while the modal is open. */ static setAppElement(appElement: string | HTMLElement): void; + + portal: { + overlay: Element | undefined; + content: HTMLDivElement; + }; } diff --git a/types/react-modal/react-modal-tests.tsx b/types/react-modal/react-modal-tests.tsx index 96f7c84678..714a20e4ef 100644 --- a/types/react-modal/react-modal-tests.tsx +++ b/types/react-modal/react-modal-tests.tsx @@ -82,3 +82,13 @@ class ExampleOfUsingReactModal extends React.Component { ); } } + +const MyWrapperComponent: React.FC = () => { + const reactModaRef = React.useRef(); + + React.useLayoutEffect(() => { + reactModaRef.current.portal.content.focus(); + }); + + return Hello, World!; +};