UNPKG

8.13 kBTypeScriptView Raw
1import * as React from "react";
2import { AbstractPureComponent2 } from "../../common";
3import { Props } from "../../common/props";
4export declare type OverlayableProps = IOverlayableProps;
5/** @deprecated use OverlayableProps */
6export interface IOverlayableProps extends IOverlayLifecycleProps {
7 /**
8 * Whether the overlay should acquire application focus when it first opens.
9 *
10 * @default true
11 */
12 autoFocus?: boolean;
13 /**
14 * Whether pressing the `esc` key should invoke `onClose`.
15 *
16 * @default true
17 */
18 canEscapeKeyClose?: boolean;
19 /**
20 * Whether the overlay should prevent focus from leaving itself. That is, if the user attempts
21 * to focus an element outside the overlay and this prop is enabled, then the overlay will
22 * immediately bring focus back to itself. If you are nesting overlay components, either disable
23 * this prop on the "outermost" overlays or mark the nested ones `usePortal={false}`.
24 *
25 * @default true
26 */
27 enforceFocus?: boolean;
28 /**
29 * If `true` and `usePortal={true}`, the `Portal` containing the children is created and attached
30 * to the DOM when the overlay is opened for the first time; otherwise this happens when the
31 * component mounts. Lazy mounting provides noticeable performance improvements if you have lots
32 * of overlays at once, such as on each row of a table.
33 *
34 * @default true
35 */
36 lazy?: boolean;
37 /**
38 * Whether the application should return focus to the last active element in the
39 * document after this overlay closes.
40 *
41 * @default true
42 */
43 shouldReturnFocusOnClose?: boolean;
44 /**
45 * Indicates how long (in milliseconds) the overlay's enter/leave transition takes.
46 * This is used by React `CSSTransition` to know when a transition completes and must match
47 * the duration of the animation in CSS. Only set this prop if you override Blueprint's default
48 * transitions with new transitions of a different length.
49 *
50 * @default 300
51 */
52 transitionDuration?: number;
53 /**
54 * Whether the overlay should be wrapped in a `Portal`, which renders its contents in a new
55 * element attached to `portalContainer` prop.
56 *
57 * This prop essentially determines which element is covered by the backdrop: if `false`,
58 * then only its parent is covered; otherwise, the entire page is covered (because the parent
59 * of the `Portal` is the `<body>` itself).
60 *
61 * Set this prop to `false` on nested overlays (such as `Dialog` or `Popover`) to ensure that they
62 * are rendered above their parents.
63 *
64 * @default true
65 */
66 usePortal?: boolean;
67 /**
68 * Space-delimited string of class names applied to the `Portal` element if
69 * `usePortal={true}`.
70 */
71 portalClassName?: string;
72 /**
73 * The container element into which the overlay renders its contents, when `usePortal` is `true`.
74 * This prop is ignored if `usePortal` is `false`.
75 *
76 * @default document.body
77 */
78 portalContainer?: HTMLElement;
79 /**
80 * A callback that is invoked when user interaction causes the overlay to close, such as
81 * clicking on the overlay or pressing the `esc` key (if enabled).
82 *
83 * Receives the event from the user's interaction, if there was an event (generally either a
84 * mouse or key event). Note that, since this component is controlled by the `isOpen` prop, it
85 * will not actually close itself until that prop becomes `false`.
86 */
87 onClose?: (event: React.SyntheticEvent<HTMLElement>) => void;
88}
89export declare type OverlayLifecycleProps = IOverlayLifecycleProps;
90export interface IOverlayLifecycleProps {
91 /**
92 * Lifecycle method invoked just before the CSS _close_ transition begins on
93 * a child. Receives the DOM element of the child being closed.
94 */
95 onClosing?: (node: HTMLElement) => void;
96 /**
97 * Lifecycle method invoked just after the CSS _close_ transition ends but
98 * before the child has been removed from the DOM. Receives the DOM element
99 * of the child being closed.
100 */
101 onClosed?: (node: HTMLElement) => void;
102 /**
103 * Lifecycle method invoked just after mounting the child in the DOM but
104 * just before the CSS _open_ transition begins. Receives the DOM element of
105 * the child being opened.
106 */
107 onOpening?: (node: HTMLElement) => void;
108 /**
109 * Lifecycle method invoked just after the CSS _open_ transition ends.
110 * Receives the DOM element of the child being opened.
111 */
112 onOpened?: (node: HTMLElement) => void;
113}
114export declare type BackdropProps = IBackdropProps;
115export interface IBackdropProps {
116 /** CSS class names to apply to backdrop element. */
117 backdropClassName?: string;
118 /** HTML props for the backdrop element. */
119 backdropProps?: React.HTMLProps<HTMLDivElement>;
120 /**
121 * Whether clicking outside the overlay element (either on backdrop when present or on document)
122 * should invoke `onClose`.
123 *
124 * @default true
125 */
126 canOutsideClickClose?: boolean;
127 /**
128 * Whether a container-spanning backdrop element should be rendered behind the contents.
129 *
130 * @default true
131 */
132 hasBackdrop?: boolean;
133}
134export declare type OverlayProps = IOverlayProps;
135/** @deprecated use OverlayProps */
136export interface IOverlayProps extends OverlayableProps, IBackdropProps, Props {
137 /**
138 * Toggles the visibility of the overlay and its children.
139 * This prop is required because the component is controlled.
140 */
141 isOpen: boolean;
142 /**
143 * Name of the transition for internal `CSSTransition`.
144 * Providing your own name here will require defining new CSS transition properties.
145 *
146 * @default Classes.OVERLAY
147 */
148 transitionName?: string;
149}
150export interface IOverlayState {
151 hasEverOpened?: boolean;
152}
153export declare class Overlay extends AbstractPureComponent2<OverlayProps, IOverlayState> {
154 static displayName: string;
155 static defaultProps: OverlayProps;
156 static getDerivedStateFromProps({ isOpen: hasEverOpened }: OverlayProps): {
157 hasEverOpened: true;
158 } | null;
159 private static openStack;
160 private static getLastOpened;
161 private isAutoFocusing;
162 private lastActiveElementBeforeOpened;
163 state: IOverlayState;
164 containerElement: HTMLElement | null;
165 private startFocusTrapElement;
166 private endFocusTrapElement;
167 private refHandlers;
168 render(): JSX.Element | null;
169 componentDidMount(): void;
170 componentDidUpdate(prevProps: OverlayProps): void;
171 componentWillUnmount(): void;
172 private maybeRenderChild;
173 private maybeRenderBackdrop;
174 private renderDummyElement;
175 /**
176 * Ensures repeatedly pressing shift+tab keeps focus inside the Overlay. Moves focus to
177 * the `endFocusTrapElement` or the first keyboard-focusable element in the Overlay (excluding
178 * the `startFocusTrapElement`), depending on whether the element losing focus is inside the
179 * Overlay.
180 */
181 private handleStartFocusTrapElementFocus;
182 /**
183 * Wrap around to the end of the dialog if `enforceFocus` is enabled.
184 */
185 private handleStartFocusTrapElementKeyDown;
186 /**
187 * Ensures repeatedly pressing tab keeps focus inside the Overlay. Moves focus to the
188 * `startFocusTrapElement` or the last keyboard-focusable element in the Overlay (excluding the
189 * `startFocusTrapElement`), depending on whether the element losing focus is inside the
190 * Overlay.
191 */
192 private handleEndFocusTrapElementFocus;
193 private getKeyboardFocusableElements;
194 private overlayWillClose;
195 private overlayWillOpen;
196 private handleTransitionExited;
197 private handleBackdropMouseDown;
198 private handleDocumentClick;
199 /**
200 * When multiple Overlays are open, this event handler is only active for the most recently
201 * opened one to avoid Overlays competing with each other for focus.
202 */
203 private handleDocumentFocus;
204 private handleKeyDown;
205 private handleTransitionAddEnd;
206}