@razorpay/blade 10.14.1 → 10.14.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.
@@ -29032,6 +29032,7 @@ var _BottomSheet = function _BottomSheet(_ref2) {
29032
29032
  var scrollRef = React__default.useRef(null);
29033
29033
  var grabHandleRef = React__default.useRef(null);
29034
29034
  var defaultInitialFocusRef = React__default.useRef(null);
29035
+ var originalFocusElement = React__default.useRef(null);
29035
29036
  var initialSnapPoint = React__default.useRef(snapPoints[1]);
29036
29037
  var totalHeight = React__default.useMemo(function () {
29037
29038
  return grabHandleHeight + headerHeight + footerHeight + contentHeight;
@@ -29096,17 +29097,43 @@ var _BottomSheet = function _BottomSheet(_ref2) {
29096
29097
  }
29097
29098
  }
29098
29099
  }, [dimensions.height, snapPoints, totalHeight]);
29100
+ var returnFocus = React__default.useCallback(function () {
29101
+ if (!originalFocusElement.current) return;
29102
+ originalFocusElement.current.focus();
29103
+ // After returning focus we will clear the original focus
29104
+ // Because if sheet can be opened up via multiple triggers
29105
+ // We want to ensure the focus returns back to the most recent triggerer
29106
+ originalFocusElement.current = null;
29107
+ }, [originalFocusElement]);
29108
+ var focusOnInitialRef = React__default.useCallback(function () {
29109
+ if (!initialFocusRef) {
29110
+ var _defaultInitialFocusR;
29111
+ // focus on close button
29112
+ (_defaultInitialFocusR = defaultInitialFocusRef.current) === null || _defaultInitialFocusR === void 0 ? void 0 : _defaultInitialFocusR.focus();
29113
+ } else {
29114
+ var _initialFocusRef$curr;
29115
+ // focus on the initialRef passed by the user
29116
+ (_initialFocusRef$curr = initialFocusRef.current) === null || _initialFocusRef$curr === void 0 ? void 0 : _initialFocusRef$curr.focus();
29117
+ }
29118
+ }, [initialFocusRef]);
29099
29119
  var handleOnOpen = React__default.useCallback(function () {
29120
+ var _originalFocusElement;
29100
29121
  setPositionY(dimensions.height * initialSnapPoint.current);
29101
29122
  scrollLockRef.current.activate();
29102
- }, [dimensions.height, scrollLockRef, setPositionY]);
29123
+ // initialize the original focused element
29124
+ // On first render it will be the activeElement, eg: the button trigger or select input
29125
+ // On Subsequent open operations it won't further update the original focus
29126
+ originalFocusElement.current = (_originalFocusElement = originalFocusElement.current) !== null && _originalFocusElement !== void 0 ? _originalFocusElement : document.activeElement;
29127
+ focusOnInitialRef();
29128
+ }, [dimensions.height, focusOnInitialRef, scrollLockRef, setPositionY]);
29103
29129
  var handleOnClose = React__default.useCallback(function () {
29104
29130
  setPositionY(0);
29105
29131
  }, [setPositionY]);
29106
29132
  var close = React__default.useCallback(function () {
29107
29133
  onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss();
29108
29134
  bottomSheetAndDropdownGlue === null || bottomSheetAndDropdownGlue === void 0 ? void 0 : bottomSheetAndDropdownGlue.onBottomSheetDismiss();
29109
- }, [bottomSheetAndDropdownGlue, onDismiss]);
29135
+ returnFocus();
29136
+ }, [bottomSheetAndDropdownGlue, onDismiss, returnFocus]);
29110
29137
 
29111
29138
  // sync controlled state to our actions
29112
29139
  React__default.useEffect(function () {
@@ -29313,13 +29340,6 @@ var _BottomSheet = function _BottomSheet(_ref2) {
29313
29340
  }
29314
29341
  }, [isMounted, scrollLockRef]);
29315
29342
 
29316
- // required by floating ui to handle focus
29317
- var _useFloating = useFloating({
29318
- open: isMounted
29319
- }),
29320
- refs = _useFloating.refs,
29321
- context = _useFloating.context;
29322
-
29323
29343
  // We don't want to destroy the react tree when we are rendering inside Dropdown
29324
29344
  // Because if we bail out early then ActionList won't render,
29325
29345
  // and Dropdown manages it's state based on the rendered JSX of ActionList
@@ -29328,48 +29348,39 @@ var _BottomSheet = function _BottomSheet(_ref2) {
29328
29348
  if (!isMounted && !isInsideDropdown) {
29329
29349
  return /*#__PURE__*/jsx(Fragment, {});
29330
29350
  }
29331
- return /*#__PURE__*/jsx(BottomSheetContext.Provider, {
29351
+ return /*#__PURE__*/jsxs(BottomSheetContext.Provider, {
29332
29352
  value: contextValue,
29333
- children: (isMounted || isInsideDropdown) && /*#__PURE__*/jsx(FloatingFocusManager, {
29334
- returnFocus: true,
29335
- initialFocus: initialFocusRef !== null && initialFocusRef !== void 0 ? initialFocusRef : defaultInitialFocusRef,
29336
- context: context,
29353
+ children: [/*#__PURE__*/jsx(BottomSheetBackdrop, {
29354
+ zIndex: bottomSheetZIndex
29355
+ }), /*#__PURE__*/jsx(BottomSheetSurface, _objectSpread$f(_objectSpread$f(_objectSpread$f({}, metaAttribute({
29356
+ name: MetaConstants.BottomSheet,
29357
+ testID: 'bottomsheet-surface'
29358
+ })), makeAccessible({
29337
29359
  modal: true,
29338
- children: /*#__PURE__*/jsxs(Fragment, {
29339
- children: [/*#__PURE__*/jsx(BottomSheetBackdrop, {
29340
- zIndex: bottomSheetZIndex
29341
- }), /*#__PURE__*/jsx(BottomSheetSurface, _objectSpread$f(_objectSpread$f(_objectSpread$f({}, metaAttribute({
29342
- name: MetaConstants.BottomSheet,
29343
- testID: 'bottomsheet-surface'
29344
- })), makeAccessible({
29345
- modal: true,
29346
- role: 'dialog'
29347
- })), {}, {
29348
- windowHeight: dimensions.height,
29349
- isDragging: isDragging,
29350
- style: {
29351
- opacity: isVisible ? 1 : 0,
29352
- pointerEvents: isVisible ? 'all' : 'none',
29353
- height: positionY,
29354
- bottom: 0,
29355
- top: 'auto',
29356
- zIndex: bottomSheetZIndex
29357
- },
29358
- ref: refs.setFloating,
29359
- children: /*#__PURE__*/jsxs(BaseBox, {
29360
- height: "100%",
29361
- display: "flex",
29362
- flexDirection: "column",
29363
- children: [/*#__PURE__*/jsx(BottomSheetGrabHandle, _objectSpread$f(_objectSpread$f({
29364
- ref: grabHandleRef,
29365
- isHeaderFloating: isHeaderFloating
29366
- }, metaAttribute({
29367
- name: ComponentIds.BottomSheetGrabHandle
29368
- })), bind())), children]
29369
- })
29370
- }))]
29360
+ role: 'dialog'
29361
+ })), {}, {
29362
+ windowHeight: dimensions.height,
29363
+ isDragging: isDragging,
29364
+ style: {
29365
+ opacity: isVisible ? 1 : 0,
29366
+ pointerEvents: isVisible ? 'all' : 'none',
29367
+ height: positionY,
29368
+ bottom: 0,
29369
+ top: 'auto',
29370
+ zIndex: bottomSheetZIndex
29371
+ },
29372
+ children: /*#__PURE__*/jsxs(BaseBox, {
29373
+ height: "100%",
29374
+ display: "flex",
29375
+ flexDirection: "column",
29376
+ children: [/*#__PURE__*/jsx(BottomSheetGrabHandle, _objectSpread$f(_objectSpread$f({
29377
+ ref: grabHandleRef,
29378
+ isHeaderFloating: isHeaderFloating
29379
+ }, metaAttribute({
29380
+ name: ComponentIds.BottomSheetGrabHandle
29381
+ })), bind())), children]
29371
29382
  })
29372
- })
29383
+ }))]
29373
29384
  });
29374
29385
  };
29375
29386
  var BottomSheet = /*#__PURE__*/assignWithoutSideEffects(_BottomSheet, {