@thecb/components 6.0.0-beta.3 → 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
@@ -19470,7 +19470,8 @@ var Dropdown = function Dropdown(_ref9) {
19470
19470
  _ref9$hasTitles = _ref9.hasTitles,
19471
19471
  hasTitles = _ref9$hasTitles === void 0 ? false : _ref9$hasTitles,
19472
19472
  _ref9$autoEraseTypeAh = _ref9.autoEraseTypeAhead,
19473
- autoEraseTypeAhead = _ref9$autoEraseTypeAh === void 0 ? true : _ref9$autoEraseTypeAh;
19473
+ autoEraseTypeAhead = _ref9$autoEraseTypeAh === void 0 ? true : _ref9$autoEraseTypeAh,
19474
+ ariaLabelledby = _ref9.ariaLabelledby;
19474
19475
 
19475
19476
  var _useState = React.useState(""),
19476
19477
  _useState2 = _slicedToArray(_useState, 2),
@@ -19526,6 +19527,8 @@ var Dropdown = function Dropdown(_ref9) {
19526
19527
  };
19527
19528
 
19528
19529
  var onKeyDown = function onKeyDown(e) {
19530
+ var _optionRefs$current$l, _optionRefs$current;
19531
+
19529
19532
  var key = e.key,
19530
19533
  keyCode = e.keyCode;
19531
19534
  var focus = document.activeElement;
@@ -19579,10 +19582,18 @@ var Dropdown = function Dropdown(_ref9) {
19579
19582
 
19580
19583
  case "Backspace" :
19581
19584
  e.preventDefault();
19582
- console.log("input value is", inputValue);
19583
- console.log("new input value will be", inputValue.slice(0, -1));
19584
19585
  setInputValue(inputValue.slice(0, -1));
19585
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;
19586
19597
  }
19587
19598
 
19588
19599
  if (keyCode > 64 && keyCode < 91 || keyCode == 32 || keyCode == 189) {
@@ -19596,7 +19607,11 @@ var Dropdown = function Dropdown(_ref9) {
19596
19607
  console.log("selected refs in isopen useffect", selectedRef);
19597
19608
  console.log("value in isopen useffect", value);
19598
19609
 
19599
- if (isOpen && optionRefs.current[0].current) {
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
19600
19615
  optionRefs.current[0].current.focus();
19601
19616
  }
19602
19617
 
@@ -19633,6 +19648,10 @@ var Dropdown = function Dropdown(_ref9) {
19633
19648
  width: "100%",
19634
19649
  hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19635
19650
  "aria-expanded": isOpen,
19651
+ role: "combobox",
19652
+ "aria-owns": "".concat(ariaLabelledby, "_listbox"),
19653
+ "aria-haspopup": "listbox",
19654
+ "aria-labelledby": ariaLabelledby,
19636
19655
  extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
19637
19656
  title: hasTitles ? getSelection() : null
19638
19657
  }, /*#__PURE__*/React__default.createElement(Box, {
@@ -19644,28 +19663,34 @@ var Dropdown = function Dropdown(_ref9) {
19644
19663
  borderSize: "1px",
19645
19664
  borderColor: isError ? ERROR_COLOR : isOpen ? themeValues.selectedColor : GREY_CHATEAU,
19646
19665
  borderRadius: "2px",
19647
- tabIndex: 0,
19648
19666
  dataQa: placeholder,
19649
19667
  extraStyles: "height: 48px;\n ".concat(disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;", "\n ")
19650
19668
  }, /*#__PURE__*/React__default.createElement(Stack, {
19651
19669
  direction: "row",
19652
19670
  bottomItem: 2
19653
- }, isOpen ? /*#__PURE__*/React__default.createElement(SearchInput, {
19654
- "aria-label": inputValue || "Dropdown awaiting search value",
19671
+ }, /*#__PURE__*/React__default.createElement(SearchInput, {
19672
+ "aria-label": getSelection(),
19673
+ placeholder: getSelection(),
19655
19674
  value: inputValue,
19656
19675
  onChange: noop,
19657
- themeValues: themeValues
19658
- }) : /*#__PURE__*/React__default.createElement(Text$1, {
19659
- variant: "p",
19660
- extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;"
19661
- }, 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, {
19662
19685
  open: isOpen
19663
19686
  }, /*#__PURE__*/React__default.createElement(DropdownIcon, null)))), isOpen ? /*#__PURE__*/React__default.createElement(DropdownContentWrapper, {
19664
19687
  maxHeight: maxHeight,
19665
19688
  open: isOpen,
19666
19689
  ref: dropdownRef,
19667
19690
  widthFitOptions: widthFitOptions,
19668
- tabIndex: 0
19691
+ tabIndex: 0,
19692
+ role: "listbox",
19693
+ id: "".concat(ariaLabelledby, "_listbox")
19669
19694
  }, /*#__PURE__*/React__default.createElement(Stack, {
19670
19695
  childGap: "0"
19671
19696
  }, filteredOptions.map(function (choice, i) {
@@ -19674,6 +19699,7 @@ var Dropdown = function Dropdown(_ref9) {
19674
19699
  }
19675
19700
 
19676
19701
  return /*#__PURE__*/React__default.createElement(DropdownItemWrapper, {
19702
+ id: choice.value === value ? "selected_option" : choice.value,
19677
19703
  key: choice.value,
19678
19704
  ref: optionRefs.current[i],
19679
19705
  as: "button",
@@ -19684,10 +19710,12 @@ var Dropdown = function Dropdown(_ref9) {
19684
19710
  return onSelect(choice.value);
19685
19711
  },
19686
19712
  selected: choice.value === value,
19713
+ "aria-selected": choice.value === value,
19687
19714
  disabled: disabledValues.includes(choice.value),
19688
19715
  "data-qa": choice.text,
19689
19716
  themeValues: themeValues,
19690
- title: hasTitles ? choice.text : null
19717
+ title: hasTitles ? choice.text : null,
19718
+ role: "option"
19691
19719
  }, /*#__PURE__*/React__default.createElement(Text$1, {
19692
19720
  variant: "p",
19693
19721
  color: choice.value === value ? WHITE : disabledValues.includes(choice.value) ? STORM_GREY : MINESHAFT_GREY,
@@ -19832,7 +19860,7 @@ var FormSelect = function FormSelect(_ref) {
19832
19860
  extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
19833
19861
  id: labelTextWhenNoError.replace(/\s+/g, "-")
19834
19862
  }, labelTextWhenNoError))), /*#__PURE__*/React__default.createElement(Dropdown$1, {
19835
- "aria-labelledby": labelTextWhenNoError.replace(/\s+/g, "-"),
19863
+ ariaLabelledby: labelTextWhenNoError.replace(/\s+/g, "-"),
19836
19864
  maxHeight: dropdownMaxHeight,
19837
19865
  hasTitles: hasTitles,
19838
19866
  placeholder: options[0] ? options[0].text : "",