@radix-ui/react-dialog 1.0.6-rc.5 → 1.1.0-rc.1
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/index.d.mts +52 -40
- package/dist/index.d.ts +52 -40
- package/dist/index.js +324 -363
- package/dist/index.js.map +7 -1
- package/dist/index.mjs +309 -336
- package/dist/index.mjs.map +7 -1
- package/package.json +13 -14
- package/dist/index.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,389 +1,350 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
+
}) : x)(function(x) {
|
|
12
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
+
});
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
17
31
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
/* -------------------------------------------------------------------------------------------------
|
|
60
|
-
* Dialog
|
|
61
|
-
* -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$DIALOG_NAME = 'Dialog';
|
|
62
|
-
const [$f4833395aa1bca1a$var$createDialogContext, $f4833395aa1bca1a$export$cc702773b8ea3e41] = $aJCrN$radixuireactcontext.createContextScope($f4833395aa1bca1a$var$DIALOG_NAME);
|
|
63
|
-
const [$f4833395aa1bca1a$var$DialogProvider, $f4833395aa1bca1a$var$useDialogContext] = $f4833395aa1bca1a$var$createDialogContext($f4833395aa1bca1a$var$DIALOG_NAME);
|
|
64
|
-
const $f4833395aa1bca1a$export$3ddf2d174ce01153 = (props)=>{
|
|
65
|
-
const { __scopeDialog: __scopeDialog , children: children , open: openProp , defaultOpen: defaultOpen , onOpenChange: onOpenChange , modal: modal = true } = props;
|
|
66
|
-
const triggerRef = $aJCrN$react.useRef(null);
|
|
67
|
-
const contentRef = $aJCrN$react.useRef(null);
|
|
68
|
-
const [open = false, setOpen] = $aJCrN$radixuireactusecontrollablestate.useControllableState({
|
|
69
|
-
prop: openProp,
|
|
70
|
-
defaultProp: defaultOpen,
|
|
71
|
-
onChange: onOpenChange
|
|
32
|
+
// packages/react/dialog/src/Dialog.tsx
|
|
33
|
+
var React = __toESM(__require("react"));
|
|
34
|
+
var import_primitive = __require("@radix-ui/primitive");
|
|
35
|
+
var import_react_compose_refs = __require("@radix-ui/react-compose-refs");
|
|
36
|
+
var import_react_context = __require("@radix-ui/react-context");
|
|
37
|
+
var import_react_id = __require("@radix-ui/react-id");
|
|
38
|
+
var import_react_use_controllable_state = __require("@radix-ui/react-use-controllable-state");
|
|
39
|
+
var import_react_dismissable_layer = __require("@radix-ui/react-dismissable-layer");
|
|
40
|
+
var import_react_focus_scope = __require("@radix-ui/react-focus-scope");
|
|
41
|
+
var import_react_portal = __require("@radix-ui/react-portal");
|
|
42
|
+
var import_react_presence = __require("@radix-ui/react-presence");
|
|
43
|
+
var import_react_primitive = __require("@radix-ui/react-primitive");
|
|
44
|
+
var import_react_focus_guards = __require("@radix-ui/react-focus-guards");
|
|
45
|
+
var import_react_remove_scroll = __require("react-remove-scroll");
|
|
46
|
+
var import_aria_hidden = __require("aria-hidden");
|
|
47
|
+
var import_react_slot = __require("@radix-ui/react-slot");
|
|
48
|
+
var import_jsx_runtime = __require("react/jsx-runtime");
|
|
49
|
+
var DIALOG_NAME = "Dialog";
|
|
50
|
+
var [createDialogContext, createDialogScope] = (0, import_react_context.createContextScope)(DIALOG_NAME);
|
|
51
|
+
var [DialogProvider, useDialogContext] = createDialogContext(DIALOG_NAME);
|
|
52
|
+
var Dialog = (props) => {
|
|
53
|
+
const {
|
|
54
|
+
__scopeDialog,
|
|
55
|
+
children,
|
|
56
|
+
open: openProp,
|
|
57
|
+
defaultOpen,
|
|
58
|
+
onOpenChange,
|
|
59
|
+
modal = true
|
|
60
|
+
} = props;
|
|
61
|
+
const triggerRef = React.useRef(null);
|
|
62
|
+
const contentRef = React.useRef(null);
|
|
63
|
+
const [open = false, setOpen] = (0, import_react_use_controllable_state.useControllableState)({
|
|
64
|
+
prop: openProp,
|
|
65
|
+
defaultProp: defaultOpen,
|
|
66
|
+
onChange: onOpenChange
|
|
72
67
|
});
|
|
73
|
-
return
|
|
68
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
69
|
+
DialogProvider,
|
|
70
|
+
{
|
|
74
71
|
scope: __scopeDialog,
|
|
75
|
-
triggerRef
|
|
76
|
-
contentRef
|
|
77
|
-
contentId:
|
|
78
|
-
titleId:
|
|
79
|
-
descriptionId:
|
|
80
|
-
open
|
|
72
|
+
triggerRef,
|
|
73
|
+
contentRef,
|
|
74
|
+
contentId: (0, import_react_id.useId)(),
|
|
75
|
+
titleId: (0, import_react_id.useId)(),
|
|
76
|
+
descriptionId: (0, import_react_id.useId)(),
|
|
77
|
+
open,
|
|
81
78
|
onOpenChange: setOpen,
|
|
82
|
-
onOpenToggle:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}, triggerProps, {
|
|
107
|
-
ref: composedTriggerRef,
|
|
108
|
-
onClick: $aJCrN$radixuiprimitive.composeEventHandlers(props.onClick, context.onOpenToggle)
|
|
109
|
-
}));
|
|
110
|
-
});
|
|
111
|
-
/*#__PURE__*/ Object.assign($f4833395aa1bca1a$export$2e1e1122cf0cba88, {
|
|
112
|
-
displayName: $f4833395aa1bca1a$var$TRIGGER_NAME
|
|
113
|
-
});
|
|
114
|
-
/* -------------------------------------------------------------------------------------------------
|
|
115
|
-
* DialogPortal
|
|
116
|
-
* -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$PORTAL_NAME = 'DialogPortal';
|
|
117
|
-
const [$f4833395aa1bca1a$var$PortalProvider, $f4833395aa1bca1a$var$usePortalContext] = $f4833395aa1bca1a$var$createDialogContext($f4833395aa1bca1a$var$PORTAL_NAME, {
|
|
118
|
-
forceMount: undefined
|
|
119
|
-
});
|
|
120
|
-
const $f4833395aa1bca1a$export$dad7c95542bacce0 = (props)=>{
|
|
121
|
-
const { __scopeDialog: __scopeDialog , forceMount: forceMount , children: children , container: container } = props;
|
|
122
|
-
const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$PORTAL_NAME, __scopeDialog);
|
|
123
|
-
return /*#__PURE__*/ $aJCrN$react.createElement($f4833395aa1bca1a$var$PortalProvider, {
|
|
124
|
-
scope: __scopeDialog,
|
|
125
|
-
forceMount: forceMount
|
|
126
|
-
}, $aJCrN$react.Children.map(children, (child)=>/*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactpresence.Presence, {
|
|
127
|
-
present: forceMount || context.open
|
|
128
|
-
}, /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactportal.Portal, {
|
|
129
|
-
asChild: true,
|
|
130
|
-
container: container
|
|
131
|
-
}, child))
|
|
132
|
-
));
|
|
133
|
-
};
|
|
134
|
-
/*#__PURE__*/ Object.assign($f4833395aa1bca1a$export$dad7c95542bacce0, {
|
|
135
|
-
displayName: $f4833395aa1bca1a$var$PORTAL_NAME
|
|
136
|
-
});
|
|
137
|
-
/* -------------------------------------------------------------------------------------------------
|
|
138
|
-
* DialogOverlay
|
|
139
|
-
* -----------------------------------------------------------------------------------------------*/ const $f4833395aa1bca1a$var$OVERLAY_NAME = 'DialogOverlay';
|
|
140
|
-
const $f4833395aa1bca1a$export$bd1d06c79be19e17 = /*#__PURE__*/ $aJCrN$react.forwardRef((props, forwardedRef)=>{
|
|
141
|
-
const portalContext = $f4833395aa1bca1a$var$usePortalContext($f4833395aa1bca1a$var$OVERLAY_NAME, props.__scopeDialog);
|
|
142
|
-
const { forceMount: forceMount = portalContext.forceMount , ...overlayProps } = props;
|
|
143
|
-
const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$OVERLAY_NAME, props.__scopeDialog);
|
|
144
|
-
return context.modal ? /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactpresence.Presence, {
|
|
145
|
-
present: forceMount || context.open
|
|
146
|
-
}, /*#__PURE__*/ $aJCrN$react.createElement($f4833395aa1bca1a$var$DialogOverlayImpl, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({}, overlayProps, {
|
|
147
|
-
ref: forwardedRef
|
|
148
|
-
}))) : null;
|
|
149
|
-
});
|
|
150
|
-
/*#__PURE__*/ Object.assign($f4833395aa1bca1a$export$bd1d06c79be19e17, {
|
|
151
|
-
displayName: $f4833395aa1bca1a$var$OVERLAY_NAME
|
|
152
|
-
});
|
|
153
|
-
const $f4833395aa1bca1a$var$DialogOverlayImpl = /*#__PURE__*/ $aJCrN$react.forwardRef((props, forwardedRef)=>{
|
|
154
|
-
const { __scopeDialog: __scopeDialog , ...overlayProps } = props;
|
|
155
|
-
const context = $f4833395aa1bca1a$var$useDialogContext($f4833395aa1bca1a$var$OVERLAY_NAME, __scopeDialog);
|
|
156
|
-
return(/*#__PURE__*/ // Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
|
|
157
|
-
// ie. when `Overlay` and `Content` are siblings
|
|
158
|
-
$aJCrN$react.createElement($aJCrN$reactremovescroll.RemoveScroll, {
|
|
159
|
-
as: $aJCrN$radixuireactslot.Slot,
|
|
160
|
-
allowPinchZoom: true,
|
|
161
|
-
shards: [
|
|
162
|
-
context.contentRef
|
|
163
|
-
]
|
|
164
|
-
}, /*#__PURE__*/ $aJCrN$react.createElement($aJCrN$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($aJCrN$babelruntimehelpersextends))({
|
|
165
|
-
"data-state": $f4833395aa1bca1a$var$getState(context.open)
|
|
166
|
-
}, overlayProps, {
|
|
167
|
-
ref: forwardedRef // We re-enable pointer-events prevented by `Dialog.Content` to allow scrolling the overlay.
|
|
168
|
-
,
|
|
169
|
-
style: {
|
|
170
|
-
pointerEvents: 'auto',
|
|
171
|
-
...overlayProps.style
|
|
79
|
+
onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]),
|
|
80
|
+
modal,
|
|
81
|
+
children
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
Dialog.displayName = DIALOG_NAME;
|
|
86
|
+
var TRIGGER_NAME = "DialogTrigger";
|
|
87
|
+
var DialogTrigger = React.forwardRef(
|
|
88
|
+
(props, forwardedRef) => {
|
|
89
|
+
const { __scopeDialog, ...triggerProps } = props;
|
|
90
|
+
const context = useDialogContext(TRIGGER_NAME, __scopeDialog);
|
|
91
|
+
const composedTriggerRef = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, context.triggerRef);
|
|
92
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
93
|
+
import_react_primitive.Primitive.button,
|
|
94
|
+
{
|
|
95
|
+
type: "button",
|
|
96
|
+
"aria-haspopup": "dialog",
|
|
97
|
+
"aria-expanded": context.open,
|
|
98
|
+
"aria-controls": context.contentId,
|
|
99
|
+
"data-state": getState(context.open),
|
|
100
|
+
...triggerProps,
|
|
101
|
+
ref: composedTriggerRef,
|
|
102
|
+
onClick: (0, import_primitive.composeEventHandlers)(props.onClick, context.onOpenToggle)
|
|
172
103
|
}
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
/*
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
DialogTrigger.displayName = TRIGGER_NAME;
|
|
108
|
+
var PORTAL_NAME = "DialogPortal";
|
|
109
|
+
var [PortalProvider, usePortalContext] = createDialogContext(PORTAL_NAME, {
|
|
110
|
+
forceMount: void 0
|
|
111
|
+
});
|
|
112
|
+
var DialogPortal = (props) => {
|
|
113
|
+
const { __scopeDialog, forceMount, children, container } = props;
|
|
114
|
+
const context = useDialogContext(PORTAL_NAME, __scopeDialog);
|
|
115
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PortalProvider, { scope: __scopeDialog, forceMount, children: React.Children.map(children, (child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_presence.Presence, { present: forceMount || context.open, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_portal.Portal, { asChild: true, container, children: child }) })) });
|
|
116
|
+
};
|
|
117
|
+
DialogPortal.displayName = PORTAL_NAME;
|
|
118
|
+
var OVERLAY_NAME = "DialogOverlay";
|
|
119
|
+
var DialogOverlay = React.forwardRef(
|
|
120
|
+
(props, forwardedRef) => {
|
|
121
|
+
const portalContext = usePortalContext(OVERLAY_NAME, props.__scopeDialog);
|
|
122
|
+
const { forceMount = portalContext.forceMount, ...overlayProps } = props;
|
|
123
|
+
const context = useDialogContext(OVERLAY_NAME, props.__scopeDialog);
|
|
124
|
+
return context.modal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_presence.Presence, { present: forceMount || context.open, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogOverlayImpl, { ...overlayProps, ref: forwardedRef }) }) : null;
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
DialogOverlay.displayName = OVERLAY_NAME;
|
|
128
|
+
var DialogOverlayImpl = React.forwardRef(
|
|
129
|
+
(props, forwardedRef) => {
|
|
130
|
+
const { __scopeDialog, ...overlayProps } = props;
|
|
131
|
+
const context = useDialogContext(OVERLAY_NAME, __scopeDialog);
|
|
132
|
+
return (
|
|
133
|
+
// Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
|
|
134
|
+
// ie. when `Overlay` and `Content` are siblings
|
|
135
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_remove_scroll.RemoveScroll, { as: import_react_slot.Slot, allowPinchZoom: true, shards: [context.contentRef], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
136
|
+
import_react_primitive.Primitive.div,
|
|
137
|
+
{
|
|
138
|
+
"data-state": getState(context.open),
|
|
139
|
+
...overlayProps,
|
|
140
|
+
ref: forwardedRef,
|
|
141
|
+
style: { pointerEvents: "auto", ...overlayProps.style }
|
|
142
|
+
}
|
|
143
|
+
) })
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
var CONTENT_NAME = "DialogContent";
|
|
148
|
+
var DialogContent = React.forwardRef(
|
|
149
|
+
(props, forwardedRef) => {
|
|
150
|
+
const portalContext = usePortalContext(CONTENT_NAME, props.__scopeDialog);
|
|
151
|
+
const { forceMount = portalContext.forceMount, ...contentProps } = props;
|
|
152
|
+
const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
|
|
153
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_presence.Presence, { present: forceMount || context.open, children: context.modal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentModal, { ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogContentNonModal, { ...contentProps, ref: forwardedRef }) });
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
DialogContent.displayName = CONTENT_NAME;
|
|
157
|
+
var DialogContentModal = React.forwardRef(
|
|
158
|
+
(props, forwardedRef) => {
|
|
159
|
+
const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
|
|
160
|
+
const contentRef = React.useRef(null);
|
|
161
|
+
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, context.contentRef, contentRef);
|
|
162
|
+
React.useEffect(() => {
|
|
198
163
|
const content = contentRef.current;
|
|
199
|
-
if (content) return
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
164
|
+
if (content) return (0, import_aria_hidden.hideOthers)(content);
|
|
165
|
+
}, []);
|
|
166
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
167
|
+
DialogContentImpl,
|
|
168
|
+
{
|
|
169
|
+
...props,
|
|
170
|
+
ref: composedRefs,
|
|
171
|
+
trapFocus: context.open,
|
|
172
|
+
disableOutsidePointerEvents: true,
|
|
173
|
+
onCloseAutoFocus: (0, import_primitive.composeEventHandlers)(props.onCloseAutoFocus, (event) => {
|
|
208
174
|
event.preventDefault();
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
175
|
+
context.triggerRef.current?.focus();
|
|
176
|
+
}),
|
|
177
|
+
onPointerDownOutside: (0, import_primitive.composeEventHandlers)(props.onPointerDownOutside, (event) => {
|
|
212
178
|
const originalEvent = event.detail.originalEvent;
|
|
213
179
|
const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
214
|
-
const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
215
|
-
// it is effectively as if we right-clicked the `Overlay`.
|
|
180
|
+
const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
216
181
|
if (isRightClick) event.preventDefault();
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
182
|
+
}),
|
|
183
|
+
onFocusOutside: (0, import_primitive.composeEventHandlers)(
|
|
184
|
+
props.onFocusOutside,
|
|
185
|
+
(event) => event.preventDefault()
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
var DialogContentNonModal = React.forwardRef(
|
|
192
|
+
(props, forwardedRef) => {
|
|
193
|
+
const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
|
|
194
|
+
const hasInteractedOutsideRef = React.useRef(false);
|
|
195
|
+
const hasPointerDownOutsideRef = React.useRef(false);
|
|
196
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
197
|
+
DialogContentImpl,
|
|
198
|
+
{
|
|
199
|
+
...props,
|
|
200
|
+
ref: forwardedRef,
|
|
201
|
+
trapFocus: false,
|
|
202
|
+
disableOutsidePointerEvents: false,
|
|
203
|
+
onCloseAutoFocus: (event) => {
|
|
204
|
+
props.onCloseAutoFocus?.(event);
|
|
234
205
|
if (!event.defaultPrevented) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
event.preventDefault();
|
|
206
|
+
if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();
|
|
207
|
+
event.preventDefault();
|
|
238
208
|
}
|
|
239
209
|
hasInteractedOutsideRef.current = false;
|
|
240
210
|
hasPointerDownOutsideRef.current = false;
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
(_props$onInteractOuts = props.onInteractOutside) === null || _props$onInteractOuts === void 0 || _props$onInteractOuts.call(props, event);
|
|
211
|
+
},
|
|
212
|
+
onInteractOutside: (event) => {
|
|
213
|
+
props.onInteractOutside?.(event);
|
|
245
214
|
if (!event.defaultPrevented) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
215
|
+
hasInteractedOutsideRef.current = true;
|
|
216
|
+
if (event.detail.originalEvent.type === "pointerdown") {
|
|
217
|
+
hasPointerDownOutsideRef.current = true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
251
220
|
const target = event.target;
|
|
252
|
-
const targetIsTrigger =
|
|
253
|
-
if (targetIsTrigger) event.preventDefault();
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
221
|
+
const targetIsTrigger = context.triggerRef.current?.contains(target);
|
|
222
|
+
if (targetIsTrigger) event.preventDefault();
|
|
223
|
+
if (event.detail.originalEvent.type === "focusin" && hasPointerDownOutsideRef.current) {
|
|
224
|
+
event.preventDefault();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
258
227
|
}
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
var DialogContentImpl = React.forwardRef(
|
|
232
|
+
(props, forwardedRef) => {
|
|
233
|
+
const { __scopeDialog, trapFocus, onOpenAutoFocus, onCloseAutoFocus, ...contentProps } = props;
|
|
234
|
+
const context = useDialogContext(CONTENT_NAME, __scopeDialog);
|
|
235
|
+
const contentRef = React.useRef(null);
|
|
236
|
+
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, contentRef);
|
|
237
|
+
(0, import_react_focus_guards.useFocusGuards)();
|
|
238
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
239
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
240
|
+
import_react_focus_scope.FocusScope,
|
|
241
|
+
{
|
|
242
|
+
asChild: true,
|
|
243
|
+
loop: true,
|
|
244
|
+
trapped: trapFocus,
|
|
245
|
+
onMountAutoFocus: onOpenAutoFocus,
|
|
246
|
+
onUnmountAutoFocus: onCloseAutoFocus,
|
|
247
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
248
|
+
import_react_dismissable_layer.DismissableLayer,
|
|
249
|
+
{
|
|
250
|
+
role: "dialog",
|
|
251
|
+
id: context.contentId,
|
|
252
|
+
"aria-describedby": context.descriptionId,
|
|
253
|
+
"aria-labelledby": context.titleId,
|
|
254
|
+
"data-state": getState(context.open),
|
|
255
|
+
...contentProps,
|
|
256
|
+
ref: composedRefs,
|
|
257
|
+
onDismiss: () => context.onOpenChange(false)
|
|
258
|
+
}
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
),
|
|
262
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
263
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TitleWarning, { titleId: context.titleId }),
|
|
264
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescriptionWarning, { contentRef, descriptionId: context.descriptionId })
|
|
265
|
+
] })
|
|
266
|
+
] });
|
|
267
|
+
}
|
|
268
|
+
);
|
|
269
|
+
var TITLE_NAME = "DialogTitle";
|
|
270
|
+
var DialogTitle = React.forwardRef(
|
|
271
|
+
(props, forwardedRef) => {
|
|
272
|
+
const { __scopeDialog, ...titleProps } = props;
|
|
273
|
+
const context = useDialogContext(TITLE_NAME, __scopeDialog);
|
|
274
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.h2, { id: context.titleId, ...titleProps, ref: forwardedRef });
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
DialogTitle.displayName = TITLE_NAME;
|
|
278
|
+
var DESCRIPTION_NAME = "DialogDescription";
|
|
279
|
+
var DialogDescription = React.forwardRef(
|
|
280
|
+
(props, forwardedRef) => {
|
|
281
|
+
const { __scopeDialog, ...descriptionProps } = props;
|
|
282
|
+
const context = useDialogContext(DESCRIPTION_NAME, __scopeDialog);
|
|
283
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.p, { id: context.descriptionId, ...descriptionProps, ref: forwardedRef });
|
|
284
|
+
}
|
|
285
|
+
);
|
|
286
|
+
DialogDescription.displayName = DESCRIPTION_NAME;
|
|
287
|
+
var CLOSE_NAME = "DialogClose";
|
|
288
|
+
var DialogClose = React.forwardRef(
|
|
289
|
+
(props, forwardedRef) => {
|
|
290
|
+
const { __scopeDialog, ...closeProps } = props;
|
|
291
|
+
const context = useDialogContext(CLOSE_NAME, __scopeDialog);
|
|
292
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
293
|
+
import_react_primitive.Primitive.button,
|
|
294
|
+
{
|
|
295
|
+
type: "button",
|
|
296
|
+
...closeProps,
|
|
297
|
+
ref: forwardedRef,
|
|
298
|
+
onClick: (0, import_primitive.composeEventHandlers)(props.onClick, () => context.onOpenChange(false))
|
|
299
|
+
}
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
);
|
|
303
|
+
DialogClose.displayName = CLOSE_NAME;
|
|
304
|
+
function getState(open) {
|
|
305
|
+
return open ? "open" : "closed";
|
|
306
|
+
}
|
|
307
|
+
var TITLE_WARNING_NAME = "DialogTitleWarning";
|
|
308
|
+
var [WarningProvider, useWarningContext] = (0, import_react_context.createContext)(TITLE_WARNING_NAME, {
|
|
309
|
+
contentName: CONTENT_NAME,
|
|
310
|
+
titleName: TITLE_NAME,
|
|
311
|
+
docsSlug: "dialog"
|
|
312
|
+
});
|
|
313
|
+
var TitleWarning = ({ titleId }) => {
|
|
314
|
+
const titleWarningContext = useWarningContext(TITLE_WARNING_NAME);
|
|
343
315
|
const MESSAGE = `\`${titleWarningContext.contentName}\` requires a \`${titleWarningContext.titleName}\` for the component to be accessible for screen reader users.
|
|
344
316
|
|
|
345
317
|
If you want to hide the \`${titleWarningContext.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
346
318
|
|
|
347
319
|
For more information, see https://radix-ui.com/primitives/docs/components/${titleWarningContext.docsSlug}`;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}, [
|
|
354
|
-
MESSAGE,
|
|
355
|
-
titleId
|
|
356
|
-
]);
|
|
320
|
+
React.useEffect(() => {
|
|
321
|
+
if (titleId) {
|
|
322
|
+
const hasTitle = document.getElementById(titleId);
|
|
323
|
+
if (!hasTitle) throw new Error(MESSAGE);
|
|
324
|
+
}
|
|
325
|
+
}, [MESSAGE, titleId]);
|
|
357
326
|
return null;
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
const descriptionWarningContext =
|
|
327
|
+
};
|
|
328
|
+
var DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning";
|
|
329
|
+
var DescriptionWarning = ({ contentRef, descriptionId }) => {
|
|
330
|
+
const descriptionWarningContext = useWarningContext(DESCRIPTION_WARNING_NAME);
|
|
362
331
|
const MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${descriptionWarningContext.contentName}}.`;
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}, [
|
|
371
|
-
MESSAGE,
|
|
372
|
-
contentRef,
|
|
373
|
-
descriptionId
|
|
374
|
-
]);
|
|
332
|
+
React.useEffect(() => {
|
|
333
|
+
const describedById = contentRef.current?.getAttribute("aria-describedby");
|
|
334
|
+
if (descriptionId && describedById) {
|
|
335
|
+
const hasDescription = document.getElementById(descriptionId);
|
|
336
|
+
if (!hasDescription) console.warn(MESSAGE);
|
|
337
|
+
}
|
|
338
|
+
}, [MESSAGE, contentRef, descriptionId]);
|
|
375
339
|
return null;
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
340
|
+
};
|
|
341
|
+
var Root = Dialog;
|
|
342
|
+
var Trigger = DialogTrigger;
|
|
343
|
+
var Portal = DialogPortal;
|
|
344
|
+
var Overlay = DialogOverlay;
|
|
345
|
+
var Content = DialogContent;
|
|
346
|
+
var Title = DialogTitle;
|
|
347
|
+
var Description = DialogDescription;
|
|
348
|
+
var Close = DialogClose;
|
|
349
|
+
})();
|
|
389
350
|
//# sourceMappingURL=index.js.map
|