@thecb/components 6.0.0-beta.28 → 6.0.0-beta.30

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.cjs.js CHANGED
@@ -20752,6 +20752,11 @@ var Dropdown = function Dropdown(_ref8) {
20752
20752
  inputChangedByAutofill = _useState14[0],
20753
20753
  setInputChangedByAutofill = _useState14[1];
20754
20754
 
20755
+ var _useState15 = React.useState(false),
20756
+ _useState16 = _slicedToArray(_useState15, 2),
20757
+ focusedByClick = _useState16[0],
20758
+ setFocusedByClick = _useState16[1];
20759
+
20755
20760
  if (optionsState !== options) {
20756
20761
  setOptionsState(options);
20757
20762
  setOptionsChanged(true);
@@ -20762,10 +20767,10 @@ var Dropdown = function Dropdown(_ref8) {
20762
20767
  setOptionsChanged(false);
20763
20768
  }
20764
20769
 
20765
- var _useState15 = React.useState(null),
20766
- _useState16 = _slicedToArray(_useState15, 2),
20767
- timer = _useState16[0],
20768
- setTimer = _useState16[1];
20770
+ var _useState17 = React.useState(null),
20771
+ _useState18 = _slicedToArray(_useState17, 2),
20772
+ timer = _useState18[0],
20773
+ setTimer = _useState18[1];
20769
20774
 
20770
20775
  var optionRefs = React.useRef(_toConsumableArray(Array(options.length)).map(function () {
20771
20776
  return /*#__PURE__*/React.createRef();
@@ -20880,14 +20885,23 @@ var Dropdown = function Dropdown(_ref8) {
20880
20885
  };
20881
20886
 
20882
20887
  React.useEffect(function () {
20883
- if (isOpen && selectedRef !== undefined && selectedRef.current !== null) {
20888
+ var selectedRefExists = selectedRef !== undefined && selectedRef.current !== null;
20889
+
20890
+ if (isOpen && selectedRefExists && !focusedByClick) {
20884
20891
  // WAI-ARIA requires the selected option to receive focus
20885
20892
  selectedRef.current.focus();
20886
- console.log("input box ref", inputRef, inputRef.current);
20887
- } else if (isOpen && optionRefs.current[0].current) {
20893
+ } else if (isOpen && optionRefs.current[0].current && !focusedByClick) {
20888
20894
  // If no selected option, first option receives focus
20889
20895
  optionRefs.current[0].current.focus();
20890
- console.log("input box ref", inputRef, inputRef.current);
20896
+ }
20897
+
20898
+ if (isOpen && focusedByClick && selectedRefExists) {
20899
+ selectedRef.current.scrollIntoView({
20900
+ behavior: "smooth",
20901
+ block: "nearest",
20902
+ inline: "start"
20903
+ });
20904
+ setFocusedByClick(false);
20891
20905
  }
20892
20906
 
20893
20907
  clearTimeout(timer);
@@ -20936,6 +20950,8 @@ var Dropdown = function Dropdown(_ref8) {
20936
20950
  minWidth: "100%",
20937
20951
  onClick: function onClick() {
20938
20952
  if (!isOpen) {
20953
+ setFocusedByClick(true);
20954
+
20939
20955
  _onClick();
20940
20956
  }
20941
20957
  },