@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.
@@ -29495,6 +29495,7 @@ var _BottomSheet = function _BottomSheet(_ref2) {
29495
29495
  var scrollRef = React__default.useRef(null);
29496
29496
  var grabHandleRef = React__default.useRef(null);
29497
29497
  var defaultInitialFocusRef = React__default.useRef(null);
29498
+ var originalFocusElement = React__default.useRef(null);
29498
29499
  var initialSnapPoint = React__default.useRef(snapPoints[1]);
29499
29500
  var totalHeight = React__default.useMemo(function () {
29500
29501
  return grabHandleHeight + headerHeight + footerHeight + contentHeight;
@@ -29559,17 +29560,43 @@ var _BottomSheet = function _BottomSheet(_ref2) {
29559
29560
  }
29560
29561
  }
29561
29562
  }, [dimensions.height, snapPoints, totalHeight]);
29563
+ var returnFocus = React__default.useCallback(function () {
29564
+ if (!originalFocusElement.current) return;
29565
+ originalFocusElement.current.focus();
29566
+ // After returning focus we will clear the original focus
29567
+ // Because if sheet can be opened up via multiple triggers
29568
+ // We want to ensure the focus returns back to the most recent triggerer
29569
+ originalFocusElement.current = null;
29570
+ }, [originalFocusElement]);
29571
+ var focusOnInitialRef = React__default.useCallback(function () {
29572
+ if (!initialFocusRef) {
29573
+ var _defaultInitialFocusR;
29574
+ // focus on close button
29575
+ (_defaultInitialFocusR = defaultInitialFocusRef.current) === null || _defaultInitialFocusR === void 0 ? void 0 : _defaultInitialFocusR.focus();
29576
+ } else {
29577
+ var _initialFocusRef$curr;
29578
+ // focus on the initialRef passed by the user
29579
+ (_initialFocusRef$curr = initialFocusRef.current) === null || _initialFocusRef$curr === void 0 ? void 0 : _initialFocusRef$curr.focus();
29580
+ }
29581
+ }, [initialFocusRef]);
29562
29582
  var handleOnOpen = React__default.useCallback(function () {
29583
+ var _originalFocusElement;
29563
29584
  setPositionY(dimensions.height * initialSnapPoint.current);
29564
29585
  scrollLockRef.current.activate();
29565
- }, [dimensions.height, scrollLockRef, setPositionY]);
29586
+ // initialize the original focused element
29587
+ // On first render it will be the activeElement, eg: the button trigger or select input
29588
+ // On Subsequent open operations it won't further update the original focus
29589
+ originalFocusElement.current = (_originalFocusElement = originalFocusElement.current) !== null && _originalFocusElement !== void 0 ? _originalFocusElement : document.activeElement;
29590
+ focusOnInitialRef();
29591
+ }, [dimensions.height, focusOnInitialRef, scrollLockRef, setPositionY]);
29566
29592
  var handleOnClose = React__default.useCallback(function () {
29567
29593
  setPositionY(0);
29568
29594
  }, [setPositionY]);
29569
29595
  var close = React__default.useCallback(function () {
29570
29596
  onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss();
29571
29597
  bottomSheetAndDropdownGlue === null || bottomSheetAndDropdownGlue === void 0 ? void 0 : bottomSheetAndDropdownGlue.onBottomSheetDismiss();
29572
- }, [bottomSheetAndDropdownGlue, onDismiss]);
29598
+ returnFocus();
29599
+ }, [bottomSheetAndDropdownGlue, onDismiss, returnFocus]);
29573
29600
 
29574
29601
  // sync controlled state to our actions
29575
29602
  React__default.useEffect(function () {
@@ -29776,13 +29803,6 @@ var _BottomSheet = function _BottomSheet(_ref2) {
29776
29803
  }
29777
29804
  }, [isMounted, scrollLockRef]);
29778
29805
 
29779
- // required by floating ui to handle focus
29780
- var _useFloating = useFloating({
29781
- open: isMounted
29782
- }),
29783
- refs = _useFloating.refs,
29784
- context = _useFloating.context;
29785
-
29786
29806
  // We don't want to destroy the react tree when we are rendering inside Dropdown
29787
29807
  // Because if we bail out early then ActionList won't render,
29788
29808
  // and Dropdown manages it's state based on the rendered JSX of ActionList
@@ -29791,48 +29811,39 @@ var _BottomSheet = function _BottomSheet(_ref2) {
29791
29811
  if (!isMounted && !isInsideDropdown) {
29792
29812
  return /*#__PURE__*/jsx(Fragment, {});
29793
29813
  }
29794
- return /*#__PURE__*/jsx(BottomSheetContext.Provider, {
29814
+ return /*#__PURE__*/jsxs(BottomSheetContext.Provider, {
29795
29815
  value: contextValue,
29796
- children: (isMounted || isInsideDropdown) && /*#__PURE__*/jsx(FloatingFocusManager, {
29797
- returnFocus: true,
29798
- initialFocus: initialFocusRef !== null && initialFocusRef !== void 0 ? initialFocusRef : defaultInitialFocusRef,
29799
- context: context,
29816
+ children: [/*#__PURE__*/jsx(BottomSheetBackdrop, {
29817
+ zIndex: bottomSheetZIndex
29818
+ }), /*#__PURE__*/jsx(BottomSheetSurface, _objectSpread$f(_objectSpread$f(_objectSpread$f({}, metaAttribute({
29819
+ name: MetaConstants.BottomSheet,
29820
+ testID: 'bottomsheet-surface'
29821
+ })), makeAccessible({
29800
29822
  modal: true,
29801
- children: /*#__PURE__*/jsxs(Fragment, {
29802
- children: [/*#__PURE__*/jsx(BottomSheetBackdrop, {
29803
- zIndex: bottomSheetZIndex
29804
- }), /*#__PURE__*/jsx(BottomSheetSurface, _objectSpread$f(_objectSpread$f(_objectSpread$f({}, metaAttribute({
29805
- name: MetaConstants.BottomSheet,
29806
- testID: 'bottomsheet-surface'
29807
- })), makeAccessible({
29808
- modal: true,
29809
- role: 'dialog'
29810
- })), {}, {
29811
- windowHeight: dimensions.height,
29812
- isDragging: isDragging,
29813
- style: {
29814
- opacity: isVisible ? 1 : 0,
29815
- pointerEvents: isVisible ? 'all' : 'none',
29816
- height: positionY,
29817
- bottom: 0,
29818
- top: 'auto',
29819
- zIndex: bottomSheetZIndex
29820
- },
29821
- ref: refs.setFloating,
29822
- children: /*#__PURE__*/jsxs(BaseBox, {
29823
- height: "100%",
29824
- display: "flex",
29825
- flexDirection: "column",
29826
- children: [/*#__PURE__*/jsx(BottomSheetGrabHandle, _objectSpread$f(_objectSpread$f({
29827
- ref: grabHandleRef,
29828
- isHeaderFloating: isHeaderFloating
29829
- }, metaAttribute({
29830
- name: ComponentIds.BottomSheetGrabHandle
29831
- })), bind())), children]
29832
- })
29833
- }))]
29823
+ role: 'dialog'
29824
+ })), {}, {
29825
+ windowHeight: dimensions.height,
29826
+ isDragging: isDragging,
29827
+ style: {
29828
+ opacity: isVisible ? 1 : 0,
29829
+ pointerEvents: isVisible ? 'all' : 'none',
29830
+ height: positionY,
29831
+ bottom: 0,
29832
+ top: 'auto',
29833
+ zIndex: bottomSheetZIndex
29834
+ },
29835
+ children: /*#__PURE__*/jsxs(BaseBox, {
29836
+ height: "100%",
29837
+ display: "flex",
29838
+ flexDirection: "column",
29839
+ children: [/*#__PURE__*/jsx(BottomSheetGrabHandle, _objectSpread$f(_objectSpread$f({
29840
+ ref: grabHandleRef,
29841
+ isHeaderFloating: isHeaderFloating
29842
+ }, metaAttribute({
29843
+ name: ComponentIds.BottomSheetGrabHandle
29844
+ })), bind())), children]
29834
29845
  })
29835
- })
29846
+ }))]
29836
29847
  });
29837
29848
  };
29838
29849
  var BottomSheet = /*#__PURE__*/assignWithoutSideEffects(_BottomSheet, {