@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.mjs CHANGED
@@ -1,365 +1,338 @@
1
- import $67UHm$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
2
- import {useRef as $67UHm$useRef, createElement as $67UHm$createElement, useCallback as $67UHm$useCallback, forwardRef as $67UHm$forwardRef, Children as $67UHm$Children, useEffect as $67UHm$useEffect, Fragment as $67UHm$Fragment} from "react";
3
- import {composeEventHandlers as $67UHm$composeEventHandlers} from "@radix-ui/primitive";
4
- import {useComposedRefs as $67UHm$useComposedRefs} from "@radix-ui/react-compose-refs";
5
- import {createContextScope as $67UHm$createContextScope, createContext as $67UHm$createContext} from "@radix-ui/react-context";
6
- import {useId as $67UHm$useId} from "@radix-ui/react-id";
7
- import {useControllableState as $67UHm$useControllableState} from "@radix-ui/react-use-controllable-state";
8
- import {DismissableLayer as $67UHm$DismissableLayer} from "@radix-ui/react-dismissable-layer";
9
- import {FocusScope as $67UHm$FocusScope} from "@radix-ui/react-focus-scope";
10
- import {Portal as $67UHm$Portal} from "@radix-ui/react-portal";
11
- import {Presence as $67UHm$Presence} from "@radix-ui/react-presence";
12
- import {Primitive as $67UHm$Primitive} from "@radix-ui/react-primitive";
13
- import {useFocusGuards as $67UHm$useFocusGuards} from "@radix-ui/react-focus-guards";
14
- import {RemoveScroll as $67UHm$RemoveScroll} from "react-remove-scroll";
15
- import {hideOthers as $67UHm$hideOthers} from "aria-hidden";
16
- import {Slot as $67UHm$Slot} from "@radix-ui/react-slot";
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
- /* -------------------------------------------------------------------------------------------------
35
- * Dialog
36
- * -----------------------------------------------------------------------------------------------*/ const $5d3850c4d0b4e6c7$var$DIALOG_NAME = 'Dialog';
37
- const [$5d3850c4d0b4e6c7$var$createDialogContext, $5d3850c4d0b4e6c7$export$cc702773b8ea3e41] = $67UHm$createContextScope($5d3850c4d0b4e6c7$var$DIALOG_NAME);
38
- const [$5d3850c4d0b4e6c7$var$DialogProvider, $5d3850c4d0b4e6c7$var$useDialogContext] = $5d3850c4d0b4e6c7$var$createDialogContext($5d3850c4d0b4e6c7$var$DIALOG_NAME);
39
- const $5d3850c4d0b4e6c7$export$3ddf2d174ce01153 = (props)=>{
40
- const { __scopeDialog: __scopeDialog , children: children , open: openProp , defaultOpen: defaultOpen , onOpenChange: onOpenChange , modal: modal = true } = props;
41
- const triggerRef = $67UHm$useRef(null);
42
- const contentRef = $67UHm$useRef(null);
43
- const [open = false, setOpen] = $67UHm$useControllableState({
44
- prop: openProp,
45
- defaultProp: defaultOpen,
46
- onChange: onOpenChange
47
- });
48
- return /*#__PURE__*/ $67UHm$createElement($5d3850c4d0b4e6c7$var$DialogProvider, {
49
- scope: __scopeDialog,
50
- triggerRef: triggerRef,
51
- contentRef: contentRef,
52
- contentId: $67UHm$useId(),
53
- titleId: $67UHm$useId(),
54
- descriptionId: $67UHm$useId(),
55
- open: open,
56
- onOpenChange: setOpen,
57
- onOpenToggle: $67UHm$useCallback(()=>setOpen((prevOpen)=>!prevOpen
58
- )
59
- , [
60
- setOpen
61
- ]),
62
- modal: modal
63
- }, children);
1
+ // packages/react/dialog/src/Dialog.tsx
2
+ import * as React from "react";
3
+ import { composeEventHandlers } from "@radix-ui/primitive";
4
+ import { useComposedRefs } from "@radix-ui/react-compose-refs";
5
+ import { createContext, createContextScope } from "@radix-ui/react-context";
6
+ import { useId } from "@radix-ui/react-id";
7
+ import { useControllableState } from "@radix-ui/react-use-controllable-state";
8
+ import { DismissableLayer } from "@radix-ui/react-dismissable-layer";
9
+ import { FocusScope } from "@radix-ui/react-focus-scope";
10
+ import { Portal as PortalPrimitive } from "@radix-ui/react-portal";
11
+ import { Presence } from "@radix-ui/react-presence";
12
+ import { Primitive } from "@radix-ui/react-primitive";
13
+ import { useFocusGuards } from "@radix-ui/react-focus-guards";
14
+ import { RemoveScroll } from "react-remove-scroll";
15
+ import { hideOthers } from "aria-hidden";
16
+ import { Slot } from "@radix-ui/react-slot";
17
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
18
+ var DIALOG_NAME = "Dialog";
19
+ var [createDialogContext, createDialogScope] = createContextScope(DIALOG_NAME);
20
+ var [DialogProvider, useDialogContext] = createDialogContext(DIALOG_NAME);
21
+ var Dialog = (props) => {
22
+ const {
23
+ __scopeDialog,
24
+ children,
25
+ open: openProp,
26
+ defaultOpen,
27
+ onOpenChange,
28
+ modal = true
29
+ } = props;
30
+ const triggerRef = React.useRef(null);
31
+ const contentRef = React.useRef(null);
32
+ const [open = false, setOpen] = useControllableState({
33
+ prop: openProp,
34
+ defaultProp: defaultOpen,
35
+ onChange: onOpenChange
36
+ });
37
+ return /* @__PURE__ */ jsx(
38
+ DialogProvider,
39
+ {
40
+ scope: __scopeDialog,
41
+ triggerRef,
42
+ contentRef,
43
+ contentId: useId(),
44
+ titleId: useId(),
45
+ descriptionId: useId(),
46
+ open,
47
+ onOpenChange: setOpen,
48
+ onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]),
49
+ modal,
50
+ children
51
+ }
52
+ );
64
53
  };
65
- /*#__PURE__*/ Object.assign($5d3850c4d0b4e6c7$export$3ddf2d174ce01153, {
66
- displayName: $5d3850c4d0b4e6c7$var$DIALOG_NAME
67
- });
68
- /* -------------------------------------------------------------------------------------------------
69
- * DialogTrigger
70
- * -----------------------------------------------------------------------------------------------*/ const $5d3850c4d0b4e6c7$var$TRIGGER_NAME = 'DialogTrigger';
71
- const $5d3850c4d0b4e6c7$export$2e1e1122cf0cba88 = /*#__PURE__*/ $67UHm$forwardRef((props, forwardedRef)=>{
72
- const { __scopeDialog: __scopeDialog , ...triggerProps } = props;
73
- const context = $5d3850c4d0b4e6c7$var$useDialogContext($5d3850c4d0b4e6c7$var$TRIGGER_NAME, __scopeDialog);
74
- const composedTriggerRef = $67UHm$useComposedRefs(forwardedRef, context.triggerRef);
75
- return /*#__PURE__*/ $67UHm$createElement($67UHm$Primitive.button, $67UHm$babelruntimehelpersesmextends({
54
+ Dialog.displayName = DIALOG_NAME;
55
+ var TRIGGER_NAME = "DialogTrigger";
56
+ var DialogTrigger = React.forwardRef(
57
+ (props, forwardedRef) => {
58
+ const { __scopeDialog, ...triggerProps } = props;
59
+ const context = useDialogContext(TRIGGER_NAME, __scopeDialog);
60
+ const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);
61
+ return /* @__PURE__ */ jsx(
62
+ Primitive.button,
63
+ {
76
64
  type: "button",
77
65
  "aria-haspopup": "dialog",
78
66
  "aria-expanded": context.open,
79
67
  "aria-controls": context.contentId,
80
- "data-state": $5d3850c4d0b4e6c7$var$getState(context.open)
81
- }, triggerProps, {
68
+ "data-state": getState(context.open),
69
+ ...triggerProps,
82
70
  ref: composedTriggerRef,
83
- onClick: $67UHm$composeEventHandlers(props.onClick, context.onOpenToggle)
84
- }));
71
+ onClick: composeEventHandlers(props.onClick, context.onOpenToggle)
72
+ }
73
+ );
74
+ }
75
+ );
76
+ DialogTrigger.displayName = TRIGGER_NAME;
77
+ var PORTAL_NAME = "DialogPortal";
78
+ var [PortalProvider, usePortalContext] = createDialogContext(PORTAL_NAME, {
79
+ forceMount: void 0
85
80
  });
86
- /*#__PURE__*/ Object.assign($5d3850c4d0b4e6c7$export$2e1e1122cf0cba88, {
87
- displayName: $5d3850c4d0b4e6c7$var$TRIGGER_NAME
88
- });
89
- /* -------------------------------------------------------------------------------------------------
90
- * DialogPortal
91
- * -----------------------------------------------------------------------------------------------*/ const $5d3850c4d0b4e6c7$var$PORTAL_NAME = 'DialogPortal';
92
- const [$5d3850c4d0b4e6c7$var$PortalProvider, $5d3850c4d0b4e6c7$var$usePortalContext] = $5d3850c4d0b4e6c7$var$createDialogContext($5d3850c4d0b4e6c7$var$PORTAL_NAME, {
93
- forceMount: undefined
94
- });
95
- const $5d3850c4d0b4e6c7$export$dad7c95542bacce0 = (props)=>{
96
- const { __scopeDialog: __scopeDialog , forceMount: forceMount , children: children , container: container } = props;
97
- const context = $5d3850c4d0b4e6c7$var$useDialogContext($5d3850c4d0b4e6c7$var$PORTAL_NAME, __scopeDialog);
98
- return /*#__PURE__*/ $67UHm$createElement($5d3850c4d0b4e6c7$var$PortalProvider, {
99
- scope: __scopeDialog,
100
- forceMount: forceMount
101
- }, $67UHm$Children.map(children, (child)=>/*#__PURE__*/ $67UHm$createElement($67UHm$Presence, {
102
- present: forceMount || context.open
103
- }, /*#__PURE__*/ $67UHm$createElement($67UHm$Portal, {
104
- asChild: true,
105
- container: container
106
- }, child))
107
- ));
81
+ var DialogPortal = (props) => {
82
+ const { __scopeDialog, forceMount, children, container } = props;
83
+ const context = useDialogContext(PORTAL_NAME, __scopeDialog);
84
+ return /* @__PURE__ */ jsx(PortalProvider, { scope: __scopeDialog, forceMount, children: React.Children.map(children, (child) => /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: /* @__PURE__ */ jsx(PortalPrimitive, { asChild: true, container, children: child }) })) });
108
85
  };
109
- /*#__PURE__*/ Object.assign($5d3850c4d0b4e6c7$export$dad7c95542bacce0, {
110
- displayName: $5d3850c4d0b4e6c7$var$PORTAL_NAME
111
- });
112
- /* -------------------------------------------------------------------------------------------------
113
- * DialogOverlay
114
- * -----------------------------------------------------------------------------------------------*/ const $5d3850c4d0b4e6c7$var$OVERLAY_NAME = 'DialogOverlay';
115
- const $5d3850c4d0b4e6c7$export$bd1d06c79be19e17 = /*#__PURE__*/ $67UHm$forwardRef((props, forwardedRef)=>{
116
- const portalContext = $5d3850c4d0b4e6c7$var$usePortalContext($5d3850c4d0b4e6c7$var$OVERLAY_NAME, props.__scopeDialog);
117
- const { forceMount: forceMount = portalContext.forceMount , ...overlayProps } = props;
118
- const context = $5d3850c4d0b4e6c7$var$useDialogContext($5d3850c4d0b4e6c7$var$OVERLAY_NAME, props.__scopeDialog);
119
- return context.modal ? /*#__PURE__*/ $67UHm$createElement($67UHm$Presence, {
120
- present: forceMount || context.open
121
- }, /*#__PURE__*/ $67UHm$createElement($5d3850c4d0b4e6c7$var$DialogOverlayImpl, $67UHm$babelruntimehelpersesmextends({}, overlayProps, {
122
- ref: forwardedRef
123
- }))) : null;
124
- });
125
- /*#__PURE__*/ Object.assign($5d3850c4d0b4e6c7$export$bd1d06c79be19e17, {
126
- displayName: $5d3850c4d0b4e6c7$var$OVERLAY_NAME
127
- });
128
- const $5d3850c4d0b4e6c7$var$DialogOverlayImpl = /*#__PURE__*/ $67UHm$forwardRef((props, forwardedRef)=>{
129
- const { __scopeDialog: __scopeDialog , ...overlayProps } = props;
130
- const context = $5d3850c4d0b4e6c7$var$useDialogContext($5d3850c4d0b4e6c7$var$OVERLAY_NAME, __scopeDialog);
131
- return(/*#__PURE__*/ // Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
132
- // ie. when `Overlay` and `Content` are siblings
133
- $67UHm$createElement($67UHm$RemoveScroll, {
134
- as: $67UHm$Slot,
135
- allowPinchZoom: true,
136
- shards: [
137
- context.contentRef
138
- ]
139
- }, /*#__PURE__*/ $67UHm$createElement($67UHm$Primitive.div, $67UHm$babelruntimehelpersesmextends({
140
- "data-state": $5d3850c4d0b4e6c7$var$getState(context.open)
141
- }, overlayProps, {
142
- ref: forwardedRef // We re-enable pointer-events prevented by `Dialog.Content` to allow scrolling the overlay.
143
- ,
144
- style: {
145
- pointerEvents: 'auto',
146
- ...overlayProps.style
86
+ DialogPortal.displayName = PORTAL_NAME;
87
+ var OVERLAY_NAME = "DialogOverlay";
88
+ var DialogOverlay = React.forwardRef(
89
+ (props, forwardedRef) => {
90
+ const portalContext = usePortalContext(OVERLAY_NAME, props.__scopeDialog);
91
+ const { forceMount = portalContext.forceMount, ...overlayProps } = props;
92
+ const context = useDialogContext(OVERLAY_NAME, props.__scopeDialog);
93
+ return context.modal ? /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: /* @__PURE__ */ jsx(DialogOverlayImpl, { ...overlayProps, ref: forwardedRef }) }) : null;
94
+ }
95
+ );
96
+ DialogOverlay.displayName = OVERLAY_NAME;
97
+ var DialogOverlayImpl = React.forwardRef(
98
+ (props, forwardedRef) => {
99
+ const { __scopeDialog, ...overlayProps } = props;
100
+ const context = useDialogContext(OVERLAY_NAME, __scopeDialog);
101
+ return (
102
+ // Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
103
+ // ie. when `Overlay` and `Content` are siblings
104
+ /* @__PURE__ */ jsx(RemoveScroll, { as: Slot, allowPinchZoom: true, shards: [context.contentRef], children: /* @__PURE__ */ jsx(
105
+ Primitive.div,
106
+ {
107
+ "data-state": getState(context.open),
108
+ ...overlayProps,
109
+ ref: forwardedRef,
110
+ style: { pointerEvents: "auto", ...overlayProps.style }
147
111
  }
148
- }))));
149
- });
150
- /* -------------------------------------------------------------------------------------------------
151
- * DialogContent
152
- * -----------------------------------------------------------------------------------------------*/ const $5d3850c4d0b4e6c7$var$CONTENT_NAME = 'DialogContent';
153
- const $5d3850c4d0b4e6c7$export$b6d9565de1e068cf = /*#__PURE__*/ $67UHm$forwardRef((props, forwardedRef)=>{
154
- const portalContext = $5d3850c4d0b4e6c7$var$usePortalContext($5d3850c4d0b4e6c7$var$CONTENT_NAME, props.__scopeDialog);
155
- const { forceMount: forceMount = portalContext.forceMount , ...contentProps } = props;
156
- const context = $5d3850c4d0b4e6c7$var$useDialogContext($5d3850c4d0b4e6c7$var$CONTENT_NAME, props.__scopeDialog);
157
- return /*#__PURE__*/ $67UHm$createElement($67UHm$Presence, {
158
- present: forceMount || context.open
159
- }, context.modal ? /*#__PURE__*/ $67UHm$createElement($5d3850c4d0b4e6c7$var$DialogContentModal, $67UHm$babelruntimehelpersesmextends({}, contentProps, {
160
- ref: forwardedRef
161
- })) : /*#__PURE__*/ $67UHm$createElement($5d3850c4d0b4e6c7$var$DialogContentNonModal, $67UHm$babelruntimehelpersesmextends({}, contentProps, {
162
- ref: forwardedRef
163
- })));
164
- });
165
- /*#__PURE__*/ Object.assign($5d3850c4d0b4e6c7$export$b6d9565de1e068cf, {
166
- displayName: $5d3850c4d0b4e6c7$var$CONTENT_NAME
167
- });
168
- /* -----------------------------------------------------------------------------------------------*/ const $5d3850c4d0b4e6c7$var$DialogContentModal = /*#__PURE__*/ $67UHm$forwardRef((props, forwardedRef)=>{
169
- const context = $5d3850c4d0b4e6c7$var$useDialogContext($5d3850c4d0b4e6c7$var$CONTENT_NAME, props.__scopeDialog);
170
- const contentRef = $67UHm$useRef(null);
171
- const composedRefs = $67UHm$useComposedRefs(forwardedRef, context.contentRef, contentRef); // aria-hide everything except the content (better supported equivalent to setting aria-modal)
172
- $67UHm$useEffect(()=>{
173
- const content = contentRef.current;
174
- if (content) return $67UHm$hideOthers(content);
112
+ ) })
113
+ );
114
+ }
115
+ );
116
+ var CONTENT_NAME = "DialogContent";
117
+ var DialogContent = React.forwardRef(
118
+ (props, forwardedRef) => {
119
+ const portalContext = usePortalContext(CONTENT_NAME, props.__scopeDialog);
120
+ const { forceMount = portalContext.forceMount, ...contentProps } = props;
121
+ const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
122
+ return /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: context.modal ? /* @__PURE__ */ jsx(DialogContentModal, { ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ jsx(DialogContentNonModal, { ...contentProps, ref: forwardedRef }) });
123
+ }
124
+ );
125
+ DialogContent.displayName = CONTENT_NAME;
126
+ var DialogContentModal = React.forwardRef(
127
+ (props, forwardedRef) => {
128
+ const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
129
+ const contentRef = React.useRef(null);
130
+ const composedRefs = useComposedRefs(forwardedRef, context.contentRef, contentRef);
131
+ React.useEffect(() => {
132
+ const content = contentRef.current;
133
+ if (content) return hideOthers(content);
175
134
  }, []);
176
- return /*#__PURE__*/ $67UHm$createElement($5d3850c4d0b4e6c7$var$DialogContentImpl, $67UHm$babelruntimehelpersesmextends({}, props, {
177
- ref: composedRefs // we make sure focus isn't trapped once `DialogContent` has been closed
178
- ,
135
+ return /* @__PURE__ */ jsx(
136
+ DialogContentImpl,
137
+ {
138
+ ...props,
139
+ ref: composedRefs,
179
140
  trapFocus: context.open,
180
141
  disableOutsidePointerEvents: true,
181
- onCloseAutoFocus: $67UHm$composeEventHandlers(props.onCloseAutoFocus, (event)=>{
182
- var _context$triggerRef$c;
183
- event.preventDefault();
184
- (_context$triggerRef$c = context.triggerRef.current) === null || _context$triggerRef$c === void 0 || _context$triggerRef$c.focus();
142
+ onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, (event) => {
143
+ event.preventDefault();
144
+ context.triggerRef.current?.focus();
145
+ }),
146
+ onPointerDownOutside: composeEventHandlers(props.onPointerDownOutside, (event) => {
147
+ const originalEvent = event.detail.originalEvent;
148
+ const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
149
+ const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
150
+ if (isRightClick) event.preventDefault();
185
151
  }),
186
- onPointerDownOutside: $67UHm$composeEventHandlers(props.onPointerDownOutside, (event)=>{
187
- const originalEvent = event.detail.originalEvent;
188
- const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
189
- const isRightClick = originalEvent.button === 2 || ctrlLeftClick; // If the event is a right-click, we shouldn't close because
190
- // it is effectively as if we right-clicked the `Overlay`.
191
- if (isRightClick) event.preventDefault();
192
- }) // When focus is trapped, a `focusout` event may still happen.
193
- ,
194
- onFocusOutside: $67UHm$composeEventHandlers(props.onFocusOutside, (event)=>event.preventDefault()
152
+ onFocusOutside: composeEventHandlers(
153
+ props.onFocusOutside,
154
+ (event) => event.preventDefault()
195
155
  )
196
- }));
197
- });
198
- /* -----------------------------------------------------------------------------------------------*/ const $5d3850c4d0b4e6c7$var$DialogContentNonModal = /*#__PURE__*/ $67UHm$forwardRef((props, forwardedRef)=>{
199
- const context = $5d3850c4d0b4e6c7$var$useDialogContext($5d3850c4d0b4e6c7$var$CONTENT_NAME, props.__scopeDialog);
200
- const hasInteractedOutsideRef = $67UHm$useRef(false);
201
- const hasPointerDownOutsideRef = $67UHm$useRef(false);
202
- return /*#__PURE__*/ $67UHm$createElement($5d3850c4d0b4e6c7$var$DialogContentImpl, $67UHm$babelruntimehelpersesmextends({}, props, {
156
+ }
157
+ );
158
+ }
159
+ );
160
+ var DialogContentNonModal = React.forwardRef(
161
+ (props, forwardedRef) => {
162
+ const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
163
+ const hasInteractedOutsideRef = React.useRef(false);
164
+ const hasPointerDownOutsideRef = React.useRef(false);
165
+ return /* @__PURE__ */ jsx(
166
+ DialogContentImpl,
167
+ {
168
+ ...props,
203
169
  ref: forwardedRef,
204
170
  trapFocus: false,
205
171
  disableOutsidePointerEvents: false,
206
- onCloseAutoFocus: (event)=>{
207
- var _props$onCloseAutoFoc;
208
- (_props$onCloseAutoFoc = props.onCloseAutoFocus) === null || _props$onCloseAutoFoc === void 0 || _props$onCloseAutoFoc.call(props, event);
209
- if (!event.defaultPrevented) {
210
- var _context$triggerRef$c2;
211
- if (!hasInteractedOutsideRef.current) (_context$triggerRef$c2 = context.triggerRef.current) === null || _context$triggerRef$c2 === void 0 || _context$triggerRef$c2.focus(); // Always prevent auto focus because we either focus manually or want user agent focus
212
- event.preventDefault();
213
- }
214
- hasInteractedOutsideRef.current = false;
215
- hasPointerDownOutsideRef.current = false;
172
+ onCloseAutoFocus: (event) => {
173
+ props.onCloseAutoFocus?.(event);
174
+ if (!event.defaultPrevented) {
175
+ if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();
176
+ event.preventDefault();
177
+ }
178
+ hasInteractedOutsideRef.current = false;
179
+ hasPointerDownOutsideRef.current = false;
216
180
  },
217
- onInteractOutside: (event)=>{
218
- var _props$onInteractOuts, _context$triggerRef$c3;
219
- (_props$onInteractOuts = props.onInteractOutside) === null || _props$onInteractOuts === void 0 || _props$onInteractOuts.call(props, event);
220
- if (!event.defaultPrevented) {
221
- hasInteractedOutsideRef.current = true;
222
- if (event.detail.originalEvent.type === 'pointerdown') hasPointerDownOutsideRef.current = true;
223
- } // Prevent dismissing when clicking the trigger.
224
- // As the trigger is already setup to close, without doing so would
225
- // cause it to close and immediately open.
226
- const target = event.target;
227
- const targetIsTrigger = (_context$triggerRef$c3 = context.triggerRef.current) === null || _context$triggerRef$c3 === void 0 ? void 0 : _context$triggerRef$c3.contains(target);
228
- if (targetIsTrigger) event.preventDefault(); // On Safari if the trigger is inside a container with tabIndex={0}, when clicked
229
- // we will get the pointer down outside event on the trigger, but then a subsequent
230
- // focus outside event on the container, we ignore any focus outside event when we've
231
- // already had a pointer down outside event.
232
- if (event.detail.originalEvent.type === 'focusin' && hasPointerDownOutsideRef.current) event.preventDefault();
181
+ onInteractOutside: (event) => {
182
+ props.onInteractOutside?.(event);
183
+ if (!event.defaultPrevented) {
184
+ hasInteractedOutsideRef.current = true;
185
+ if (event.detail.originalEvent.type === "pointerdown") {
186
+ hasPointerDownOutsideRef.current = true;
187
+ }
188
+ }
189
+ const target = event.target;
190
+ const targetIsTrigger = context.triggerRef.current?.contains(target);
191
+ if (targetIsTrigger) event.preventDefault();
192
+ if (event.detail.originalEvent.type === "focusin" && hasPointerDownOutsideRef.current) {
193
+ event.preventDefault();
194
+ }
233
195
  }
234
- }));
235
- });
236
- /* -----------------------------------------------------------------------------------------------*/ const $5d3850c4d0b4e6c7$var$DialogContentImpl = /*#__PURE__*/ $67UHm$forwardRef((props, forwardedRef)=>{
237
- const { __scopeDialog: __scopeDialog , trapFocus: trapFocus , onOpenAutoFocus: onOpenAutoFocus , onCloseAutoFocus: onCloseAutoFocus , ...contentProps } = props;
238
- const context = $5d3850c4d0b4e6c7$var$useDialogContext($5d3850c4d0b4e6c7$var$CONTENT_NAME, __scopeDialog);
239
- const contentRef = $67UHm$useRef(null);
240
- const composedRefs = $67UHm$useComposedRefs(forwardedRef, contentRef); // Make sure the whole tree has focus guards as our `Dialog` will be
241
- // the last element in the DOM (beacuse of the `Portal`)
242
- $67UHm$useFocusGuards();
243
- return /*#__PURE__*/ $67UHm$createElement($67UHm$Fragment, null, /*#__PURE__*/ $67UHm$createElement($67UHm$FocusScope, {
244
- asChild: true,
245
- loop: true,
246
- trapped: trapFocus,
247
- onMountAutoFocus: onOpenAutoFocus,
248
- onUnmountAutoFocus: onCloseAutoFocus
249
- }, /*#__PURE__*/ $67UHm$createElement($67UHm$DismissableLayer, $67UHm$babelruntimehelpersesmextends({
250
- role: "dialog",
251
- id: context.contentId,
252
- "aria-describedby": context.descriptionId,
253
- "aria-labelledby": context.titleId,
254
- "data-state": $5d3850c4d0b4e6c7$var$getState(context.open)
255
- }, contentProps, {
256
- ref: composedRefs,
257
- onDismiss: ()=>context.onOpenChange(false)
258
- }))), false);
259
- });
260
- /* -------------------------------------------------------------------------------------------------
261
- * DialogTitle
262
- * -----------------------------------------------------------------------------------------------*/ const $5d3850c4d0b4e6c7$var$TITLE_NAME = 'DialogTitle';
263
- const $5d3850c4d0b4e6c7$export$16f7638e4a34b909 = /*#__PURE__*/ $67UHm$forwardRef((props, forwardedRef)=>{
264
- const { __scopeDialog: __scopeDialog , ...titleProps } = props;
265
- const context = $5d3850c4d0b4e6c7$var$useDialogContext($5d3850c4d0b4e6c7$var$TITLE_NAME, __scopeDialog);
266
- return /*#__PURE__*/ $67UHm$createElement($67UHm$Primitive.h2, $67UHm$babelruntimehelpersesmextends({
267
- id: context.titleId
268
- }, titleProps, {
269
- ref: forwardedRef
270
- }));
271
- });
272
- /*#__PURE__*/ Object.assign($5d3850c4d0b4e6c7$export$16f7638e4a34b909, {
273
- displayName: $5d3850c4d0b4e6c7$var$TITLE_NAME
274
- });
275
- /* -------------------------------------------------------------------------------------------------
276
- * DialogDescription
277
- * -----------------------------------------------------------------------------------------------*/ const $5d3850c4d0b4e6c7$var$DESCRIPTION_NAME = 'DialogDescription';
278
- const $5d3850c4d0b4e6c7$export$94e94c2ec2c954d5 = /*#__PURE__*/ $67UHm$forwardRef((props, forwardedRef)=>{
279
- const { __scopeDialog: __scopeDialog , ...descriptionProps } = props;
280
- const context = $5d3850c4d0b4e6c7$var$useDialogContext($5d3850c4d0b4e6c7$var$DESCRIPTION_NAME, __scopeDialog);
281
- return /*#__PURE__*/ $67UHm$createElement($67UHm$Primitive.p, $67UHm$babelruntimehelpersesmextends({
282
- id: context.descriptionId
283
- }, descriptionProps, {
284
- ref: forwardedRef
285
- }));
286
- });
287
- /*#__PURE__*/ Object.assign($5d3850c4d0b4e6c7$export$94e94c2ec2c954d5, {
288
- displayName: $5d3850c4d0b4e6c7$var$DESCRIPTION_NAME
289
- });
290
- /* -------------------------------------------------------------------------------------------------
291
- * DialogClose
292
- * -----------------------------------------------------------------------------------------------*/ const $5d3850c4d0b4e6c7$var$CLOSE_NAME = 'DialogClose';
293
- const $5d3850c4d0b4e6c7$export$fba2fb7cd781b7ac = /*#__PURE__*/ $67UHm$forwardRef((props, forwardedRef)=>{
294
- const { __scopeDialog: __scopeDialog , ...closeProps } = props;
295
- const context = $5d3850c4d0b4e6c7$var$useDialogContext($5d3850c4d0b4e6c7$var$CLOSE_NAME, __scopeDialog);
296
- return /*#__PURE__*/ $67UHm$createElement($67UHm$Primitive.button, $67UHm$babelruntimehelpersesmextends({
297
- type: "button"
298
- }, closeProps, {
196
+ }
197
+ );
198
+ }
199
+ );
200
+ var DialogContentImpl = React.forwardRef(
201
+ (props, forwardedRef) => {
202
+ const { __scopeDialog, trapFocus, onOpenAutoFocus, onCloseAutoFocus, ...contentProps } = props;
203
+ const context = useDialogContext(CONTENT_NAME, __scopeDialog);
204
+ const contentRef = React.useRef(null);
205
+ const composedRefs = useComposedRefs(forwardedRef, contentRef);
206
+ useFocusGuards();
207
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
208
+ /* @__PURE__ */ jsx(
209
+ FocusScope,
210
+ {
211
+ asChild: true,
212
+ loop: true,
213
+ trapped: trapFocus,
214
+ onMountAutoFocus: onOpenAutoFocus,
215
+ onUnmountAutoFocus: onCloseAutoFocus,
216
+ children: /* @__PURE__ */ jsx(
217
+ DismissableLayer,
218
+ {
219
+ role: "dialog",
220
+ id: context.contentId,
221
+ "aria-describedby": context.descriptionId,
222
+ "aria-labelledby": context.titleId,
223
+ "data-state": getState(context.open),
224
+ ...contentProps,
225
+ ref: composedRefs,
226
+ onDismiss: () => context.onOpenChange(false)
227
+ }
228
+ )
229
+ }
230
+ ),
231
+ /* @__PURE__ */ jsxs(Fragment, { children: [
232
+ /* @__PURE__ */ jsx(TitleWarning, { titleId: context.titleId }),
233
+ /* @__PURE__ */ jsx(DescriptionWarning, { contentRef, descriptionId: context.descriptionId })
234
+ ] })
235
+ ] });
236
+ }
237
+ );
238
+ var TITLE_NAME = "DialogTitle";
239
+ var DialogTitle = React.forwardRef(
240
+ (props, forwardedRef) => {
241
+ const { __scopeDialog, ...titleProps } = props;
242
+ const context = useDialogContext(TITLE_NAME, __scopeDialog);
243
+ return /* @__PURE__ */ jsx(Primitive.h2, { id: context.titleId, ...titleProps, ref: forwardedRef });
244
+ }
245
+ );
246
+ DialogTitle.displayName = TITLE_NAME;
247
+ var DESCRIPTION_NAME = "DialogDescription";
248
+ var DialogDescription = React.forwardRef(
249
+ (props, forwardedRef) => {
250
+ const { __scopeDialog, ...descriptionProps } = props;
251
+ const context = useDialogContext(DESCRIPTION_NAME, __scopeDialog);
252
+ return /* @__PURE__ */ jsx(Primitive.p, { id: context.descriptionId, ...descriptionProps, ref: forwardedRef });
253
+ }
254
+ );
255
+ DialogDescription.displayName = DESCRIPTION_NAME;
256
+ var CLOSE_NAME = "DialogClose";
257
+ var DialogClose = React.forwardRef(
258
+ (props, forwardedRef) => {
259
+ const { __scopeDialog, ...closeProps } = props;
260
+ const context = useDialogContext(CLOSE_NAME, __scopeDialog);
261
+ return /* @__PURE__ */ jsx(
262
+ Primitive.button,
263
+ {
264
+ type: "button",
265
+ ...closeProps,
299
266
  ref: forwardedRef,
300
- onClick: $67UHm$composeEventHandlers(props.onClick, ()=>context.onOpenChange(false)
301
- )
302
- }));
303
- });
304
- /*#__PURE__*/ Object.assign($5d3850c4d0b4e6c7$export$fba2fb7cd781b7ac, {
305
- displayName: $5d3850c4d0b4e6c7$var$CLOSE_NAME
306
- });
307
- /* -----------------------------------------------------------------------------------------------*/ function $5d3850c4d0b4e6c7$var$getState(open) {
308
- return open ? 'open' : 'closed';
267
+ onClick: composeEventHandlers(props.onClick, () => context.onOpenChange(false))
268
+ }
269
+ );
270
+ }
271
+ );
272
+ DialogClose.displayName = CLOSE_NAME;
273
+ function getState(open) {
274
+ return open ? "open" : "closed";
309
275
  }
310
- const $5d3850c4d0b4e6c7$var$TITLE_WARNING_NAME = 'DialogTitleWarning';
311
- const [$5d3850c4d0b4e6c7$export$69b62a49393917d6, $5d3850c4d0b4e6c7$var$useWarningContext] = $67UHm$createContext($5d3850c4d0b4e6c7$var$TITLE_WARNING_NAME, {
312
- contentName: $5d3850c4d0b4e6c7$var$CONTENT_NAME,
313
- titleName: $5d3850c4d0b4e6c7$var$TITLE_NAME,
314
- docsSlug: 'dialog'
276
+ var TITLE_WARNING_NAME = "DialogTitleWarning";
277
+ var [WarningProvider, useWarningContext] = createContext(TITLE_WARNING_NAME, {
278
+ contentName: CONTENT_NAME,
279
+ titleName: TITLE_NAME,
280
+ docsSlug: "dialog"
315
281
  });
316
- const $5d3850c4d0b4e6c7$var$TitleWarning = ({ titleId: titleId })=>{
317
- const titleWarningContext = $5d3850c4d0b4e6c7$var$useWarningContext($5d3850c4d0b4e6c7$var$TITLE_WARNING_NAME);
318
- const MESSAGE = `\`${titleWarningContext.contentName}\` requires a \`${titleWarningContext.titleName}\` for the component to be accessible for screen reader users.
282
+ var TitleWarning = ({ titleId }) => {
283
+ const titleWarningContext = useWarningContext(TITLE_WARNING_NAME);
284
+ const MESSAGE = `\`${titleWarningContext.contentName}\` requires a \`${titleWarningContext.titleName}\` for the component to be accessible for screen reader users.
319
285
 
320
286
  If you want to hide the \`${titleWarningContext.titleName}\`, you can wrap it with our VisuallyHidden component.
321
287
 
322
288
  For more information, see https://radix-ui.com/primitives/docs/components/${titleWarningContext.docsSlug}`;
323
- $67UHm$useEffect(()=>{
324
- if (titleId) {
325
- const hasTitle = document.getElementById(titleId);
326
- if (!hasTitle) throw new Error(MESSAGE);
327
- }
328
- }, [
329
- MESSAGE,
330
- titleId
331
- ]);
332
- return null;
289
+ React.useEffect(() => {
290
+ if (titleId) {
291
+ const hasTitle = document.getElementById(titleId);
292
+ if (!hasTitle) throw new Error(MESSAGE);
293
+ }
294
+ }, [MESSAGE, titleId]);
295
+ return null;
333
296
  };
334
- const $5d3850c4d0b4e6c7$var$DESCRIPTION_WARNING_NAME = 'DialogDescriptionWarning';
335
- const $5d3850c4d0b4e6c7$var$DescriptionWarning = ({ contentRef: contentRef , descriptionId: descriptionId })=>{
336
- const descriptionWarningContext = $5d3850c4d0b4e6c7$var$useWarningContext($5d3850c4d0b4e6c7$var$DESCRIPTION_WARNING_NAME);
337
- const MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${descriptionWarningContext.contentName}}.`;
338
- $67UHm$useEffect(()=>{
339
- var _contentRef$current;
340
- const describedById = (_contentRef$current = contentRef.current) === null || _contentRef$current === void 0 ? void 0 : _contentRef$current.getAttribute('aria-describedby'); // if we have an id and the user hasn't set aria-describedby={undefined}
341
- if (descriptionId && describedById) {
342
- const hasDescription = document.getElementById(descriptionId);
343
- if (!hasDescription) console.warn(MESSAGE);
344
- }
345
- }, [
346
- MESSAGE,
347
- contentRef,
348
- descriptionId
349
- ]);
350
- return null;
297
+ var DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning";
298
+ var DescriptionWarning = ({ contentRef, descriptionId }) => {
299
+ const descriptionWarningContext = useWarningContext(DESCRIPTION_WARNING_NAME);
300
+ const MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${descriptionWarningContext.contentName}}.`;
301
+ React.useEffect(() => {
302
+ const describedById = contentRef.current?.getAttribute("aria-describedby");
303
+ if (descriptionId && describedById) {
304
+ const hasDescription = document.getElementById(descriptionId);
305
+ if (!hasDescription) console.warn(MESSAGE);
306
+ }
307
+ }, [MESSAGE, contentRef, descriptionId]);
308
+ return null;
309
+ };
310
+ var Root = Dialog;
311
+ var Trigger = DialogTrigger;
312
+ var Portal = DialogPortal;
313
+ var Overlay = DialogOverlay;
314
+ var Content = DialogContent;
315
+ var Title = DialogTitle;
316
+ var Description = DialogDescription;
317
+ var Close = DialogClose;
318
+ export {
319
+ Close,
320
+ Content,
321
+ Description,
322
+ Dialog,
323
+ DialogClose,
324
+ DialogContent,
325
+ DialogDescription,
326
+ DialogOverlay,
327
+ DialogPortal,
328
+ DialogTitle,
329
+ DialogTrigger,
330
+ Overlay,
331
+ Portal,
332
+ Root,
333
+ Title,
334
+ Trigger,
335
+ WarningProvider,
336
+ createDialogScope
351
337
  };
352
- const $5d3850c4d0b4e6c7$export$be92b6f5f03c0fe9 = $5d3850c4d0b4e6c7$export$3ddf2d174ce01153;
353
- const $5d3850c4d0b4e6c7$export$41fb9f06171c75f4 = $5d3850c4d0b4e6c7$export$2e1e1122cf0cba88;
354
- const $5d3850c4d0b4e6c7$export$602eac185826482c = $5d3850c4d0b4e6c7$export$dad7c95542bacce0;
355
- const $5d3850c4d0b4e6c7$export$c6fdb837b070b4ff = $5d3850c4d0b4e6c7$export$bd1d06c79be19e17;
356
- const $5d3850c4d0b4e6c7$export$7c6e2c02157bb7d2 = $5d3850c4d0b4e6c7$export$b6d9565de1e068cf;
357
- const $5d3850c4d0b4e6c7$export$f99233281efd08a0 = $5d3850c4d0b4e6c7$export$16f7638e4a34b909;
358
- const $5d3850c4d0b4e6c7$export$393edc798c47379d = $5d3850c4d0b4e6c7$export$94e94c2ec2c954d5;
359
- const $5d3850c4d0b4e6c7$export$f39c2d165cd861fe = $5d3850c4d0b4e6c7$export$fba2fb7cd781b7ac;
360
-
361
-
362
-
363
-
364
- export {$5d3850c4d0b4e6c7$export$cc702773b8ea3e41 as createDialogScope, $5d3850c4d0b4e6c7$export$3ddf2d174ce01153 as Dialog, $5d3850c4d0b4e6c7$export$2e1e1122cf0cba88 as DialogTrigger, $5d3850c4d0b4e6c7$export$dad7c95542bacce0 as DialogPortal, $5d3850c4d0b4e6c7$export$bd1d06c79be19e17 as DialogOverlay, $5d3850c4d0b4e6c7$export$b6d9565de1e068cf as DialogContent, $5d3850c4d0b4e6c7$export$16f7638e4a34b909 as DialogTitle, $5d3850c4d0b4e6c7$export$94e94c2ec2c954d5 as DialogDescription, $5d3850c4d0b4e6c7$export$fba2fb7cd781b7ac as DialogClose, $5d3850c4d0b4e6c7$export$be92b6f5f03c0fe9 as Root, $5d3850c4d0b4e6c7$export$41fb9f06171c75f4 as Trigger, $5d3850c4d0b4e6c7$export$602eac185826482c as Portal, $5d3850c4d0b4e6c7$export$c6fdb837b070b4ff as Overlay, $5d3850c4d0b4e6c7$export$7c6e2c02157bb7d2 as Content, $5d3850c4d0b4e6c7$export$f99233281efd08a0 as Title, $5d3850c4d0b4e6c7$export$393edc798c47379d as Description, $5d3850c4d0b4e6c7$export$f39c2d165cd861fe as Close, $5d3850c4d0b4e6c7$export$69b62a49393917d6 as WarningProvider};
365
338
  //# sourceMappingURL=index.mjs.map