@thecb/components 6.0.0-beta.3 → 6.0.0-beta.6

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,31 +19438,31 @@ 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;
19444
- });
19445
-
19446
- var Dropdown = function Dropdown(_ref9) {
19447
- var placeholder = _ref9.placeholder,
19448
- options = _ref9.options,
19449
- value = _ref9.value,
19450
- isOpen = _ref9.isOpen,
19451
- isError = _ref9.isError,
19452
- onSelect = _ref9.onSelect,
19453
- _ref9$disabledValues = _ref9.disabledValues,
19454
- disabledValues = _ref9$disabledValues === void 0 ? [] : _ref9$disabledValues,
19455
- _ref9$onClick = _ref9.onClick,
19456
- onClick = _ref9$onClick === void 0 ? noop : _ref9$onClick,
19457
- themeValues = _ref9.themeValues,
19458
- maxHeight = _ref9.maxHeight,
19459
- _ref9$widthFitOptions = _ref9.widthFitOptions,
19460
- widthFitOptions = _ref9$widthFitOptions === void 0 ? false : _ref9$widthFitOptions,
19461
- disabled = _ref9.disabled,
19462
- _ref9$hasTitles = _ref9.hasTitles,
19463
- hasTitles = _ref9$hasTitles === void 0 ? false : _ref9$hasTitles,
19464
- _ref9$autoEraseTypeAh = _ref9.autoEraseTypeAhead,
19465
- autoEraseTypeAhead = _ref9$autoEraseTypeAh === void 0 ? true : _ref9$autoEraseTypeAh;
19441
+ })(["border:none;background-color:transparent;font-size:16px;height:24px;min-width:80%;"]);
19442
+
19443
+ var Dropdown = function Dropdown(_ref8) {
19444
+ var placeholder = _ref8.placeholder,
19445
+ options = _ref8.options,
19446
+ value = _ref8.value,
19447
+ isOpen = _ref8.isOpen,
19448
+ isError = _ref8.isError,
19449
+ onSelect = _ref8.onSelect,
19450
+ _ref8$disabledValues = _ref8.disabledValues,
19451
+ disabledValues = _ref8$disabledValues === void 0 ? [] : _ref8$disabledValues,
19452
+ _ref8$onClick = _ref8.onClick,
19453
+ onClick = _ref8$onClick === void 0 ? noop : _ref8$onClick,
19454
+ themeValues = _ref8.themeValues,
19455
+ maxHeight = _ref8.maxHeight,
19456
+ _ref8$widthFitOptions = _ref8.widthFitOptions,
19457
+ widthFitOptions = _ref8$widthFitOptions === void 0 ? false : _ref8$widthFitOptions,
19458
+ disabled = _ref8.disabled,
19459
+ _ref8$hasTitles = _ref8.hasTitles,
19460
+ hasTitles = _ref8$hasTitles === void 0 ? false : _ref8$hasTitles,
19461
+ _ref8$autoEraseTypeAh = _ref8.autoEraseTypeAhead,
19462
+ autoEraseTypeAhead = _ref8$autoEraseTypeAh === void 0 ? true : _ref8$autoEraseTypeAh,
19463
+ ariaLabelledby = _ref8.ariaLabelledby,
19464
+ _ref8$autocompleteVal = _ref8.autocompleteValue,
19465
+ autocompleteValue = _ref8$autocompleteVal === void 0 ? "" : _ref8$autocompleteVal;
19466
19466
 
19467
19467
  var _useState = useState(""),
19468
19468
  _useState2 = _slicedToArray(_useState, 2),
@@ -19518,6 +19518,8 @@ var Dropdown = function Dropdown(_ref9) {
19518
19518
  };
19519
19519
 
19520
19520
  var onKeyDown = function onKeyDown(e) {
19521
+ var _optionRefs$current$l, _optionRefs$current;
19522
+
19521
19523
  var key = e.key,
19522
19524
  keyCode = e.keyCode;
19523
19525
  var focus = document.activeElement;
@@ -19571,10 +19573,18 @@ var Dropdown = function Dropdown(_ref9) {
19571
19573
 
19572
19574
  case "Backspace" :
19573
19575
  e.preventDefault();
19574
- console.log("input value is", inputValue);
19575
- console.log("new input value will be", inputValue.slice(0, -1));
19576
19576
  setInputValue(inputValue.slice(0, -1));
19577
19577
  break;
19578
+
19579
+ case "Home":
19580
+ e.preventDefault();
19581
+ optionRefs.current[0].current.focus();
19582
+ break;
19583
+
19584
+ case "End":
19585
+ e.preventDefault();
19586
+ 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();
19587
+ break;
19578
19588
  }
19579
19589
 
19580
19590
  if (keyCode > 64 && keyCode < 91 || keyCode == 32 || keyCode == 189) {
@@ -19588,7 +19598,11 @@ var Dropdown = function Dropdown(_ref9) {
19588
19598
  console.log("selected refs in isopen useffect", selectedRef);
19589
19599
  console.log("value in isopen useffect", value);
19590
19600
 
19591
- if (isOpen && optionRefs.current[0].current) {
19601
+ if (isOpen && selectedRef !== undefined) {
19602
+ // WAI-ARIA requires the selected option to receive focus
19603
+ selectedRef.current.focus();
19604
+ } else if (isOpen && optionRefs.current[0].current) {
19605
+ // If no selected option, first option receives focus
19592
19606
  optionRefs.current[0].current.focus();
19593
19607
  }
19594
19608
 
@@ -19609,6 +19623,8 @@ var Dropdown = function Dropdown(_ref9) {
19609
19623
  }, [inputValue]);
19610
19624
  useEffect$1(function () {
19611
19625
  if (!isOpen && filteredOptions[0] && !disabledValues.includes(filteredOptions[0].value) && filteredOptions[0].text != placeholder) {
19626
+ console.log("filtered options are", filteredOptions);
19627
+ console.log("option refs are", optionRefs);
19612
19628
  onSelect(filteredOptions[0].value);
19613
19629
  }
19614
19630
 
@@ -19625,6 +19641,10 @@ var Dropdown = function Dropdown(_ref9) {
19625
19641
  width: "100%",
19626
19642
  hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19627
19643
  "aria-expanded": isOpen,
19644
+ role: "combobox",
19645
+ "aria-owns": "".concat(ariaLabelledby, "_listbox"),
19646
+ "aria-haspopup": "listbox",
19647
+ "aria-labelledby": ariaLabelledby,
19628
19648
  extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
19629
19649
  title: hasTitles ? getSelection() : null
19630
19650
  }, /*#__PURE__*/React.createElement(Box, {
@@ -19641,31 +19661,43 @@ var Dropdown = function Dropdown(_ref9) {
19641
19661
  extraStyles: "height: 48px;\n ".concat(disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;", "\n ")
19642
19662
  }, /*#__PURE__*/React.createElement(Stack, {
19643
19663
  direction: "row",
19644
- bottomItem: 2
19645
- }, isOpen ? /*#__PURE__*/React.createElement(SearchInput, {
19646
- "aria-label": inputValue || "Dropdown awaiting search value",
19664
+ bottomItem: 2,
19665
+ extraStyles: "position: relative;"
19666
+ }, /*#__PURE__*/React.createElement(SearchInput, {
19667
+ "aria-label": getSelection(),
19668
+ placeholder: getSelection(),
19647
19669
  value: inputValue,
19648
19670
  onChange: noop,
19649
- themeValues: themeValues
19650
- }) : /*#__PURE__*/React.createElement(Text$1, {
19651
- variant: "p",
19652
- extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;"
19653
- }, getSelection()), /*#__PURE__*/React.createElement(IconWrapper, {
19671
+ themeValues: themeValues,
19672
+ role: "searchbox",
19673
+ type: "text",
19674
+ "aria-multiline": "false",
19675
+ "aria-autocomplete": "list",
19676
+ "aria-controls": "".concat(ariaLabelledby, "_listbox"),
19677
+ "aria-activedescendant": "selected_option",
19678
+ isOpen: isOpen,
19679
+ tabIndex: -1,
19680
+ name: autocompleteValue,
19681
+ autocomplete: autocompleteValue
19682
+ }), /*#__PURE__*/React.createElement(IconWrapper, {
19654
19683
  open: isOpen
19655
19684
  }, /*#__PURE__*/React.createElement(DropdownIcon, null)))), isOpen ? /*#__PURE__*/React.createElement(DropdownContentWrapper, {
19656
19685
  maxHeight: maxHeight,
19657
19686
  open: isOpen,
19658
19687
  ref: dropdownRef,
19659
19688
  widthFitOptions: widthFitOptions,
19660
- tabIndex: 0
19689
+ tabIndex: 0,
19690
+ role: "listbox",
19691
+ id: "".concat(ariaLabelledby, "_listbox")
19661
19692
  }, /*#__PURE__*/React.createElement(Stack, {
19662
19693
  childGap: "0"
19663
19694
  }, filteredOptions.map(function (choice, i) {
19664
- if (selectedRef === undefined && choice.value === value) {
19695
+ if (choice.value === value && selectedRef !== optionRefs.current[i]) {
19665
19696
  setSelectedRef(optionRefs.current[i]);
19666
19697
  }
19667
19698
 
19668
19699
  return /*#__PURE__*/React.createElement(DropdownItemWrapper, {
19700
+ id: choice.value === value ? "selected_option" : choice.value,
19669
19701
  key: choice.value,
19670
19702
  ref: optionRefs.current[i],
19671
19703
  as: "button",
@@ -19673,13 +19705,16 @@ var Dropdown = function Dropdown(_ref9) {
19673
19705
  onClick: disabledValues.includes(choice.value) ? function (evt) {
19674
19706
  return evt.preventDefault();
19675
19707
  } : function () {
19676
- return onSelect(choice.value);
19708
+ setSelectedRef(optionRefs.current[i]);
19709
+ onSelect(choice.value);
19677
19710
  },
19678
19711
  selected: choice.value === value,
19712
+ "aria-selected": choice.value === value,
19679
19713
  disabled: disabledValues.includes(choice.value),
19680
19714
  "data-qa": choice.text,
19681
19715
  themeValues: themeValues,
19682
- title: hasTitles ? choice.text : null
19716
+ title: hasTitles ? choice.text : null,
19717
+ role: "option"
19683
19718
  }, /*#__PURE__*/React.createElement(Text$1, {
19684
19719
  variant: "p",
19685
19720
  color: choice.value === value ? WHITE : disabledValues.includes(choice.value) ? STORM_GREY : MINESHAFT_GREY,
@@ -19824,7 +19859,7 @@ var FormSelect = function FormSelect(_ref) {
19824
19859
  extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
19825
19860
  id: labelTextWhenNoError.replace(/\s+/g, "-")
19826
19861
  }, labelTextWhenNoError))), /*#__PURE__*/React.createElement(Dropdown$1, {
19827
- "aria-labelledby": labelTextWhenNoError.replace(/\s+/g, "-"),
19862
+ ariaLabelledby: labelTextWhenNoError.replace(/\s+/g, "-"),
19828
19863
  maxHeight: dropdownMaxHeight,
19829
19864
  hasTitles: hasTitles,
19830
19865
  placeholder: options[0] ? options[0].text : "",