@thecb/components 6.0.0-beta.1 → 6.0.0-beta.4

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
@@ -19468,7 +19468,10 @@ var Dropdown = function Dropdown(_ref9) {
19468
19468
  widthFitOptions = _ref9$widthFitOptions === void 0 ? false : _ref9$widthFitOptions,
19469
19469
  disabled = _ref9.disabled,
19470
19470
  _ref9$hasTitles = _ref9.hasTitles,
19471
- hasTitles = _ref9$hasTitles === void 0 ? false : _ref9$hasTitles;
19471
+ hasTitles = _ref9$hasTitles === void 0 ? false : _ref9$hasTitles,
19472
+ _ref9$autoEraseTypeAh = _ref9.autoEraseTypeAhead,
19473
+ autoEraseTypeAhead = _ref9$autoEraseTypeAh === void 0 ? true : _ref9$autoEraseTypeAh,
19474
+ ariaLabelledby = _ref9.ariaLabelledby;
19472
19475
 
19473
19476
  var _useState = React.useState(""),
19474
19477
  _useState2 = _slicedToArray(_useState, 2),
@@ -19490,6 +19493,11 @@ var Dropdown = function Dropdown(_ref9) {
19490
19493
  optionsChanged = _useState8[0],
19491
19494
  setOptionsChanged = _useState8[1];
19492
19495
 
19496
+ var _useState9 = React.useState(undefined),
19497
+ _useState10 = _slicedToArray(_useState9, 2),
19498
+ selectedRef = _useState10[0],
19499
+ setSelectedRef = _useState10[1];
19500
+
19493
19501
  if (optionsState !== options) {
19494
19502
  setOptionsState(options);
19495
19503
  setOptionsChanged(true);
@@ -19500,10 +19508,10 @@ var Dropdown = function Dropdown(_ref9) {
19500
19508
  setOptionsChanged(false);
19501
19509
  }
19502
19510
 
19503
- var _useState9 = React.useState(null),
19504
- _useState10 = _slicedToArray(_useState9, 2),
19505
- timer = _useState10[0],
19506
- setTimer = _useState10[1];
19511
+ var _useState11 = React.useState(null),
19512
+ _useState12 = _slicedToArray(_useState11, 2),
19513
+ timer = _useState12[0],
19514
+ setTimer = _useState12[1];
19507
19515
 
19508
19516
  var optionRefs = React.useRef(_toConsumableArray(Array(options.length)).map(function () {
19509
19517
  return /*#__PURE__*/React.createRef();
@@ -19519,6 +19527,8 @@ var Dropdown = function Dropdown(_ref9) {
19519
19527
  };
19520
19528
 
19521
19529
  var onKeyDown = function onKeyDown(e) {
19530
+ var _optionRefs$current$l, _optionRefs$current;
19531
+
19522
19532
  var key = e.key,
19523
19533
  keyCode = e.keyCode;
19524
19534
  var focus = document.activeElement;
@@ -19574,6 +19584,16 @@ var Dropdown = function Dropdown(_ref9) {
19574
19584
  e.preventDefault();
19575
19585
  setInputValue(inputValue.slice(0, -1));
19576
19586
  break;
19587
+
19588
+ case "Home":
19589
+ e.preventDefault();
19590
+ optionRefs.current[0].current.focus();
19591
+ break;
19592
+
19593
+ case "End":
19594
+ e.preventDefault();
19595
+ optionRefs.current[(_optionRefs$current$l = optionRefs === null || optionRefs === void 0 ? void 0 : (_optionRefs$current = optionRefs.current) === null || _optionRefs$current === void 0 ? void 0 : _optionRefs$current.length) !== null && _optionRefs$current$l !== void 0 ? _optionRefs$current$l : 0 - 1].current.focus();
19596
+ break;
19577
19597
  }
19578
19598
 
19579
19599
  if (keyCode > 64 && keyCode < 91 || keyCode == 32 || keyCode == 189) {
@@ -19583,7 +19603,15 @@ var Dropdown = function Dropdown(_ref9) {
19583
19603
  };
19584
19604
 
19585
19605
  React.useEffect(function () {
19586
- if (isOpen && optionRefs.current[0].current) {
19606
+ console.log("option refs in isopen useffect", optionRefs.current[0].current);
19607
+ console.log("selected refs in isopen useffect", selectedRef);
19608
+ console.log("value in isopen useffect", value);
19609
+
19610
+ if (isOpen && selectedRef !== undefined) {
19611
+ // WAI-ARIA requires the selected option to receive focus
19612
+ selectedRef.current.focus();
19613
+ } else if (isOpen && optionRefs.current[0].current) {
19614
+ // If no selected option, first option receives focus
19587
19615
  optionRefs.current[0].current.focus();
19588
19616
  }
19589
19617
 
@@ -19591,10 +19619,13 @@ var Dropdown = function Dropdown(_ref9) {
19591
19619
  setInputValue("");
19592
19620
  }, [isOpen]);
19593
19621
  React.useEffect(function () {
19594
- clearTimeout(timer);
19595
- setTimer(setTimeout(function () {
19596
- return setInputValue("");
19597
- }, 2000));
19622
+ if (autoEraseTypeAhead) {
19623
+ clearTimeout(timer);
19624
+ setTimer(setTimeout(function () {
19625
+ return setInputValue("");
19626
+ }, 2000));
19627
+ }
19628
+
19598
19629
  setFilteredOptions(options.filter(function (option) {
19599
19630
  return option.value.toLowerCase().startsWith(inputValue.toLowerCase()) || option.text.toLowerCase().startsWith(inputValue.toLowerCase());
19600
19631
  }));
@@ -19617,6 +19648,10 @@ var Dropdown = function Dropdown(_ref9) {
19617
19648
  width: "100%",
19618
19649
  hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19619
19650
  "aria-expanded": isOpen,
19651
+ role: "combobox",
19652
+ "aria-owns": "".concat(ariaLabelledby, "_listbox"),
19653
+ "aria-haspopup": "listbox",
19654
+ "aria-labelledby": ariaLabelledby,
19620
19655
  extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
19621
19656
  title: hasTitles ? getSelection() : null
19622
19657
  }, /*#__PURE__*/React__default.createElement(Box, {
@@ -19628,32 +19663,43 @@ var Dropdown = function Dropdown(_ref9) {
19628
19663
  borderSize: "1px",
19629
19664
  borderColor: isError ? ERROR_COLOR : isOpen ? themeValues.selectedColor : GREY_CHATEAU,
19630
19665
  borderRadius: "2px",
19631
- tabIndex: 0,
19632
19666
  dataQa: placeholder,
19633
19667
  extraStyles: "height: 48px;\n ".concat(disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;", "\n ")
19634
19668
  }, /*#__PURE__*/React__default.createElement(Stack, {
19635
19669
  direction: "row",
19636
19670
  bottomItem: 2
19637
- }, isOpen ? /*#__PURE__*/React__default.createElement(SearchInput, {
19638
- "aria-label": inputValue || "Dropdown awaiting search value",
19671
+ }, /*#__PURE__*/React__default.createElement(SearchInput, {
19672
+ "aria-label": getSelection(),
19673
+ placeholder: getSelection(),
19639
19674
  value: inputValue,
19640
19675
  onChange: noop,
19641
- themeValues: themeValues
19642
- }) : /*#__PURE__*/React__default.createElement(Text$1, {
19643
- variant: "p",
19644
- extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;"
19645
- }, getSelection()), /*#__PURE__*/React__default.createElement(IconWrapper, {
19676
+ themeValues: themeValues,
19677
+ role: "searchbox",
19678
+ type: "text",
19679
+ "aria-multiline": "false",
19680
+ "aria-autocomplete": "list",
19681
+ "aria-controls": "".concat(ariaLabelledby, "_listbox"),
19682
+ "aria-activedescendant": "selected_option",
19683
+ tabIndex: 0
19684
+ }), /*#__PURE__*/React__default.createElement(IconWrapper, {
19646
19685
  open: isOpen
19647
19686
  }, /*#__PURE__*/React__default.createElement(DropdownIcon, null)))), isOpen ? /*#__PURE__*/React__default.createElement(DropdownContentWrapper, {
19648
19687
  maxHeight: maxHeight,
19649
19688
  open: isOpen,
19650
19689
  ref: dropdownRef,
19651
19690
  widthFitOptions: widthFitOptions,
19652
- tabIndex: 0
19691
+ tabIndex: 0,
19692
+ role: "listbox",
19693
+ id: "".concat(ariaLabelledby, "_listbox")
19653
19694
  }, /*#__PURE__*/React__default.createElement(Stack, {
19654
19695
  childGap: "0"
19655
19696
  }, filteredOptions.map(function (choice, i) {
19697
+ if (selectedRef === undefined && choice.value === value) {
19698
+ setSelectedRef(optionRefs.current[i]);
19699
+ }
19700
+
19656
19701
  return /*#__PURE__*/React__default.createElement(DropdownItemWrapper, {
19702
+ id: choice.value === value ? "selected_option" : choice.value,
19657
19703
  key: choice.value,
19658
19704
  ref: optionRefs.current[i],
19659
19705
  as: "button",
@@ -19664,10 +19710,12 @@ var Dropdown = function Dropdown(_ref9) {
19664
19710
  return onSelect(choice.value);
19665
19711
  },
19666
19712
  selected: choice.value === value,
19713
+ "aria-selected": choice.value === value,
19667
19714
  disabled: disabledValues.includes(choice.value),
19668
19715
  "data-qa": choice.text,
19669
19716
  themeValues: themeValues,
19670
- title: hasTitles ? choice.text : null
19717
+ title: hasTitles ? choice.text : null,
19718
+ role: "option"
19671
19719
  }, /*#__PURE__*/React__default.createElement(Text$1, {
19672
19720
  variant: "p",
19673
19721
  color: choice.value === value ? WHITE : disabledValues.includes(choice.value) ? STORM_GREY : MINESHAFT_GREY,
@@ -19812,7 +19860,7 @@ var FormSelect = function FormSelect(_ref) {
19812
19860
  extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
19813
19861
  id: labelTextWhenNoError.replace(/\s+/g, "-")
19814
19862
  }, labelTextWhenNoError))), /*#__PURE__*/React__default.createElement(Dropdown$1, {
19815
- "aria-labelledby": labelTextWhenNoError.replace(/\s+/g, "-"),
19863
+ ariaLabelledby: labelTextWhenNoError.replace(/\s+/g, "-"),
19816
19864
  maxHeight: dropdownMaxHeight,
19817
19865
  hasTitles: hasTitles,
19818
19866
  placeholder: options[0] ? options[0].text : "",