@razorpay/blade 10.14.0 → 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.
@@ -15051,7 +15051,7 @@ var StyledInput = /*#__PURE__*/styled.input.withConfig({
15051
15051
  hasError = _ref2.hasError,
15052
15052
  hoverTokens = _ref2.hoverTokens;
15053
15053
  return _objectSpread$1w(_objectSpread$1w({}, screenReaderStyles), {}, {
15054
- '&:focus + div': {
15054
+ '&:focus-visible + div': {
15055
15055
  // TODO: Replace with focus outline token
15056
15056
  outline: "1px solid ".concat(theme.colors.surface.background.level1.lowContrast),
15057
15057
  boxShadow: "0px 0px 0px 4px ".concat(theme.colors.brand.primary[400])
@@ -15980,7 +15980,7 @@ var StyledButton = /*#__PURE__*/styled.button.withConfig({
15980
15980
  '&:hover': {
15981
15981
  color: iconColorToken.hover[contrastToken]
15982
15982
  },
15983
- '&:focus': {
15983
+ '&:focus-visible': {
15984
15984
  outline: 'none',
15985
15985
  boxShadow: "0px 0px 0px 4px ".concat(theme.colors.brand.primary[400]),
15986
15986
  color: iconColorToken.focus[contrastToken]
@@ -16851,7 +16851,7 @@ var StyledLink$1 = /*#__PURE__*/styled.button.withConfig({
16851
16851
  width: 'max-content',
16852
16852
  borderRadius: makeBorderSize(props.theme.border.radius.small)
16853
16853
  },
16854
- '&:focus': {
16854
+ '&:focus-visible': {
16855
16855
  '.content-container': {
16856
16856
  boxShadow: "0px 0px 0px 4px ".concat(props.focusRingColor)
16857
16857
  }
@@ -18580,7 +18580,7 @@ var getIndicatorButtonStyles = function getIndicatorButtonStyles(_ref) {
18580
18580
  padding: makeSize(size[10]),
18581
18581
  paddingTop: makeSize(size[20])
18582
18582
  },
18583
- '&:focus': {
18583
+ '&:focus-visible': {
18584
18584
  // TODO: refactor to use focus ring token
18585
18585
  outline: 'none',
18586
18586
  boxShadow: "0px 0px 0px 4px ".concat(theme.colors.brand.primary[400])
@@ -18724,7 +18724,7 @@ var getNavigationButtonStyles = function getNavigationButtonStyles(props) {
18724
18724
  borderColor: borderColorToken.hover,
18725
18725
  backgroundColor: backgroundColor[variant].hover
18726
18726
  },
18727
- '&:focus': {
18727
+ '&:focus-visible': {
18728
18728
  // TODO: refactor to use focus ring token
18729
18729
  outline: 'none',
18730
18730
  boxShadow: "0px 0px 0px 4px ".concat(theme.colors.brand.primary[400]),
@@ -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, {
@@ -29513,7 +29524,7 @@ var StyledAccordionButton = /*#__PURE__*/styled.button.withConfig({
29513
29524
  width: '100%',
29514
29525
  border: 'none',
29515
29526
  textAlign: 'left',
29516
- '&:hover, &:focus': {
29527
+ '&:hover, &:focus-visible': {
29517
29528
  backgroundColor: getBackgroundColor({
29518
29529
  theme: theme,
29519
29530
  isExpanded: isExpanded,
@@ -29523,7 +29534,7 @@ var StyledAccordionButton = /*#__PURE__*/styled.button.withConfig({
29523
29534
  '&:hover': {
29524
29535
  color: theme.colors.surface.action.icon.hover.lowContrast
29525
29536
  },
29526
- '&:focus': {
29537
+ '&:focus-visible': {
29527
29538
  outline: 'none',
29528
29539
  boxShadow: "0px 0px 0px 4px ".concat(theme.colors.brand.primary[400]),
29529
29540
  // only need border radius on the focus ring
@@ -30653,7 +30664,7 @@ var StyledPopoverInteractiveWrapper = /*#__PURE__*/styled.button.withConfig({
30653
30664
  appearance: 'none',
30654
30665
  cursor: 'pointer',
30655
30666
  lineHeight: 0,
30656
- '&:focus': {
30667
+ '&:focus-visible': {
30657
30668
  // TODO: refactor to use focus ring token
30658
30669
  outline: 'none',
30659
30670
  boxShadow: "0px 0px 0px 4px ".concat(props.theme.colors.brand.primary[400])