@thecb/components 6.0.0-beta.2 → 6.0.0-beta.5

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.esm.js CHANGED
@@ -19438,9 +19438,10 @@ var DropdownItemWrapper = styled.div.withConfig({
19438
19438
  var SearchInput = styled.input.withConfig({
19439
19439
  displayName: "Dropdown__SearchInput",
19440
19440
  componentId: "sc-pn6m0h-3"
19441
- })(["border:none;background-color:", ";font-size:16px;height:24px;"], function (_ref8) {
19442
- var themeValues = _ref8.themeValues;
19443
- return themeValues.hoverColor && themeValues.hoverColor;
19441
+ })(["border:none;background-color:", ";font-size:16px;height:24px;min-width:75%;"], function (_ref8) {
19442
+ var themeValues = _ref8.themeValues,
19443
+ isOpen = _ref8.isOpen;
19444
+ return isOpen ? themeValues.hoverColor && themeValues.hoverColor : "WHITE";
19444
19445
  });
19445
19446
 
19446
19447
  var Dropdown = function Dropdown(_ref9) {
@@ -19460,7 +19461,10 @@ var Dropdown = function Dropdown(_ref9) {
19460
19461
  widthFitOptions = _ref9$widthFitOptions === void 0 ? false : _ref9$widthFitOptions,
19461
19462
  disabled = _ref9.disabled,
19462
19463
  _ref9$hasTitles = _ref9.hasTitles,
19463
- hasTitles = _ref9$hasTitles === void 0 ? false : _ref9$hasTitles;
19464
+ hasTitles = _ref9$hasTitles === void 0 ? false : _ref9$hasTitles,
19465
+ _ref9$autoEraseTypeAh = _ref9.autoEraseTypeAhead,
19466
+ autoEraseTypeAhead = _ref9$autoEraseTypeAh === void 0 ? true : _ref9$autoEraseTypeAh,
19467
+ ariaLabelledby = _ref9.ariaLabelledby;
19464
19468
 
19465
19469
  var _useState = useState(""),
19466
19470
  _useState2 = _slicedToArray(_useState, 2),
@@ -19482,6 +19486,11 @@ var Dropdown = function Dropdown(_ref9) {
19482
19486
  optionsChanged = _useState8[0],
19483
19487
  setOptionsChanged = _useState8[1];
19484
19488
 
19489
+ var _useState9 = useState(undefined),
19490
+ _useState10 = _slicedToArray(_useState9, 2),
19491
+ selectedRef = _useState10[0],
19492
+ setSelectedRef = _useState10[1];
19493
+
19485
19494
  if (optionsState !== options) {
19486
19495
  setOptionsState(options);
19487
19496
  setOptionsChanged(true);
@@ -19492,10 +19501,10 @@ var Dropdown = function Dropdown(_ref9) {
19492
19501
  setOptionsChanged(false);
19493
19502
  }
19494
19503
 
19495
- var _useState9 = useState(null),
19496
- _useState10 = _slicedToArray(_useState9, 2),
19497
- timer = _useState10[0],
19498
- setTimer = _useState10[1];
19504
+ var _useState11 = useState(null),
19505
+ _useState12 = _slicedToArray(_useState11, 2),
19506
+ timer = _useState12[0],
19507
+ setTimer = _useState12[1];
19499
19508
 
19500
19509
  var optionRefs = useRef(_toConsumableArray(Array(options.length)).map(function () {
19501
19510
  return /*#__PURE__*/createRef();
@@ -19511,6 +19520,8 @@ var Dropdown = function Dropdown(_ref9) {
19511
19520
  };
19512
19521
 
19513
19522
  var onKeyDown = function onKeyDown(e) {
19523
+ var _optionRefs$current$l, _optionRefs$current;
19524
+
19514
19525
  var key = e.key,
19515
19526
  keyCode = e.keyCode;
19516
19527
  var focus = document.activeElement;
@@ -19564,10 +19575,18 @@ var Dropdown = function Dropdown(_ref9) {
19564
19575
 
19565
19576
  case "Backspace" :
19566
19577
  e.preventDefault();
19567
- console.log("input value is", inputValue);
19568
- console.log("new input value will be", inputValue.slice(0, -1));
19569
19578
  setInputValue(inputValue.slice(0, -1));
19570
19579
  break;
19580
+
19581
+ case "Home":
19582
+ e.preventDefault();
19583
+ optionRefs.current[0].current.focus();
19584
+ break;
19585
+
19586
+ case "End":
19587
+ e.preventDefault();
19588
+ 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();
19589
+ break;
19571
19590
  }
19572
19591
 
19573
19592
  if (keyCode > 64 && keyCode < 91 || keyCode == 32 || keyCode == 189) {
@@ -19578,9 +19597,14 @@ var Dropdown = function Dropdown(_ref9) {
19578
19597
 
19579
19598
  useEffect$1(function () {
19580
19599
  console.log("option refs in isopen useffect", optionRefs.current[0].current);
19600
+ console.log("selected refs in isopen useffect", selectedRef);
19581
19601
  console.log("value in isopen useffect", value);
19582
19602
 
19583
- if (isOpen && optionRefs.current[0].current) {
19603
+ if (isOpen && selectedRef !== undefined) {
19604
+ // WAI-ARIA requires the selected option to receive focus
19605
+ selectedRef.current.focus();
19606
+ } else if (isOpen && optionRefs.current[0].current) {
19607
+ // If no selected option, first option receives focus
19584
19608
  optionRefs.current[0].current.focus();
19585
19609
  }
19586
19610
 
@@ -19588,10 +19612,13 @@ var Dropdown = function Dropdown(_ref9) {
19588
19612
  setInputValue("");
19589
19613
  }, [isOpen]);
19590
19614
  useEffect$1(function () {
19591
- clearTimeout(timer);
19592
- setTimer(setTimeout(function () {
19593
- return setInputValue("");
19594
- }, 2000));
19615
+ if (autoEraseTypeAhead) {
19616
+ clearTimeout(timer);
19617
+ setTimer(setTimeout(function () {
19618
+ return setInputValue("");
19619
+ }, 2000));
19620
+ }
19621
+
19595
19622
  setFilteredOptions(options.filter(function (option) {
19596
19623
  return option.value.toLowerCase().startsWith(inputValue.toLowerCase()) || option.text.toLowerCase().startsWith(inputValue.toLowerCase());
19597
19624
  }));
@@ -19614,6 +19641,10 @@ var Dropdown = function Dropdown(_ref9) {
19614
19641
  width: "100%",
19615
19642
  hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19616
19643
  "aria-expanded": isOpen,
19644
+ role: "combobox",
19645
+ "aria-owns": "".concat(ariaLabelledby, "_listbox"),
19646
+ "aria-haspopup": "listbox",
19647
+ "aria-labelledby": ariaLabelledby,
19617
19648
  extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
19618
19649
  title: hasTitles ? getSelection() : null
19619
19650
  }, /*#__PURE__*/React.createElement(Box, {
@@ -19631,26 +19662,38 @@ var Dropdown = function Dropdown(_ref9) {
19631
19662
  }, /*#__PURE__*/React.createElement(Stack, {
19632
19663
  direction: "row",
19633
19664
  bottomItem: 2
19634
- }, isOpen ? /*#__PURE__*/React.createElement(SearchInput, {
19635
- "aria-label": inputValue || "Dropdown awaiting search value",
19665
+ }, /*#__PURE__*/React.createElement(SearchInput, {
19666
+ "aria-label": getSelection(),
19667
+ placeholder: getSelection(),
19636
19668
  value: inputValue,
19637
19669
  onChange: noop,
19638
- themeValues: themeValues
19639
- }) : /*#__PURE__*/React.createElement(Text$1, {
19640
- variant: "p",
19641
- extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;"
19642
- }, getSelection()), /*#__PURE__*/React.createElement(IconWrapper, {
19670
+ themeValues: themeValues,
19671
+ role: "searchbox",
19672
+ type: "text",
19673
+ "aria-multiline": "false",
19674
+ "aria-autocomplete": "list",
19675
+ "aria-controls": "".concat(ariaLabelledby, "_listbox"),
19676
+ "aria-activedescendant": "selected_option",
19677
+ isOpen: isOpen
19678
+ }), /*#__PURE__*/React.createElement(IconWrapper, {
19643
19679
  open: isOpen
19644
19680
  }, /*#__PURE__*/React.createElement(DropdownIcon, null)))), isOpen ? /*#__PURE__*/React.createElement(DropdownContentWrapper, {
19645
19681
  maxHeight: maxHeight,
19646
19682
  open: isOpen,
19647
19683
  ref: dropdownRef,
19648
19684
  widthFitOptions: widthFitOptions,
19649
- tabIndex: 0
19685
+ tabIndex: 0,
19686
+ role: "listbox",
19687
+ id: "".concat(ariaLabelledby, "_listbox")
19650
19688
  }, /*#__PURE__*/React.createElement(Stack, {
19651
19689
  childGap: "0"
19652
19690
  }, filteredOptions.map(function (choice, i) {
19691
+ if (choice.value === value && selectedRef !== optionRefs.current[i]) {
19692
+ setSelectedRef(optionRefs.current[i]);
19693
+ }
19694
+
19653
19695
  return /*#__PURE__*/React.createElement(DropdownItemWrapper, {
19696
+ id: choice.value === value ? "selected_option" : choice.value,
19654
19697
  key: choice.value,
19655
19698
  ref: optionRefs.current[i],
19656
19699
  as: "button",
@@ -19658,13 +19701,16 @@ var Dropdown = function Dropdown(_ref9) {
19658
19701
  onClick: disabledValues.includes(choice.value) ? function (evt) {
19659
19702
  return evt.preventDefault();
19660
19703
  } : function () {
19661
- return onSelect(choice.value);
19704
+ setSelectedRef(optionRefs.current[i]);
19705
+ onSelect(choice.value);
19662
19706
  },
19663
19707
  selected: choice.value === value,
19708
+ "aria-selected": choice.value === value,
19664
19709
  disabled: disabledValues.includes(choice.value),
19665
19710
  "data-qa": choice.text,
19666
19711
  themeValues: themeValues,
19667
- title: hasTitles ? choice.text : null
19712
+ title: hasTitles ? choice.text : null,
19713
+ role: "option"
19668
19714
  }, /*#__PURE__*/React.createElement(Text$1, {
19669
19715
  variant: "p",
19670
19716
  color: choice.value === value ? WHITE : disabledValues.includes(choice.value) ? STORM_GREY : MINESHAFT_GREY,
@@ -19809,7 +19855,7 @@ var FormSelect = function FormSelect(_ref) {
19809
19855
  extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
19810
19856
  id: labelTextWhenNoError.replace(/\s+/g, "-")
19811
19857
  }, labelTextWhenNoError))), /*#__PURE__*/React.createElement(Dropdown$1, {
19812
- "aria-labelledby": labelTextWhenNoError.replace(/\s+/g, "-"),
19858
+ ariaLabelledby: labelTextWhenNoError.replace(/\s+/g, "-"),
19813
19859
  maxHeight: dropdownMaxHeight,
19814
19860
  hasTitles: hasTitles,
19815
19861
  placeholder: options[0] ? options[0].text : "",