@radix-ui/react-toast 0.1.2-rc.48 → 0.1.2-rc.50
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.ts.map +1 -1
- package/dist/index.js +171 -65
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +171 -65
- package/dist/index.module.js.map +1 -1
- package/package.json +12 -11
package/dist/index.module.js
CHANGED
|
@@ -3,11 +3,12 @@ import {useState as $eyrYI$useState, useRef as $eyrYI$useRef, createElement as $
|
|
|
3
3
|
import {createPortal as $eyrYI$createPortal} from "react-dom";
|
|
4
4
|
import {composeEventHandlers as $eyrYI$composeEventHandlers} from "@radix-ui/primitive";
|
|
5
5
|
import {useComposedRefs as $eyrYI$useComposedRefs} from "@radix-ui/react-compose-refs";
|
|
6
|
+
import {createCollection as $eyrYI$createCollection} from "@radix-ui/react-collection";
|
|
6
7
|
import {createContextScope as $eyrYI$createContextScope} from "@radix-ui/react-context";
|
|
7
8
|
import {Branch as $eyrYI$Branch, Root as $eyrYI$Root} from "@radix-ui/react-dismissable-layer";
|
|
8
|
-
import {Portal as $eyrYI$Portal} from "@radix-ui/react-portal";
|
|
9
9
|
import {Presence as $eyrYI$Presence} from "@radix-ui/react-presence";
|
|
10
10
|
import {Primitive as $eyrYI$Primitive, dispatchDiscreteCustomEvent as $eyrYI$dispatchDiscreteCustomEvent} from "@radix-ui/react-primitive";
|
|
11
|
+
import {Slottable as $eyrYI$Slottable} from "@radix-ui/react-slot";
|
|
11
12
|
import {useCallbackRef as $eyrYI$useCallbackRef} from "@radix-ui/react-use-callback-ref";
|
|
12
13
|
import {useControllableState as $eyrYI$useControllableState} from "@radix-ui/react-use-controllable-state";
|
|
13
14
|
import {useLayoutEffect as $eyrYI$useLayoutEffect} from "@radix-ui/react-use-layout-effect";
|
|
@@ -47,10 +48,14 @@ $parcel$export($054eb8030ebde76e$exports, "Close", () => $054eb8030ebde76e$expor
|
|
|
47
48
|
|
|
48
49
|
|
|
49
50
|
|
|
51
|
+
|
|
50
52
|
/* -------------------------------------------------------------------------------------------------
|
|
51
53
|
* ToastProvider
|
|
52
54
|
* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$PROVIDER_NAME = 'ToastProvider';
|
|
53
|
-
const [$054eb8030ebde76e$var$
|
|
55
|
+
const [$054eb8030ebde76e$var$Collection, $054eb8030ebde76e$var$useCollection, $054eb8030ebde76e$var$createCollectionScope] = $eyrYI$createCollection('Toast');
|
|
56
|
+
const [$054eb8030ebde76e$var$createToastContext, $054eb8030ebde76e$export$8a359da18fbc9073] = $eyrYI$createContextScope('Toast', [
|
|
57
|
+
$054eb8030ebde76e$var$createCollectionScope
|
|
58
|
+
]);
|
|
54
59
|
const [$054eb8030ebde76e$var$ToastProviderProvider, $054eb8030ebde76e$var$useToastProviderContext] = $054eb8030ebde76e$var$createToastContext($054eb8030ebde76e$var$PROVIDER_NAME);
|
|
55
60
|
const $054eb8030ebde76e$export$f5d03d415824e0e = (props)=>{
|
|
56
61
|
const { __scopeToast: __scopeToast , label: label = 'Notification' , duration: duration = 5000 , swipeDirection: swipeDirection = 'right' , swipeThreshold: swipeThreshold = 50 , children: children } = props;
|
|
@@ -58,7 +63,9 @@ const $054eb8030ebde76e$export$f5d03d415824e0e = (props)=>{
|
|
|
58
63
|
const [toastCount, setToastCount] = $eyrYI$useState(0);
|
|
59
64
|
const isFocusedToastEscapeKeyDownRef = $eyrYI$useRef(false);
|
|
60
65
|
const isClosePausedRef = $eyrYI$useRef(false);
|
|
61
|
-
return /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$
|
|
66
|
+
return /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$Collection.Provider, {
|
|
67
|
+
scope: __scopeToast
|
|
68
|
+
}, /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$ToastProviderProvider, {
|
|
62
69
|
scope: __scopeToast,
|
|
63
70
|
label: label,
|
|
64
71
|
duration: duration,
|
|
@@ -75,7 +82,16 @@ const $054eb8030ebde76e$export$f5d03d415824e0e = (props)=>{
|
|
|
75
82
|
, []),
|
|
76
83
|
isFocusedToastEscapeKeyDownRef: isFocusedToastEscapeKeyDownRef,
|
|
77
84
|
isClosePausedRef: isClosePausedRef
|
|
78
|
-
}, children);
|
|
85
|
+
}, children));
|
|
86
|
+
};
|
|
87
|
+
$054eb8030ebde76e$export$f5d03d415824e0e.propTypes = {
|
|
88
|
+
label (props) {
|
|
89
|
+
if (props.label && typeof props.label === 'string' && !props.label.trim()) {
|
|
90
|
+
const error = `Invalid prop \`label\` supplied to \`${$054eb8030ebde76e$var$PROVIDER_NAME}\`. Expected non-empty \`string\`.`;
|
|
91
|
+
return new Error(error);
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
79
95
|
};
|
|
80
96
|
/*#__PURE__*/ Object.assign($054eb8030ebde76e$export$f5d03d415824e0e, {
|
|
81
97
|
displayName: $054eb8030ebde76e$var$PROVIDER_NAME
|
|
@@ -91,10 +107,14 @@ const $054eb8030ebde76e$var$VIEWPORT_RESUME = 'toast.viewportResume';
|
|
|
91
107
|
const $054eb8030ebde76e$export$6192c2425ecfd989 = /*#__PURE__*/ $eyrYI$forwardRef((props, forwardedRef)=>{
|
|
92
108
|
const { __scopeToast: __scopeToast , hotkey: hotkey = $054eb8030ebde76e$var$VIEWPORT_DEFAULT_HOTKEY , label: label = 'Notifications ({hotkey})' , ...viewportProps } = props;
|
|
93
109
|
const context = $054eb8030ebde76e$var$useToastProviderContext($054eb8030ebde76e$var$VIEWPORT_NAME, __scopeToast);
|
|
110
|
+
const getItems = $054eb8030ebde76e$var$useCollection(__scopeToast);
|
|
94
111
|
const wrapperRef = $eyrYI$useRef(null);
|
|
112
|
+
const headFocusProxyRef = $eyrYI$useRef(null);
|
|
113
|
+
const tailFocusProxyRef = $eyrYI$useRef(null);
|
|
95
114
|
const ref = $eyrYI$useRef(null);
|
|
96
115
|
const composedRefs = $eyrYI$useComposedRefs(forwardedRef, ref, context.onViewportChange);
|
|
97
116
|
const hotkeyLabel = hotkey.join('+').replace(/Key/g, '').replace(/Digit/g, '');
|
|
117
|
+
const hasToasts = context.toastCount > 0;
|
|
98
118
|
$eyrYI$useEffect(()=>{
|
|
99
119
|
const handleKeyDown = (event)=>{
|
|
100
120
|
var _ref$current;
|
|
@@ -142,33 +162,62 @@ const $054eb8030ebde76e$export$6192c2425ecfd989 = /*#__PURE__*/ $eyrYI$forwardRe
|
|
|
142
162
|
}, [
|
|
143
163
|
context.isClosePausedRef
|
|
144
164
|
]);
|
|
165
|
+
const getSortedTabbableCandidates = $eyrYI$useCallback(({ tabbingDirection: tabbingDirection })=>{
|
|
166
|
+
const toastItems = getItems();
|
|
167
|
+
const tabbableCandidates = toastItems.map((toastItem)=>{
|
|
168
|
+
const toastNode = toastItem.ref.current;
|
|
169
|
+
const toastTabbableCandidates = [
|
|
170
|
+
toastNode,
|
|
171
|
+
...$054eb8030ebde76e$var$getTabbableCandidates(toastNode)
|
|
172
|
+
];
|
|
173
|
+
return tabbingDirection === 'forwards' ? toastTabbableCandidates : toastTabbableCandidates.reverse();
|
|
174
|
+
});
|
|
175
|
+
return (tabbingDirection === 'forwards' ? tabbableCandidates.reverse() : tabbableCandidates).flat();
|
|
176
|
+
}, [
|
|
177
|
+
getItems
|
|
178
|
+
]);
|
|
145
179
|
$eyrYI$useEffect(()=>{
|
|
146
|
-
const viewport = ref.current; //
|
|
180
|
+
const viewport = ref.current; // We programmatically manage tabbing as we are unable to influence
|
|
181
|
+
// the source order with portals, this allows us to reverse the
|
|
182
|
+
// tab order so that it runs from most recent toast to least
|
|
147
183
|
if (viewport) {
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
//
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
184
|
+
const handleKeyDown = (event)=>{
|
|
185
|
+
const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
|
|
186
|
+
const isTabKey = event.key === 'Tab' && !isMetaKey;
|
|
187
|
+
if (isTabKey) {
|
|
188
|
+
const focusedElement = document.activeElement;
|
|
189
|
+
const isTabbingBackwards = event.shiftKey;
|
|
190
|
+
const targetIsViewport = event.target === viewport; // If we're back tabbing after jumping to the viewport then we simply
|
|
191
|
+
// proxy focus out to the preceding document
|
|
192
|
+
if (targetIsViewport && isTabbingBackwards) {
|
|
193
|
+
var _headFocusProxyRef$cu;
|
|
194
|
+
(_headFocusProxyRef$cu = headFocusProxyRef.current) === null || _headFocusProxyRef$cu === void 0 || _headFocusProxyRef$cu.focus();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const tabbingDirection = isTabbingBackwards ? 'backwards' : 'forwards';
|
|
198
|
+
const sortedCandidates = getSortedTabbableCandidates({
|
|
199
|
+
tabbingDirection: tabbingDirection
|
|
200
|
+
});
|
|
201
|
+
const index = sortedCandidates.findIndex((candidate)=>candidate === focusedElement
|
|
202
|
+
);
|
|
203
|
+
if ($054eb8030ebde76e$var$focusFirst(sortedCandidates.slice(index + 1))) event.preventDefault();
|
|
204
|
+
else {
|
|
205
|
+
var _headFocusProxyRef$cu2, _tailFocusProxyRef$cu;
|
|
206
|
+
// If we can't focus that means we're at the edges so we
|
|
207
|
+
// proxy to the corresponding exit point and let the browser handle
|
|
208
|
+
// tab/shift+tab keypress and implicitly pass focus to the next valid element in the document
|
|
209
|
+
isTabbingBackwards ? (_headFocusProxyRef$cu2 = headFocusProxyRef.current) === null || _headFocusProxyRef$cu2 === void 0 || _headFocusProxyRef$cu2.focus() : (_tailFocusProxyRef$cu = tailFocusProxyRef.current) === null || _tailFocusProxyRef$cu === void 0 || _tailFocusProxyRef$cu.focus();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}; // Toasts are not in the viewport React tree so we need to bind DOM events
|
|
213
|
+
viewport.addEventListener('keydown', handleKeyDown);
|
|
214
|
+
return ()=>viewport.removeEventListener('keydown', handleKeyDown)
|
|
169
215
|
;
|
|
170
216
|
}
|
|
171
|
-
}, [
|
|
217
|
+
}, [
|
|
218
|
+
getItems,
|
|
219
|
+
getSortedTabbableCandidates
|
|
220
|
+
]);
|
|
172
221
|
return /*#__PURE__*/ $eyrYI$createElement($eyrYI$Branch, {
|
|
173
222
|
ref: wrapperRef,
|
|
174
223
|
role: "region",
|
|
@@ -177,17 +226,59 @@ const $054eb8030ebde76e$export$6192c2425ecfd989 = /*#__PURE__*/ $eyrYI$forwardRe
|
|
|
177
226
|
tabIndex: -1 // incase list has size when empty (e.g. padding), we remove pointer events so
|
|
178
227
|
,
|
|
179
228
|
style: {
|
|
180
|
-
pointerEvents:
|
|
229
|
+
pointerEvents: hasToasts ? undefined : 'none'
|
|
230
|
+
}
|
|
231
|
+
}, hasToasts && /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$FocusProxy, {
|
|
232
|
+
ref: headFocusProxyRef,
|
|
233
|
+
onFocusFromOutsideViewport: ()=>{
|
|
234
|
+
const tabbableCandidates = getSortedTabbableCandidates({
|
|
235
|
+
tabbingDirection: 'forwards'
|
|
236
|
+
});
|
|
237
|
+
$054eb8030ebde76e$var$focusFirst(tabbableCandidates);
|
|
181
238
|
}
|
|
239
|
+
}), /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$Collection.Slot, {
|
|
240
|
+
scope: __scopeToast
|
|
182
241
|
}, /*#__PURE__*/ $eyrYI$createElement($eyrYI$Primitive.ol, $eyrYI$babelruntimehelpersesmextends({
|
|
183
242
|
tabIndex: -1
|
|
184
243
|
}, viewportProps, {
|
|
185
244
|
ref: composedRefs
|
|
186
|
-
})))
|
|
245
|
+
}))), hasToasts && /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$FocusProxy, {
|
|
246
|
+
ref: tailFocusProxyRef,
|
|
247
|
+
onFocusFromOutsideViewport: ()=>{
|
|
248
|
+
const tabbableCandidates = getSortedTabbableCandidates({
|
|
249
|
+
tabbingDirection: 'backwards'
|
|
250
|
+
});
|
|
251
|
+
$054eb8030ebde76e$var$focusFirst(tabbableCandidates);
|
|
252
|
+
}
|
|
253
|
+
}));
|
|
187
254
|
});
|
|
188
255
|
/*#__PURE__*/ Object.assign($054eb8030ebde76e$export$6192c2425ecfd989, {
|
|
189
256
|
displayName: $054eb8030ebde76e$var$VIEWPORT_NAME
|
|
190
257
|
});
|
|
258
|
+
/* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$FOCUS_PROXY_NAME = 'ToastFocusProxy';
|
|
259
|
+
const $054eb8030ebde76e$var$FocusProxy = /*#__PURE__*/ $eyrYI$forwardRef((props, forwardedRef)=>{
|
|
260
|
+
const { __scopeToast: __scopeToast , onFocusFromOutsideViewport: onFocusFromOutsideViewport , ...proxyProps } = props;
|
|
261
|
+
const context = $054eb8030ebde76e$var$useToastProviderContext($054eb8030ebde76e$var$FOCUS_PROXY_NAME, __scopeToast);
|
|
262
|
+
return /*#__PURE__*/ $eyrYI$createElement($eyrYI$VisuallyHidden, $eyrYI$babelruntimehelpersesmextends({
|
|
263
|
+
"aria-hidden": true,
|
|
264
|
+
tabIndex: 0
|
|
265
|
+
}, proxyProps, {
|
|
266
|
+
ref: forwardedRef // Avoid page scrolling when focus is on the focus proxy
|
|
267
|
+
,
|
|
268
|
+
style: {
|
|
269
|
+
position: 'fixed'
|
|
270
|
+
},
|
|
271
|
+
onFocus: (event)=>{
|
|
272
|
+
var _context$viewport;
|
|
273
|
+
const prevFocusedElement = event.relatedTarget;
|
|
274
|
+
const isFocusFromOutsideViewport = !((_context$viewport = context.viewport) !== null && _context$viewport !== void 0 && _context$viewport.contains(prevFocusedElement));
|
|
275
|
+
if (isFocusFromOutsideViewport) onFocusFromOutsideViewport();
|
|
276
|
+
}
|
|
277
|
+
}));
|
|
278
|
+
});
|
|
279
|
+
/*#__PURE__*/ Object.assign($054eb8030ebde76e$var$FocusProxy, {
|
|
280
|
+
displayName: $054eb8030ebde76e$var$FOCUS_PROXY_NAME
|
|
281
|
+
});
|
|
191
282
|
/* -------------------------------------------------------------------------------------------------
|
|
192
283
|
* Toast
|
|
193
284
|
* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$TOAST_NAME = 'Toast';
|
|
@@ -245,7 +336,7 @@ const $054eb8030ebde76e$export$8d8dc7d5f743331b = /*#__PURE__*/ $eyrYI$forwardRe
|
|
|
245
336
|
onClose () {}
|
|
246
337
|
});
|
|
247
338
|
const $054eb8030ebde76e$var$ToastImpl = /*#__PURE__*/ $eyrYI$forwardRef((props, forwardedRef)=>{
|
|
248
|
-
const { __scopeToast: __scopeToast , type: type = 'foreground' , duration: durationProp , open: open , onClose: onClose , onEscapeKeyDown: onEscapeKeyDown , onSwipeStart: onSwipeStart , onSwipeMove: onSwipeMove , onSwipeCancel: onSwipeCancel , onSwipeEnd: onSwipeEnd , ...toastProps } = props;
|
|
339
|
+
const { __scopeToast: __scopeToast , children: children , type: type = 'foreground' , duration: durationProp , open: open , onClose: onClose , onEscapeKeyDown: onEscapeKeyDown , onSwipeStart: onSwipeStart , onSwipeMove: onSwipeMove , onSwipeCancel: onSwipeCancel , onSwipeEnd: onSwipeEnd , ...toastProps } = props;
|
|
249
340
|
const context = $054eb8030ebde76e$var$useToastProviderContext($054eb8030ebde76e$var$TOAST_NAME, __scopeToast);
|
|
250
341
|
const ref = $eyrYI$useRef(null);
|
|
251
342
|
const composedRefs = $eyrYI$useComposedRefs(forwardedRef, ref);
|
|
@@ -255,13 +346,14 @@ const $054eb8030ebde76e$var$ToastImpl = /*#__PURE__*/ $eyrYI$forwardRef((props,
|
|
|
255
346
|
const closeTimerStartTimeRef = $eyrYI$useRef(0);
|
|
256
347
|
const closeTimerRemainingTimeRef = $eyrYI$useRef(duration1);
|
|
257
348
|
const closeTimerRef = $eyrYI$useRef(0);
|
|
349
|
+
const [renderLabel, setRenderLabel] = $eyrYI$useState(false);
|
|
258
350
|
const { onToastAdd: onToastAdd , onToastRemove: onToastRemove } = context;
|
|
259
351
|
const handleClose = $eyrYI$useCallbackRef(()=>{
|
|
260
|
-
var _ref$current2, _context$
|
|
352
|
+
var _ref$current2, _context$viewport2;
|
|
261
353
|
// focus viewport if focus is within toast to read the remaining toast
|
|
262
354
|
// count to SR users and ensure focus isn't lost
|
|
263
355
|
const isFocusInToast = (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.contains(document.activeElement);
|
|
264
|
-
if (isFocusInToast) (_context$
|
|
356
|
+
if (isFocusInToast) (_context$viewport2 = context.viewport) === null || _context$viewport2 === void 0 || _context$viewport2.focus();
|
|
265
357
|
onClose();
|
|
266
358
|
});
|
|
267
359
|
const startTimer = $eyrYI$useCallback((duration)=>{
|
|
@@ -312,19 +404,17 @@ const $054eb8030ebde76e$var$ToastImpl = /*#__PURE__*/ $eyrYI$forwardRef((props,
|
|
|
312
404
|
}, [
|
|
313
405
|
onToastAdd,
|
|
314
406
|
onToastRemove
|
|
315
|
-
]);
|
|
407
|
+
]); // render label in the next frame to trigger toast announcement in NVDA
|
|
408
|
+
$054eb8030ebde76e$var$useNextFrame(()=>setRenderLabel(true)
|
|
409
|
+
);
|
|
316
410
|
if (!context.viewport) return null;
|
|
317
|
-
return /*#__PURE__*/ $eyrYI$createElement($eyrYI$Fragment, null, /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$
|
|
318
|
-
__scopeToast: __scopeToast // Toasts are always role=status to avoid stuttering issues with role=alert in SRs.
|
|
319
|
-
,
|
|
320
|
-
role: "status",
|
|
321
|
-
"aria-live": type === 'foreground' ? 'assertive' : 'polite',
|
|
322
|
-
"aria-atomic": true
|
|
323
|
-
}, props.children), /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$ToastInteractiveProvider, {
|
|
411
|
+
return /*#__PURE__*/ $eyrYI$createElement($eyrYI$Fragment, null, /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$ToastInteractiveProvider, {
|
|
324
412
|
scope: __scopeToast,
|
|
325
413
|
isInteractive: true,
|
|
326
414
|
onClose: handleClose
|
|
327
|
-
}, /*#__PURE__*/ $eyrYI$createPortal(/*#__PURE__*/ $eyrYI$createElement($
|
|
415
|
+
}, /*#__PURE__*/ $eyrYI$createPortal(/*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$Collection.ItemSlot, {
|
|
416
|
+
scope: __scopeToast
|
|
417
|
+
}, /*#__PURE__*/ $eyrYI$createElement($eyrYI$Root, {
|
|
328
418
|
asChild: true,
|
|
329
419
|
onEscapeKeyDown: $eyrYI$composeEventHandlers(onEscapeKeyDown, ()=>{
|
|
330
420
|
if (!context.isFocusedToastEscapeKeyDownRef.current) handleClose();
|
|
@@ -332,8 +422,10 @@ const $054eb8030ebde76e$var$ToastImpl = /*#__PURE__*/ $eyrYI$forwardRef((props,
|
|
|
332
422
|
})
|
|
333
423
|
}, /*#__PURE__*/ $eyrYI$createElement($eyrYI$Primitive.li, $eyrYI$babelruntimehelpersesmextends({
|
|
334
424
|
role: "status",
|
|
335
|
-
"aria-live":
|
|
336
|
-
"aria-atomic": true
|
|
425
|
+
"aria-live": type === 'foreground' ? 'assertive' : 'polite',
|
|
426
|
+
"aria-atomic": true // Prevent voice over from announcing before the label is rendered
|
|
427
|
+
,
|
|
428
|
+
"aria-hidden": !renderLabel || undefined,
|
|
337
429
|
tabIndex: 0,
|
|
338
430
|
"data-state": open ? 'open' : 'closed',
|
|
339
431
|
"data-swipe-direction": context.swipeDirection
|
|
@@ -423,7 +515,7 @@ const $054eb8030ebde76e$var$ToastImpl = /*#__PURE__*/ $eyrYI$forwardRef((props,
|
|
|
423
515
|
});
|
|
424
516
|
}
|
|
425
517
|
})
|
|
426
|
-
}))), context.viewport)));
|
|
518
|
+
}), /*#__PURE__*/ $eyrYI$createElement($eyrYI$VisuallyHidden, null, renderLabel && context.label), /*#__PURE__*/ $eyrYI$createElement($eyrYI$Slottable, null, children)))), context.viewport)));
|
|
427
519
|
});
|
|
428
520
|
$054eb8030ebde76e$var$ToastImpl.propTypes = {
|
|
429
521
|
type (props) {
|
|
@@ -432,30 +524,11 @@ $054eb8030ebde76e$var$ToastImpl.propTypes = {
|
|
|
432
524
|
'background'
|
|
433
525
|
].includes(props.type)) {
|
|
434
526
|
const error = `Invalid prop \`type\` supplied to \`${$054eb8030ebde76e$var$TOAST_NAME}\`. Expected \`foreground | background\`.`;
|
|
435
|
-
|
|
527
|
+
return new Error(error);
|
|
436
528
|
}
|
|
437
529
|
return null;
|
|
438
530
|
}
|
|
439
531
|
};
|
|
440
|
-
/* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$ToastAnnounce = (props)=>{
|
|
441
|
-
const { __scopeToast: __scopeToast , ...announceProps } = props;
|
|
442
|
-
const context = $054eb8030ebde76e$var$useToastProviderContext($054eb8030ebde76e$var$TOAST_NAME, __scopeToast);
|
|
443
|
-
const [renderChildren, setRenderChildren] = $eyrYI$useState(false);
|
|
444
|
-
const [isAnnounced, setIsAnnounced] = $eyrYI$useState(false); // render children in the next frame to ensure toast is announced in NVDA
|
|
445
|
-
$054eb8030ebde76e$var$useNextFrame(()=>setRenderChildren(true)
|
|
446
|
-
);
|
|
447
|
-
$eyrYI$useEffect(()=>{
|
|
448
|
-
const timer = window.setTimeout(()=>setIsAnnounced(true)
|
|
449
|
-
, 1000);
|
|
450
|
-
return ()=>window.clearTimeout(timer)
|
|
451
|
-
;
|
|
452
|
-
}, []);
|
|
453
|
-
return isAnnounced ? null : /*#__PURE__*/ $eyrYI$createElement($eyrYI$Portal, {
|
|
454
|
-
asChild: true
|
|
455
|
-
}, /*#__PURE__*/ $eyrYI$createElement($eyrYI$VisuallyHidden, {
|
|
456
|
-
asChild: true
|
|
457
|
-
}, /*#__PURE__*/ $eyrYI$createElement("div", announceProps, renderChildren && /*#__PURE__*/ $eyrYI$createElement($eyrYI$Fragment, null, context.label, " ", props.children))));
|
|
458
|
-
};
|
|
459
532
|
/* -------------------------------------------------------------------------------------------------
|
|
460
533
|
* ToastTitle
|
|
461
534
|
* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$TITLE_NAME = 'ToastTitle';
|
|
@@ -493,7 +566,7 @@ const $054eb8030ebde76e$export$3019feecfda683d2 = /*#__PURE__*/ $eyrYI$forwardRe
|
|
|
493
566
|
});
|
|
494
567
|
$054eb8030ebde76e$export$3019feecfda683d2.propTypes = {
|
|
495
568
|
altText (props) {
|
|
496
|
-
if (!props.altText)
|
|
569
|
+
if (!props.altText) return new Error(`Missing prop \`altText\` expected on \`${$054eb8030ebde76e$var$ACTION_NAME}\``);
|
|
497
570
|
return null;
|
|
498
571
|
}
|
|
499
572
|
};
|
|
@@ -551,6 +624,39 @@ function $054eb8030ebde76e$var$useNextFrame(callback = ()=>{}) {
|
|
|
551
624
|
fn
|
|
552
625
|
]);
|
|
553
626
|
}
|
|
627
|
+
/**
|
|
628
|
+
* Returns a list of potential tabbable candidates.
|
|
629
|
+
*
|
|
630
|
+
* NOTE: This is only a close approximation. For example it doesn't take into account cases like when
|
|
631
|
+
* elements are not visible. This cannot be worked out easily by just reading a property, but rather
|
|
632
|
+
* necessitate runtime knowledge (computed styles, etc). We deal with these cases separately.
|
|
633
|
+
*
|
|
634
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
|
|
635
|
+
* Credit: https://github.com/discord/focus-layers/blob/master/src/util/wrapFocus.tsx#L1
|
|
636
|
+
*/ function $054eb8030ebde76e$var$getTabbableCandidates(container) {
|
|
637
|
+
const nodes = [];
|
|
638
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
639
|
+
acceptNode: (node)=>{
|
|
640
|
+
const isHiddenInput = node.tagName === 'INPUT' && node.type === 'hidden';
|
|
641
|
+
if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP; // `.tabIndex` is not the same as the `tabindex` attribute. It works on the
|
|
642
|
+
// runtime's understanding of tabbability, so this automatically accounts
|
|
643
|
+
// for any kind of element that could be tabbed to.
|
|
644
|
+
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
while(walker.nextNode())nodes.push(walker.currentNode); // we do not take into account the order of nodes with positive `tabIndex` as it
|
|
648
|
+
// hinders accessibility to have tab order different from visual order.
|
|
649
|
+
return nodes;
|
|
650
|
+
}
|
|
651
|
+
function $054eb8030ebde76e$var$focusFirst(candidates) {
|
|
652
|
+
const previouslyFocusedElement = document.activeElement;
|
|
653
|
+
return candidates.some((candidate)=>{
|
|
654
|
+
// if focus is already where we want to go, we don't want to keep going through the candidates
|
|
655
|
+
if (candidate === previouslyFocusedElement) return true;
|
|
656
|
+
candidate.focus();
|
|
657
|
+
return document.activeElement !== previouslyFocusedElement;
|
|
658
|
+
});
|
|
659
|
+
}
|
|
554
660
|
const $054eb8030ebde76e$export$2881499e37b75b9a = $054eb8030ebde76e$export$f5d03d415824e0e;
|
|
555
661
|
const $054eb8030ebde76e$export$d5c6c08dc2d3ca7 = $054eb8030ebde76e$export$6192c2425ecfd989;
|
|
556
662
|
const $054eb8030ebde76e$export$be92b6f5f03c0fe9 = $054eb8030ebde76e$export$8d8dc7d5f743331b;
|