@radix-ui/react-dialog 1.0.6-rc.6 → 1.1.0-rc.2

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