@razorpay/blade 10.2.1 → 10.3.0

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.
@@ -14762,33 +14762,55 @@ var SelectorSupportText = function SelectorSupportText(_ref) {
14762
14762
  });
14763
14763
  };
14764
14764
 
14765
+ /* eslint-disable @typescript-eslint/no-explicit-any */
14766
+ function assignRef(ref, value) {
14767
+ if (ref == null) return;
14768
+ if (typeof ref === 'function') {
14769
+ ref(value);
14770
+ return;
14771
+ }
14772
+ try {
14773
+ ref.current = value;
14774
+ } catch (error) {
14775
+ throwBladeError({
14776
+ moduleName: 'useMergeRefs',
14777
+ message: "Cannot assign value '".concat(value, "' to ref '").concat(ref, "'")
14778
+ });
14779
+ }
14780
+ }
14781
+ function mergeRefs() {
14782
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
14783
+ refs[_key] = arguments[_key];
14784
+ }
14785
+ return function (node) {
14786
+ refs.forEach(function (ref) {
14787
+ assignRef(ref, node);
14788
+ });
14789
+ };
14790
+ }
14791
+
14765
14792
  /**
14766
- * A hook which only exposes the properties of html input element via imparative hook
14793
+ * Merged two or more refs into a single ref callback.
14794
+ *
14795
+ * Usage:
14796
+ * ```ts
14797
+ * const internalRef = React.useRef()
14798
+ * const ref = useMergeRefs(incomingRef, internalRef);
14799
+ * ```
14800
+ *
14767
14801
  *
14768
- * It avoids exposing other native properties of HTMLElement
14769
- * like `style` `classList` to avoid unintended usage of refs.
14802
+ * Taken from ChakraUI:
14803
+ * https://github.com/chakra-ui/chakra-ui/blob/f3c4a492e5636d2745b438d10794fa4e7999b6de/packages/hooks/use-merge-refs/src/index.ts#L31
14770
14804
  */
14771
- var useBladeInnerRef = function useBladeInnerRef(targetRef, handlers) {
14772
- var innerRef = React__default.useRef(null);
14773
- React__default.useImperativeHandle(targetRef, function () {
14774
- var element = innerRef.current;
14775
- return {
14776
- focus: function focus(opts) {
14777
- var _element$focus;
14778
- return handlers !== null && handlers !== void 0 && handlers.onFocus ? handlers.onFocus(opts) : element === null || element === void 0 ? void 0 : (_element$focus = element.focus) === null || _element$focus === void 0 ? void 0 : _element$focus.call(element, opts);
14779
- },
14780
- scrollIntoView: function scrollIntoView(opts) {
14781
- var _element$scrollIntoVi;
14782
- return element === null || element === void 0 ? void 0 : (_element$scrollIntoVi = element.scrollIntoView) === null || _element$scrollIntoVi === void 0 ? void 0 : _element$scrollIntoVi.call(element, opts);
14783
- },
14784
- getBoundingClientRect: function getBoundingClientRect() {
14785
- return element === null || element === void 0 ? void 0 : element.getBoundingClientRect();
14786
- },
14787
- clientHeight: element.clientHeight
14788
- };
14789
- }, [innerRef, handlers]);
14790
- return innerRef;
14791
- };
14805
+ function useMergeRefs() {
14806
+ for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
14807
+ refs[_key2] = arguments[_key2];
14808
+ }
14809
+ // eslint-disable-next-line react-hooks/exhaustive-deps
14810
+ return useMemo(function () {
14811
+ return mergeRefs.apply(void 0, refs);
14812
+ }, refs);
14813
+ }
14792
14814
 
14793
14815
  function ownKeys$1n(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
14794
14816
  function _objectSpread$1m(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1n(Object(source), !0).forEach(function (key) { _defineProperty$1(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1n(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -14843,7 +14865,10 @@ var _SelectorInput = function _SelectorInput(_ref3, ref) {
14843
14865
  hoverTokens = _ref3.hoverTokens,
14844
14866
  tabIndex = _ref3.tabIndex,
14845
14867
  accessibilityLabel = _ref3.accessibilityLabel;
14846
- var inputRef = useBladeInnerRef(ref);
14868
+ // merging both refs because inputProps.ref needs to have access to indeterminate state
14869
+ // to be able to set the mixed value via setMixed() function
14870
+ // TODO: replace with a generic `mergeRefs()` util if we do this in other places
14871
+ var mergedRef = useMergeRefs(ref, inputProps.ref);
14847
14872
  return /*#__PURE__*/jsx(StyledInput, _objectSpread$1m(_objectSpread$1m(_objectSpread$1m({
14848
14873
  id: id,
14849
14874
  isChecked: isChecked,
@@ -14854,13 +14879,7 @@ var _SelectorInput = function _SelectorInput(_ref3, ref) {
14854
14879
  }, inputProps), makeAccessible({
14855
14880
  label: accessibilityLabel
14856
14881
  })), {}, {
14857
- // merging both refs because inputProps.ref needs to have access to indeterminate state
14858
- // to be able to set the mixed value via setMixed() function
14859
- // TODO: replace with a generic `mergeRefs()` util if we do this in other places
14860
- ref: function ref(value) {
14861
- inputProps.ref.current = value;
14862
- inputRef.current = value;
14863
- }
14882
+ ref: mergedRef
14864
14883
  }));
14865
14884
  };
14866
14885
  var SelectorInput = /*#__PURE__*/assignWithoutSideEffects( /*#__PURE__*/React__default.forwardRef(_SelectorInput), {
@@ -20901,7 +20920,8 @@ var _TextInput = function _TextInput(_ref2, ref) {
20901
20920
  autoCapitalize = _ref2.autoCapitalize,
20902
20921
  testID = _ref2.testID,
20903
20922
  styledProps = _objectWithoutProperties$1(_ref2, _excluded$h);
20904
- var textInputRef = useBladeInnerRef(ref);
20923
+ var textInputRef = React__default.useRef(null);
20924
+ var mergedRef = useMergeRefs(ref, textInputRef);
20905
20925
  var _useState = useState(false),
20906
20926
  _useState2 = _slicedToArray(_useState, 2),
20907
20927
  shouldShowClearButton = _useState2[0],
@@ -20944,7 +20964,7 @@ var _TextInput = function _TextInput(_ref2, ref) {
20944
20964
  return /*#__PURE__*/jsx(BaseInput, _objectSpread$I(_objectSpread$I({
20945
20965
  id: "textinput",
20946
20966
  componentName: MetaConstants.TextInput,
20947
- ref: textInputRef,
20967
+ ref: mergedRef,
20948
20968
  label: label,
20949
20969
  accessibilityLabel: accessibilityLabel,
20950
20970
  hideLabelText: !Boolean(label),
@@ -21046,7 +21066,6 @@ var _PasswordInput = function _PasswordInput(_ref, ref) {
21046
21066
  autoCompleteSuggestionType = _ref.autoCompleteSuggestionType,
21047
21067
  testID = _ref.testID,
21048
21068
  styledProps = _objectWithoutProperties$1(_ref, _excluded$g);
21049
- var inputRef = useBladeInnerRef(ref);
21050
21069
  var _React$useState = React__default.useState(false),
21051
21070
  _React$useState2 = _slicedToArray(_React$useState, 2),
21052
21071
  isRevealed = _React$useState2[0],
@@ -21081,7 +21100,7 @@ var _PasswordInput = function _PasswordInput(_ref, ref) {
21081
21100
  }) : null;
21082
21101
  };
21083
21102
  return /*#__PURE__*/jsx(BaseInput, _objectSpread$H({
21084
- ref: inputRef,
21103
+ ref: ref,
21085
21104
  componentName: MetaConstants.PasswordInput,
21086
21105
  id: "password-field",
21087
21106
  label: label,
@@ -21157,7 +21176,8 @@ var _TextArea = function _TextArea(_ref, ref) {
21157
21176
  numberOfLines = _ref$numberOfLines === void 0 ? 2 : _ref$numberOfLines,
21158
21177
  testID = _ref.testID,
21159
21178
  styledProps = _objectWithoutProperties$1(_ref, _excluded$f);
21160
- var inputRef = useBladeInnerRef(ref);
21179
+ var inputRef = React__default.useRef(null);
21180
+ var mergedRef = useMergeRefs(ref, inputRef);
21161
21181
  var _React$useState = React__default.useState(false),
21162
21182
  _React$useState2 = _slicedToArray(_React$useState, 2),
21163
21183
  shouldShowClearButton = _React$useState2[0],
@@ -21200,7 +21220,7 @@ var _TextArea = function _TextArea(_ref, ref) {
21200
21220
  id: "textarea",
21201
21221
  componentName: MetaConstants.TextArea,
21202
21222
  autoFocus: autoFocus,
21203
- ref: inputRef,
21223
+ ref: mergedRef,
21204
21224
  label: label,
21205
21225
  accessibilityLabel: accessibilityLabel,
21206
21226
  hideLabelText: !Boolean(label),
@@ -21629,12 +21649,6 @@ var _SelectInput = function _SelectInput(props, ref) {
21629
21649
  setIsControlled = _useDropdown.setIsControlled,
21630
21650
  selectionType = _useDropdown.selectionType,
21631
21651
  selectedIndices = _useDropdown.selectedIndices;
21632
- var inputRef = useBladeInnerRef(ref, {
21633
- onFocus: function onFocus(opts) {
21634
- var _triggererRef$current;
21635
- (_triggererRef$current = triggererRef.current) === null || _triggererRef$current === void 0 ? void 0 : _triggererRef$current.focus(opts);
21636
- }
21637
- });
21638
21652
  var icon = props.icon;
21639
21653
  props.onChange;
21640
21654
  props.defaultValue;
@@ -21725,7 +21739,11 @@ var _SelectInput = function _SelectInput(props, ref) {
21725
21739
  position: "relative",
21726
21740
  children: [!isReactNative$4() ? /*#__PURE__*/jsx(VisuallyHidden, {
21727
21741
  children: /*#__PURE__*/jsx("input", {
21728
- ref: inputRef,
21742
+ onFocus: function onFocus() {
21743
+ var _triggererRef$current;
21744
+ (_triggererRef$current = triggererRef.current) === null || _triggererRef$current === void 0 ? void 0 : _triggererRef$current.focus();
21745
+ },
21746
+ ref: ref,
21729
21747
  tabIndex: -1,
21730
21748
  required: props.isRequired,
21731
21749
  name: props.name,