@react-aria/overlays 3.0.0-nightly.1658 → 3.0.0-nightly.1663
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +15 -51
- package/dist/main.js.map +1 -1
- package/dist/module.js +4 -32
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +18 -18
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/ariaHideOutside.ts +4 -4
- package/src/calculatePosition.ts +8 -8
- package/src/index.ts +7 -8
- package/src/useCloseOnScroll.ts +2 -2
- package/src/useModal.tsx +5 -4
- package/src/useOverlay.ts +12 -11
- package/src/useOverlayPosition.ts +8 -7
- package/src/useOverlayTrigger.ts +4 -3
package/dist/types.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DOMAttributes, AriaLabelingProps, DOMProps } from "@react-types/shared";
|
|
2
2
|
import { PlacementAxis, PositionProps } from "@react-types/overlays";
|
|
3
|
+
import React, { RefObject, AriaAttributes, ReactNode } from "react";
|
|
3
4
|
import { AriaButtonProps } from "@react-types/button";
|
|
4
5
|
import { OverlayTriggerState } from "@react-stately/overlays";
|
|
5
|
-
import { AriaLabelingProps, DOMProps } from "@react-types/shared";
|
|
6
6
|
interface AriaPositionProps extends PositionProps {
|
|
7
7
|
/**
|
|
8
8
|
* Element that that serves as the positioning boundary.
|
|
9
9
|
* @default document.body
|
|
10
10
|
*/
|
|
11
|
-
boundaryElement?:
|
|
11
|
+
boundaryElement?: Element;
|
|
12
12
|
/**
|
|
13
13
|
* The ref for the element which the overlay positions itself with respect to.
|
|
14
14
|
*/
|
|
15
|
-
targetRef: RefObject<
|
|
15
|
+
targetRef: RefObject<Element>;
|
|
16
16
|
/**
|
|
17
17
|
* The ref for the overlay element.
|
|
18
18
|
*/
|
|
19
|
-
overlayRef: RefObject<
|
|
19
|
+
overlayRef: RefObject<Element>;
|
|
20
20
|
/**
|
|
21
21
|
* A ref for the scrollable region within the overlay.
|
|
22
22
|
* @default overlayRef
|
|
23
23
|
*/
|
|
24
|
-
scrollRef?: RefObject<
|
|
24
|
+
scrollRef?: RefObject<Element>;
|
|
25
25
|
/**
|
|
26
26
|
* Whether the overlay should update its position automatically.
|
|
27
27
|
* @default true
|
|
@@ -37,9 +37,9 @@ interface AriaPositionProps extends PositionProps {
|
|
|
37
37
|
}
|
|
38
38
|
interface PositionAria {
|
|
39
39
|
/** Props for the overlay container element. */
|
|
40
|
-
overlayProps:
|
|
40
|
+
overlayProps: DOMAttributes;
|
|
41
41
|
/** Props for the overlay tip arrow if any. */
|
|
42
|
-
arrowProps:
|
|
42
|
+
arrowProps: DOMAttributes;
|
|
43
43
|
/** Placement of the overlay with respect to the overlay trigger. */
|
|
44
44
|
placement: PlacementAxis;
|
|
45
45
|
/** Updates the position of the overlay. */
|
|
@@ -73,20 +73,20 @@ interface OverlayProps {
|
|
|
73
73
|
* out interaction with elements that should not dismiss the overlay.
|
|
74
74
|
* By default, onClose will always be called on interaction outside the overlay ref.
|
|
75
75
|
*/
|
|
76
|
-
shouldCloseOnInteractOutside?: (element:
|
|
76
|
+
shouldCloseOnInteractOutside?: (element: Element) => boolean;
|
|
77
77
|
}
|
|
78
78
|
interface OverlayAria {
|
|
79
79
|
/** Props to apply to the overlay container element. */
|
|
80
|
-
overlayProps:
|
|
80
|
+
overlayProps: DOMAttributes;
|
|
81
81
|
/** Props to apply to the underlay element, if any. */
|
|
82
|
-
underlayProps:
|
|
82
|
+
underlayProps: DOMAttributes;
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* Provides the behavior for overlays such as dialogs, popovers, and menus.
|
|
86
86
|
* Hides the overlay when the user interacts outside it, when the Escape key is pressed,
|
|
87
87
|
* or optionally, on blur. Only the top-most overlay will close at once.
|
|
88
88
|
*/
|
|
89
|
-
export function useOverlay(props: OverlayProps, ref: RefObject<
|
|
89
|
+
export function useOverlay(props: OverlayProps, ref: RefObject<Element>): OverlayAria;
|
|
90
90
|
interface OverlayTriggerProps {
|
|
91
91
|
/** Type of overlay that is opened by the trigger. */
|
|
92
92
|
type: 'dialog' | 'menu' | 'listbox' | 'tree' | 'grid';
|
|
@@ -95,13 +95,13 @@ interface OverlayTriggerAria {
|
|
|
95
95
|
/** Props for the trigger element. */
|
|
96
96
|
triggerProps: AriaButtonProps;
|
|
97
97
|
/** Props for the overlay container element. */
|
|
98
|
-
overlayProps:
|
|
98
|
+
overlayProps: DOMAttributes;
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
101
|
* Handles the behavior and accessibility for an overlay trigger, e.g. a button
|
|
102
102
|
* that opens a popover, menu, or other overlay that is positioned relative to the trigger.
|
|
103
103
|
*/
|
|
104
|
-
export function useOverlayTrigger(props: OverlayTriggerProps, state: OverlayTriggerState, ref: RefObject<
|
|
104
|
+
export function useOverlayTrigger(props: OverlayTriggerProps, state: OverlayTriggerState, ref: RefObject<Element>): OverlayTriggerAria;
|
|
105
105
|
interface PreventScrollOptions {
|
|
106
106
|
/** Whether the scroll lock is disabled. */
|
|
107
107
|
isDisabled?: boolean;
|
|
@@ -112,7 +112,7 @@ interface PreventScrollOptions {
|
|
|
112
112
|
* shift due to the scrollbars disappearing.
|
|
113
113
|
*/
|
|
114
114
|
export function usePreventScroll(options?: PreventScrollOptions): void;
|
|
115
|
-
interface ModalProviderProps extends
|
|
115
|
+
interface ModalProviderProps extends DOMAttributes {
|
|
116
116
|
children: ReactNode;
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
@@ -149,7 +149,7 @@ interface OverlayContainerProps extends ModalProviderProps {
|
|
|
149
149
|
* The container element in which the overlay portal will be placed.
|
|
150
150
|
* @default document.body
|
|
151
151
|
*/
|
|
152
|
-
portalContainer?:
|
|
152
|
+
portalContainer?: Element;
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
155
|
* A container for overlays like modals and popovers. Renders the overlay
|
|
@@ -159,7 +159,7 @@ interface OverlayContainerProps extends ModalProviderProps {
|
|
|
159
159
|
* be accessible at once.
|
|
160
160
|
*/
|
|
161
161
|
export function OverlayContainer(props: OverlayContainerProps): React.ReactPortal;
|
|
162
|
-
interface ModalAriaProps extends
|
|
162
|
+
interface ModalAriaProps extends DOMAttributes {
|
|
163
163
|
/** Data attribute marks the dom node as a modal for the aria-modal-polyfill. */
|
|
164
164
|
'data-ismodal': boolean;
|
|
165
165
|
}
|
|
@@ -195,6 +195,6 @@ export function DismissButton(props: DismissButtonProps): JSX.Element;
|
|
|
195
195
|
* @param root - Nothing will be hidden above this element.
|
|
196
196
|
* @returns - A function to restore all hidden elements.
|
|
197
197
|
*/
|
|
198
|
-
export function ariaHideOutside(targets:
|
|
198
|
+
export function ariaHideOutside(targets: Element[], root?: HTMLElement): () => void;
|
|
199
199
|
|
|
200
200
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;
|
|
1
|
+
{"mappings":";;;;;AEoBA,2BAA4B,SAAQ,aAAa;IAC/C;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;OAEG;IACH,SAAS,EAAE,UAAU,OAAO,CAAC,CAAC;IAC9B;;OAEG;IACH,UAAU,EAAE,UAAU,OAAO,CAAC,CAAC;IAC/B;;;OAGG;IACH,SAAS,CAAC,EAAE,UAAU,OAAO,CAAC,CAAC;IAC/B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;IACE,+CAA+C;IAC/C,YAAY,EAAE,aAAa,CAAC;IAC5B,8CAA8C;IAC9C,UAAU,EAAE,aAAa,CAAC;IAC1B,oEAAoE;IACpE,SAAS,EAAE,aAAa,CAAC;IACzB,2CAA2C;IAC3C,cAAc,IAAI,IAAI,CAAA;CACvB;AAKD;;;GAGG;AACH,mCAAmC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CA2HzE;AClLD;IACE,6CAA6C;IAC7C,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAErB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,+EAA+E;IAC/E,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;OAGG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IAEpC;;;;;OAKG;IACH,4BAA4B,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAA;CAC7D;AAED;IACE,uDAAuD;IACvD,YAAY,EAAE,aAAa,CAAC;IAC5B,sDAAsD;IACtD,aAAa,EAAE,aAAa,CAAA;CAC7B;AAID;;;;GAIG;AACH,2BAA2B,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,OAAO,CAAC,GAAG,WAAW,CAuFpF;ACjID;IACE,qDAAqD;IACrD,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAA;CACtD;AAED;IACE,qCAAqC;IACrC,YAAY,EAAE,eAAe,CAAC;IAE9B,+CAA+C;IAC/C,YAAY,EAAE,aAAa,CAAA;CAC5B;AAED;;;GAGG;AACH,kCAAkC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,mBAAmB,EAAE,GAAG,EAAE,UAAU,OAAO,CAAC,GAAG,kBAAkB,CAmCrI;ACzDD;IACE,2CAA2C;IAC3C,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAkBD;;;;GAIG;AACH,iCAAiC,OAAO,GAAE,oBAAyB,QAclE;ACrCD,4BAA6B,SAAQ,aAAa;IAChD,QAAQ,EAAE,SAAS,CAAA;CACpB;AAWD;;;;;;;GAOG;AACH,8BAA8B,KAAK,EAAE,kBAAkB,eA0BtD;AAED;IACE;;OAEG;IACH,kBAAkB,EAAE,cAAc,CAAA;CACnC;AAED;;;GAGG;AACH,oCAAoC,iBAAiB,CAOpD;AAUD;;;;;;;GAOG;AACH,gCAAgC,KAAK,EAAE,kBAAkB,eAMxD;AAED,+BAAgC,SAAQ,kBAAkB;IACxD;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;;;;;;GAMG;AACH,iCAAiC,KAAK,EAAE,qBAAqB,GAAG,MAAM,WAAW,CAgBhF;AAED,wBAAyB,SAAQ,aAAa;IAC5C,gFAAgF;IAChF,cAAc,EAAE,OAAO,CAAA;CACxB;AAED;IACE,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED;IACE,2CAA2C;IAC3C,UAAU,EAAE,cAAc,CAAA;CAC3B;AAED;;;;;GAKG;AACH,yBAAyB,OAAO,CAAC,EAAE,YAAY,GAAG,SAAS,CA2B1D;AC1KD,4BAA6B,SAAQ,iBAAiB,EAAE,QAAQ;IAC9D,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;CACvB;AAED;;;;GAIG;AACH,8BAA8B,KAAK,EAAE,kBAAkB,eAoBtD;AClCD;;;;;;;GAOG;AACH,gCAAgC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,cAAgB,cAgGvE","sources":["packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/calculatePosition.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/useCloseOnScroll.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/useOverlayPosition.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/useOverlay.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/useOverlayTrigger.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/usePreventScroll.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/useModal.tsx","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/DismissButton.tsx","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/ariaHideOutside.ts","packages/@react-aria/overlays/src/packages/@react-aria/overlays/src/index.ts","packages/@react-aria/overlays/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useOverlayPosition} from './useOverlayPosition';\nexport {useOverlay} from './useOverlay';\nexport {useOverlayTrigger} from './useOverlayTrigger';\nexport {usePreventScroll} from './usePreventScroll';\nexport {ModalProvider, useModalProvider, OverlayProvider, OverlayContainer, useModal} from './useModal';\nexport {DismissButton} from './DismissButton';\nexport {ariaHideOutside} from './ariaHideOutside';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/overlays",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.1663+2a6c48eb0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-aria/i18n": "3.0.0-nightly.
|
|
22
|
-
"@react-aria/interactions": "3.0.0-nightly.
|
|
23
|
-
"@react-aria/ssr": "3.2.1-nightly.
|
|
24
|
-
"@react-aria/utils": "3.0.0-nightly.
|
|
25
|
-
"@react-aria/visually-hidden": "3.0.0-nightly.
|
|
26
|
-
"@react-stately/overlays": "3.3.2-nightly.
|
|
27
|
-
"@react-types/button": "3.5.2-nightly.
|
|
28
|
-
"@react-types/overlays": "3.6.2-nightly.
|
|
29
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
21
|
+
"@react-aria/i18n": "3.0.0-nightly.1663+2a6c48eb0",
|
|
22
|
+
"@react-aria/interactions": "3.0.0-nightly.1663+2a6c48eb0",
|
|
23
|
+
"@react-aria/ssr": "3.2.1-nightly.3363+2a6c48eb0",
|
|
24
|
+
"@react-aria/utils": "3.0.0-nightly.1663+2a6c48eb0",
|
|
25
|
+
"@react-aria/visually-hidden": "3.0.0-nightly.1663+2a6c48eb0",
|
|
26
|
+
"@react-stately/overlays": "3.3.2-nightly.3363+2a6c48eb0",
|
|
27
|
+
"@react-types/button": "3.5.2-nightly.3363+2a6c48eb0",
|
|
28
|
+
"@react-types/overlays": "3.6.2-nightly.3363+2a6c48eb0",
|
|
29
|
+
"@react-types/shared": "3.0.0-nightly.1663+2a6c48eb0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "2a6c48eb0099671cf9b530ec3d75882c549e9cb5"
|
|
39
39
|
}
|
package/src/ariaHideOutside.ts
CHANGED
|
@@ -22,7 +22,7 @@ let refCountMap = new WeakMap<Element, number>();
|
|
|
22
22
|
* @param root - Nothing will be hidden above this element.
|
|
23
23
|
* @returns - A function to restore all hidden elements.
|
|
24
24
|
*/
|
|
25
|
-
export function ariaHideOutside(targets:
|
|
25
|
+
export function ariaHideOutside(targets: Element[], root = document.body) {
|
|
26
26
|
let visibleNodes = new Set<Element>(targets);
|
|
27
27
|
let hiddenNodes = new Set<Element>();
|
|
28
28
|
let walker = document.createTreeWalker(
|
|
@@ -31,7 +31,7 @@ export function ariaHideOutside(targets: HTMLElement[], root = document.body) {
|
|
|
31
31
|
{
|
|
32
32
|
acceptNode(node) {
|
|
33
33
|
// If this node is a live announcer, add it to the set of nodes to keep visible.
|
|
34
|
-
if ((node instanceof HTMLElement && node.dataset.liveAnnouncer === 'true')) {
|
|
34
|
+
if (((node instanceof HTMLElement || node instanceof SVGElement) && node.dataset.liveAnnouncer === 'true')) {
|
|
35
35
|
visibleNodes.add(node);
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -46,7 +46,7 @@ export function ariaHideOutside(targets: HTMLElement[], root = document.body) {
|
|
|
46
46
|
|
|
47
47
|
// VoiceOver on iOS has issues hiding elements with role="row". Hide the cells inside instead.
|
|
48
48
|
// https://bugs.webkit.org/show_bug.cgi?id=222623
|
|
49
|
-
if (node instanceof
|
|
49
|
+
if (node instanceof Element && node.getAttribute('role') === 'row') {
|
|
50
50
|
return NodeFilter.FILTER_SKIP;
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -93,7 +93,7 @@ export function ariaHideOutside(targets: HTMLElement[], root = document.body) {
|
|
|
93
93
|
// and not already inside a hidden node, hide all of the new children.
|
|
94
94
|
if (![...visibleNodes, ...hiddenNodes].some(node => node.contains(change.target))) {
|
|
95
95
|
for (let node of change.addedNodes) {
|
|
96
|
-
if ((node instanceof HTMLElement && node.dataset.liveAnnouncer === 'true')) {
|
|
96
|
+
if (((node instanceof HTMLElement || node instanceof SVGElement) && node.dataset.liveAnnouncer === 'true')) {
|
|
97
97
|
visibleNodes.add(node);
|
|
98
98
|
} else if (node instanceof Element) {
|
|
99
99
|
hide(node);
|
package/src/calculatePosition.ts
CHANGED
|
@@ -45,12 +45,12 @@ interface Offset {
|
|
|
45
45
|
|
|
46
46
|
interface PositionOpts {
|
|
47
47
|
placement: Placement,
|
|
48
|
-
targetNode:
|
|
49
|
-
overlayNode:
|
|
50
|
-
scrollNode:
|
|
48
|
+
targetNode: Element,
|
|
49
|
+
overlayNode: Element,
|
|
50
|
+
scrollNode: Element,
|
|
51
51
|
padding: number,
|
|
52
52
|
shouldFlip: boolean,
|
|
53
|
-
boundaryElement:
|
|
53
|
+
boundaryElement: Element,
|
|
54
54
|
offset: number,
|
|
55
55
|
crossOffset: number,
|
|
56
56
|
maxHeight?: number
|
|
@@ -93,7 +93,7 @@ const PARSED_PLACEMENT_CACHE = {};
|
|
|
93
93
|
// @ts-ignore
|
|
94
94
|
let visualViewport = typeof window !== 'undefined' && window.visualViewport;
|
|
95
95
|
|
|
96
|
-
function getContainerDimensions(containerNode:
|
|
96
|
+
function getContainerDimensions(containerNode: Element): Dimensions {
|
|
97
97
|
let width = 0, height = 0, top = 0, left = 0;
|
|
98
98
|
let scroll: Position = {};
|
|
99
99
|
|
|
@@ -113,7 +113,7 @@ function getContainerDimensions(containerNode: HTMLElement): Dimensions {
|
|
|
113
113
|
return {width, height, scroll, top, left};
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
function getScroll(node:
|
|
116
|
+
function getScroll(node: Element): Offset {
|
|
117
117
|
return {
|
|
118
118
|
top: node.scrollTop,
|
|
119
119
|
left: node.scrollLeft,
|
|
@@ -144,7 +144,7 @@ function getDelta(
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
function getMargins(node:
|
|
147
|
+
function getMargins(node: Element): Position {
|
|
148
148
|
let style = window.getComputedStyle(node);
|
|
149
149
|
return {
|
|
150
150
|
top: parseInt(style.marginTop, 10) || 0,
|
|
@@ -364,7 +364,7 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
|
|
|
364
364
|
maxHeight
|
|
365
365
|
} = opts;
|
|
366
366
|
|
|
367
|
-
let container = (overlayNode.offsetParent || document.body) as
|
|
367
|
+
let container = ((overlayNode instanceof HTMLElement && overlayNode.offsetParent) || document.body) as Element;
|
|
368
368
|
let isBodyContainer = container.tagName === 'BODY';
|
|
369
369
|
const containerPositionStyle = window.getComputedStyle(container).position;
|
|
370
370
|
let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';
|
package/src/index.ts
CHANGED
|
@@ -9,11 +9,10 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export * from './ariaHideOutside';
|
|
12
|
+
export {useOverlayPosition} from './useOverlayPosition';
|
|
13
|
+
export {useOverlay} from './useOverlay';
|
|
14
|
+
export {useOverlayTrigger} from './useOverlayTrigger';
|
|
15
|
+
export {usePreventScroll} from './usePreventScroll';
|
|
16
|
+
export {ModalProvider, useModalProvider, OverlayProvider, OverlayContainer, useModal} from './useModal';
|
|
17
|
+
export {DismissButton} from './DismissButton';
|
|
18
|
+
export {ariaHideOutside} from './ariaHideOutside';
|
package/src/useCloseOnScroll.ts
CHANGED
|
@@ -17,10 +17,10 @@ import {RefObject, useEffect} from 'react';
|
|
|
17
17
|
// it sets a close function here mapped from the trigger element. This way we can avoid
|
|
18
18
|
// forcing users to pass an onClose function to useOverlayPosition which could be considered
|
|
19
19
|
// a breaking change.
|
|
20
|
-
export const onCloseMap: WeakMap<
|
|
20
|
+
export const onCloseMap: WeakMap<Element, () => void> = new WeakMap();
|
|
21
21
|
|
|
22
22
|
interface CloseOnScrollOptions {
|
|
23
|
-
triggerRef: RefObject<
|
|
23
|
+
triggerRef: RefObject<Element>,
|
|
24
24
|
isOpen?: boolean,
|
|
25
25
|
onClose?: () => void
|
|
26
26
|
}
|
package/src/useModal.tsx
CHANGED
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import
|
|
13
|
+
import {DOMAttributes} from '@react-types/shared';
|
|
14
|
+
import React, {AriaAttributes, ReactNode, useContext, useEffect, useMemo, useState} from 'react';
|
|
14
15
|
import ReactDOM from 'react-dom';
|
|
15
16
|
import {useIsSSR} from '@react-aria/ssr';
|
|
16
17
|
|
|
17
|
-
interface ModalProviderProps extends
|
|
18
|
+
interface ModalProviderProps extends DOMAttributes {
|
|
18
19
|
children: ReactNode
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -112,7 +113,7 @@ interface OverlayContainerProps extends ModalProviderProps {
|
|
|
112
113
|
* The container element in which the overlay portal will be placed.
|
|
113
114
|
* @default document.body
|
|
114
115
|
*/
|
|
115
|
-
portalContainer?:
|
|
116
|
+
portalContainer?: Element
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
/**
|
|
@@ -140,7 +141,7 @@ export function OverlayContainer(props: OverlayContainerProps): React.ReactPorta
|
|
|
140
141
|
return ReactDOM.createPortal(contents, portalContainer);
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
interface ModalAriaProps extends
|
|
144
|
+
interface ModalAriaProps extends DOMAttributes {
|
|
144
145
|
/** Data attribute marks the dom node as a modal for the aria-modal-polyfill. */
|
|
145
146
|
'data-ismodal': boolean
|
|
146
147
|
}
|
package/src/useOverlay.ts
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import {DOMAttributes} from '@react-types/shared';
|
|
14
|
+
import {RefObject, SyntheticEvent, useEffect} from 'react';
|
|
14
15
|
import {useFocusWithin, useInteractOutside} from '@react-aria/interactions';
|
|
15
16
|
|
|
16
17
|
interface OverlayProps {
|
|
@@ -41,24 +42,24 @@ interface OverlayProps {
|
|
|
41
42
|
* out interaction with elements that should not dismiss the overlay.
|
|
42
43
|
* By default, onClose will always be called on interaction outside the overlay ref.
|
|
43
44
|
*/
|
|
44
|
-
shouldCloseOnInteractOutside?: (element:
|
|
45
|
+
shouldCloseOnInteractOutside?: (element: Element) => boolean
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
interface OverlayAria {
|
|
48
49
|
/** Props to apply to the overlay container element. */
|
|
49
|
-
overlayProps:
|
|
50
|
+
overlayProps: DOMAttributes,
|
|
50
51
|
/** Props to apply to the underlay element, if any. */
|
|
51
|
-
underlayProps:
|
|
52
|
+
underlayProps: DOMAttributes
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
const visibleOverlays: RefObject<
|
|
55
|
+
const visibleOverlays: RefObject<Element>[] = [];
|
|
55
56
|
|
|
56
57
|
/**
|
|
57
58
|
* Provides the behavior for overlays such as dialogs, popovers, and menus.
|
|
58
59
|
* Hides the overlay when the user interacts outside it, when the Escape key is pressed,
|
|
59
60
|
* or optionally, on blur. Only the top-most overlay will close at once.
|
|
60
61
|
*/
|
|
61
|
-
export function useOverlay(props: OverlayProps, ref: RefObject<
|
|
62
|
+
export function useOverlay(props: OverlayProps, ref: RefObject<Element>): OverlayAria {
|
|
62
63
|
let {
|
|
63
64
|
onClose,
|
|
64
65
|
shouldCloseOnBlur,
|
|
@@ -89,8 +90,8 @@ export function useOverlay(props: OverlayProps, ref: RefObject<HTMLElement>): Ov
|
|
|
89
90
|
}
|
|
90
91
|
};
|
|
91
92
|
|
|
92
|
-
let onInteractOutsideStart = (e: SyntheticEvent<
|
|
93
|
-
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as
|
|
93
|
+
let onInteractOutsideStart = (e: SyntheticEvent<Element>) => {
|
|
94
|
+
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as Element)) {
|
|
94
95
|
if (visibleOverlays[visibleOverlays.length - 1] === ref) {
|
|
95
96
|
e.stopPropagation();
|
|
96
97
|
e.preventDefault();
|
|
@@ -98,8 +99,8 @@ export function useOverlay(props: OverlayProps, ref: RefObject<HTMLElement>): Ov
|
|
|
98
99
|
}
|
|
99
100
|
};
|
|
100
101
|
|
|
101
|
-
let onInteractOutside = (e: SyntheticEvent<
|
|
102
|
-
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as
|
|
102
|
+
let onInteractOutside = (e: SyntheticEvent<Element>) => {
|
|
103
|
+
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as Element)) {
|
|
103
104
|
if (visibleOverlays[visibleOverlays.length - 1] === ref) {
|
|
104
105
|
e.stopPropagation();
|
|
105
106
|
e.preventDefault();
|
|
@@ -123,7 +124,7 @@ export function useOverlay(props: OverlayProps, ref: RefObject<HTMLElement>): Ov
|
|
|
123
124
|
let {focusWithinProps} = useFocusWithin({
|
|
124
125
|
isDisabled: !shouldCloseOnBlur,
|
|
125
126
|
onBlurWithin: (e) => {
|
|
126
|
-
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget as
|
|
127
|
+
if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget as Element)) {
|
|
127
128
|
onClose();
|
|
128
129
|
}
|
|
129
130
|
}
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {calculatePosition, PositionResult} from './calculatePosition';
|
|
14
|
-
import {
|
|
14
|
+
import {DOMAttributes} from '@react-types/shared';
|
|
15
15
|
import {Placement, PlacementAxis, PositionProps} from '@react-types/overlays';
|
|
16
|
+
import {RefObject, useCallback, useRef, useState} from 'react';
|
|
16
17
|
import {useCloseOnScroll} from './useCloseOnScroll';
|
|
17
18
|
import {useLayoutEffect} from '@react-aria/utils';
|
|
18
19
|
import {useLocale} from '@react-aria/i18n';
|
|
@@ -22,20 +23,20 @@ interface AriaPositionProps extends PositionProps {
|
|
|
22
23
|
* Element that that serves as the positioning boundary.
|
|
23
24
|
* @default document.body
|
|
24
25
|
*/
|
|
25
|
-
boundaryElement?:
|
|
26
|
+
boundaryElement?: Element,
|
|
26
27
|
/**
|
|
27
28
|
* The ref for the element which the overlay positions itself with respect to.
|
|
28
29
|
*/
|
|
29
|
-
targetRef: RefObject<
|
|
30
|
+
targetRef: RefObject<Element>,
|
|
30
31
|
/**
|
|
31
32
|
* The ref for the overlay element.
|
|
32
33
|
*/
|
|
33
|
-
overlayRef: RefObject<
|
|
34
|
+
overlayRef: RefObject<Element>,
|
|
34
35
|
/**
|
|
35
36
|
* A ref for the scrollable region within the overlay.
|
|
36
37
|
* @default overlayRef
|
|
37
38
|
*/
|
|
38
|
-
scrollRef?: RefObject<
|
|
39
|
+
scrollRef?: RefObject<Element>,
|
|
39
40
|
/**
|
|
40
41
|
* Whether the overlay should update its position automatically.
|
|
41
42
|
* @default true
|
|
@@ -52,9 +53,9 @@ interface AriaPositionProps extends PositionProps {
|
|
|
52
53
|
|
|
53
54
|
interface PositionAria {
|
|
54
55
|
/** Props for the overlay container element. */
|
|
55
|
-
overlayProps:
|
|
56
|
+
overlayProps: DOMAttributes,
|
|
56
57
|
/** Props for the overlay tip arrow if any. */
|
|
57
|
-
arrowProps:
|
|
58
|
+
arrowProps: DOMAttributes,
|
|
58
59
|
/** Placement of the overlay with respect to the overlay trigger. */
|
|
59
60
|
placement: PlacementAxis,
|
|
60
61
|
/** Updates the position of the overlay. */
|
package/src/useOverlayTrigger.ts
CHANGED
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {AriaButtonProps} from '@react-types/button';
|
|
14
|
-
import {
|
|
14
|
+
import {DOMAttributes} from '@react-types/shared';
|
|
15
15
|
import {onCloseMap} from './useCloseOnScroll';
|
|
16
16
|
import {OverlayTriggerState} from '@react-stately/overlays';
|
|
17
|
+
import {RefObject, useEffect} from 'react';
|
|
17
18
|
import {useId} from '@react-aria/utils';
|
|
18
19
|
|
|
19
20
|
interface OverlayTriggerProps {
|
|
@@ -26,14 +27,14 @@ interface OverlayTriggerAria {
|
|
|
26
27
|
triggerProps: AriaButtonProps,
|
|
27
28
|
|
|
28
29
|
/** Props for the overlay container element. */
|
|
29
|
-
overlayProps:
|
|
30
|
+
overlayProps: DOMAttributes
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* Handles the behavior and accessibility for an overlay trigger, e.g. a button
|
|
34
35
|
* that opens a popover, menu, or other overlay that is positioned relative to the trigger.
|
|
35
36
|
*/
|
|
36
|
-
export function useOverlayTrigger(props: OverlayTriggerProps, state: OverlayTriggerState, ref: RefObject<
|
|
37
|
+
export function useOverlayTrigger(props: OverlayTriggerProps, state: OverlayTriggerState, ref: RefObject<Element>): OverlayTriggerAria {
|
|
37
38
|
let {type} = props;
|
|
38
39
|
let {isOpen} = state;
|
|
39
40
|
|