@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.cjs.js CHANGED
@@ -19446,31 +19446,31 @@ var DropdownItemWrapper = styled__default.div.withConfig({
19446
19446
  var SearchInput = styled__default.input.withConfig({
19447
19447
  displayName: "Dropdown__SearchInput",
19448
19448
  componentId: "sc-pn6m0h-3"
19449
- })(["border:none;background-color:", ";font-size:16px;height:24px;"], function (_ref8) {
19450
- var themeValues = _ref8.themeValues;
19451
- return themeValues.hoverColor && themeValues.hoverColor;
19452
- });
19453
-
19454
- var Dropdown = function Dropdown(_ref9) {
19455
- var placeholder = _ref9.placeholder,
19456
- options = _ref9.options,
19457
- value = _ref9.value,
19458
- isOpen = _ref9.isOpen,
19459
- isError = _ref9.isError,
19460
- onSelect = _ref9.onSelect,
19461
- _ref9$disabledValues = _ref9.disabledValues,
19462
- disabledValues = _ref9$disabledValues === void 0 ? [] : _ref9$disabledValues,
19463
- _ref9$onClick = _ref9.onClick,
19464
- onClick = _ref9$onClick === void 0 ? noop : _ref9$onClick,
19465
- themeValues = _ref9.themeValues,
19466
- maxHeight = _ref9.maxHeight,
19467
- _ref9$widthFitOptions = _ref9.widthFitOptions,
19468
- widthFitOptions = _ref9$widthFitOptions === void 0 ? false : _ref9$widthFitOptions,
19469
- disabled = _ref9.disabled,
19470
- _ref9$hasTitles = _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;
19449
+ })(["border:none;background-color:transparent;font-size:16px;height:24px;min-width:80%;"]);
19450
+
19451
+ var Dropdown = function Dropdown(_ref8) {
19452
+ var placeholder = _ref8.placeholder,
19453
+ options = _ref8.options,
19454
+ value = _ref8.value,
19455
+ isOpen = _ref8.isOpen,
19456
+ isError = _ref8.isError,
19457
+ onSelect = _ref8.onSelect,
19458
+ _ref8$disabledValues = _ref8.disabledValues,
19459
+ disabledValues = _ref8$disabledValues === void 0 ? [] : _ref8$disabledValues,
19460
+ _ref8$onClick = _ref8.onClick,
19461
+ onClick = _ref8$onClick === void 0 ? noop : _ref8$onClick,
19462
+ themeValues = _ref8.themeValues,
19463
+ maxHeight = _ref8.maxHeight,
19464
+ _ref8$widthFitOptions = _ref8.widthFitOptions,
19465
+ widthFitOptions = _ref8$widthFitOptions === void 0 ? false : _ref8$widthFitOptions,
19466
+ disabled = _ref8.disabled,
19467
+ _ref8$hasTitles = _ref8.hasTitles,
19468
+ hasTitles = _ref8$hasTitles === void 0 ? false : _ref8$hasTitles,
19469
+ _ref8$autoEraseTypeAh = _ref8.autoEraseTypeAhead,
19470
+ autoEraseTypeAhead = _ref8$autoEraseTypeAh === void 0 ? true : _ref8$autoEraseTypeAh,
19471
+ ariaLabelledby = _ref8.ariaLabelledby,
19472
+ _ref8$autocompleteVal = _ref8.autocompleteValue,
19473
+ autocompleteValue = _ref8$autocompleteVal === void 0 ? "" : _ref8$autocompleteVal;
19474
19474
 
19475
19475
  var _useState = React.useState(""),
19476
19476
  _useState2 = _slicedToArray(_useState, 2),
@@ -19526,6 +19526,8 @@ var Dropdown = function Dropdown(_ref9) {
19526
19526
  };
19527
19527
 
19528
19528
  var onKeyDown = function onKeyDown(e) {
19529
+ var _optionRefs$current$l, _optionRefs$current;
19530
+
19529
19531
  var key = e.key,
19530
19532
  keyCode = e.keyCode;
19531
19533
  var focus = document.activeElement;
@@ -19579,10 +19581,18 @@ var Dropdown = function Dropdown(_ref9) {
19579
19581
 
19580
19582
  case "Backspace" :
19581
19583
  e.preventDefault();
19582
- console.log("input value is", inputValue);
19583
- console.log("new input value will be", inputValue.slice(0, -1));
19584
19584
  setInputValue(inputValue.slice(0, -1));
19585
19585
  break;
19586
+
19587
+ case "Home":
19588
+ e.preventDefault();
19589
+ optionRefs.current[0].current.focus();
19590
+ break;
19591
+
19592
+ case "End":
19593
+ e.preventDefault();
19594
+ 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();
19595
+ break;
19586
19596
  }
19587
19597
 
19588
19598
  if (keyCode > 64 && keyCode < 91 || keyCode == 32 || keyCode == 189) {
@@ -19596,7 +19606,11 @@ var Dropdown = function Dropdown(_ref9) {
19596
19606
  console.log("selected refs in isopen useffect", selectedRef);
19597
19607
  console.log("value in isopen useffect", value);
19598
19608
 
19599
- if (isOpen && optionRefs.current[0].current) {
19609
+ if (isOpen && selectedRef !== undefined) {
19610
+ // WAI-ARIA requires the selected option to receive focus
19611
+ selectedRef.current.focus();
19612
+ } else if (isOpen && optionRefs.current[0].current) {
19613
+ // If no selected option, first option receives focus
19600
19614
  optionRefs.current[0].current.focus();
19601
19615
  }
19602
19616
 
@@ -19617,6 +19631,8 @@ var Dropdown = function Dropdown(_ref9) {
19617
19631
  }, [inputValue]);
19618
19632
  React.useEffect(function () {
19619
19633
  if (!isOpen && filteredOptions[0] && !disabledValues.includes(filteredOptions[0].value) && filteredOptions[0].text != placeholder) {
19634
+ console.log("filtered options are", filteredOptions);
19635
+ console.log("option refs are", optionRefs);
19620
19636
  onSelect(filteredOptions[0].value);
19621
19637
  }
19622
19638
 
@@ -19633,6 +19649,10 @@ var Dropdown = function Dropdown(_ref9) {
19633
19649
  width: "100%",
19634
19650
  hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19635
19651
  "aria-expanded": isOpen,
19652
+ role: "combobox",
19653
+ "aria-owns": "".concat(ariaLabelledby, "_listbox"),
19654
+ "aria-haspopup": "listbox",
19655
+ "aria-labelledby": ariaLabelledby,
19636
19656
  extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
19637
19657
  title: hasTitles ? getSelection() : null
19638
19658
  }, /*#__PURE__*/React__default.createElement(Box, {
@@ -19649,31 +19669,43 @@ var Dropdown = function Dropdown(_ref9) {
19649
19669
  extraStyles: "height: 48px;\n ".concat(disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;", "\n ")
19650
19670
  }, /*#__PURE__*/React__default.createElement(Stack, {
19651
19671
  direction: "row",
19652
- bottomItem: 2
19653
- }, isOpen ? /*#__PURE__*/React__default.createElement(SearchInput, {
19654
- "aria-label": inputValue || "Dropdown awaiting search value",
19672
+ bottomItem: 2,
19673
+ extraStyles: "position: relative;"
19674
+ }, /*#__PURE__*/React__default.createElement(SearchInput, {
19675
+ "aria-label": getSelection(),
19676
+ placeholder: getSelection(),
19655
19677
  value: inputValue,
19656
19678
  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, {
19679
+ themeValues: themeValues,
19680
+ role: "searchbox",
19681
+ type: "text",
19682
+ "aria-multiline": "false",
19683
+ "aria-autocomplete": "list",
19684
+ "aria-controls": "".concat(ariaLabelledby, "_listbox"),
19685
+ "aria-activedescendant": "selected_option",
19686
+ isOpen: isOpen,
19687
+ tabIndex: -1,
19688
+ name: autocompleteValue,
19689
+ autocomplete: autocompleteValue
19690
+ }), /*#__PURE__*/React__default.createElement(IconWrapper, {
19662
19691
  open: isOpen
19663
19692
  }, /*#__PURE__*/React__default.createElement(DropdownIcon, null)))), isOpen ? /*#__PURE__*/React__default.createElement(DropdownContentWrapper, {
19664
19693
  maxHeight: maxHeight,
19665
19694
  open: isOpen,
19666
19695
  ref: dropdownRef,
19667
19696
  widthFitOptions: widthFitOptions,
19668
- tabIndex: 0
19697
+ tabIndex: 0,
19698
+ role: "listbox",
19699
+ id: "".concat(ariaLabelledby, "_listbox")
19669
19700
  }, /*#__PURE__*/React__default.createElement(Stack, {
19670
19701
  childGap: "0"
19671
19702
  }, filteredOptions.map(function (choice, i) {
19672
- if (selectedRef === undefined && choice.value === value) {
19703
+ if (choice.value === value && selectedRef !== optionRefs.current[i]) {
19673
19704
  setSelectedRef(optionRefs.current[i]);
19674
19705
  }
19675
19706
 
19676
19707
  return /*#__PURE__*/React__default.createElement(DropdownItemWrapper, {
19708
+ id: choice.value === value ? "selected_option" : choice.value,
19677
19709
  key: choice.value,
19678
19710
  ref: optionRefs.current[i],
19679
19711
  as: "button",
@@ -19681,13 +19713,16 @@ var Dropdown = function Dropdown(_ref9) {
19681
19713
  onClick: disabledValues.includes(choice.value) ? function (evt) {
19682
19714
  return evt.preventDefault();
19683
19715
  } : function () {
19684
- return onSelect(choice.value);
19716
+ setSelectedRef(optionRefs.current[i]);
19717
+ onSelect(choice.value);
19685
19718
  },
19686
19719
  selected: choice.value === value,
19720
+ "aria-selected": choice.value === value,
19687
19721
  disabled: disabledValues.includes(choice.value),
19688
19722
  "data-qa": choice.text,
19689
19723
  themeValues: themeValues,
19690
- title: hasTitles ? choice.text : null
19724
+ title: hasTitles ? choice.text : null,
19725
+ role: "option"
19691
19726
  }, /*#__PURE__*/React__default.createElement(Text$1, {
19692
19727
  variant: "p",
19693
19728
  color: choice.value === value ? WHITE : disabledValues.includes(choice.value) ? STORM_GREY : MINESHAFT_GREY,
@@ -19832,7 +19867,7 @@ var FormSelect = function FormSelect(_ref) {
19832
19867
  extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
19833
19868
  id: labelTextWhenNoError.replace(/\s+/g, "-")
19834
19869
  }, labelTextWhenNoError))), /*#__PURE__*/React__default.createElement(Dropdown$1, {
19835
- "aria-labelledby": labelTextWhenNoError.replace(/\s+/g, "-"),
19870
+ ariaLabelledby: labelTextWhenNoError.replace(/\s+/g, "-"),
19836
19871
  maxHeight: dropdownMaxHeight,
19837
19872
  hasTitles: hasTitles,
19838
19873
  placeholder: options[0] ? options[0].text : "",