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

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
@@ -19435,32 +19435,30 @@ var DropdownItemWrapper = styled.div.withConfig({
19435
19435
  themeValues = _ref7.themeValues;
19436
19436
  return selected ? themeValues.selectedColor : disabled ? WHITE : themeValues.hoverColor;
19437
19437
  });
19438
- var SearchInput = styled.input.withConfig({
19439
- displayName: "Dropdown__SearchInput",
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
19438
 
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;
19439
+ var Dropdown = function Dropdown(_ref8) {
19440
+ var placeholder = _ref8.placeholder,
19441
+ options = _ref8.options,
19442
+ value = _ref8.value,
19443
+ isOpen = _ref8.isOpen,
19444
+ isError = _ref8.isError,
19445
+ onSelect = _ref8.onSelect,
19446
+ _ref8$disabledValues = _ref8.disabledValues,
19447
+ disabledValues = _ref8$disabledValues === void 0 ? [] : _ref8$disabledValues,
19448
+ _ref8$onClick = _ref8.onClick,
19449
+ onClick = _ref8$onClick === void 0 ? noop : _ref8$onClick,
19450
+ themeValues = _ref8.themeValues,
19451
+ maxHeight = _ref8.maxHeight,
19452
+ _ref8$widthFitOptions = _ref8.widthFitOptions,
19453
+ widthFitOptions = _ref8$widthFitOptions === void 0 ? false : _ref8$widthFitOptions,
19454
+ disabled = _ref8.disabled,
19455
+ _ref8$hasTitles = _ref8.hasTitles,
19456
+ hasTitles = _ref8$hasTitles === void 0 ? false : _ref8$hasTitles,
19457
+ _ref8$autoEraseTypeAh = _ref8.autoEraseTypeAhead,
19458
+ autoEraseTypeAhead = _ref8$autoEraseTypeAh === void 0 ? true : _ref8$autoEraseTypeAh,
19459
+ ariaLabelledby = _ref8.ariaLabelledby,
19460
+ _ref8$autocompleteVal = _ref8.autocompleteValue,
19461
+ autocompleteValue = _ref8$autocompleteVal === void 0 ? "" : _ref8$autocompleteVal;
19464
19462
 
19465
19463
  var _useState = useState(""),
19466
19464
  _useState2 = _slicedToArray(_useState, 2),
@@ -19482,6 +19480,16 @@ var Dropdown = function Dropdown(_ref9) {
19482
19480
  optionsChanged = _useState8[0],
19483
19481
  setOptionsChanged = _useState8[1];
19484
19482
 
19483
+ var _useState9 = useState(undefined),
19484
+ _useState10 = _slicedToArray(_useState9, 2),
19485
+ selectedRef = _useState10[0],
19486
+ setSelectedRef = _useState10[1];
19487
+
19488
+ var _useState11 = useState(undefined),
19489
+ _useState12 = _slicedToArray(_useState11, 2),
19490
+ focusedRef = _useState12[0],
19491
+ setFocusedRef = _useState12[1];
19492
+
19485
19493
  if (optionsState !== options) {
19486
19494
  setOptionsState(options);
19487
19495
  setOptionsChanged(true);
@@ -19492,10 +19500,10 @@ var Dropdown = function Dropdown(_ref9) {
19492
19500
  setOptionsChanged(false);
19493
19501
  }
19494
19502
 
19495
- var _useState9 = useState(null),
19496
- _useState10 = _slicedToArray(_useState9, 2),
19497
- timer = _useState10[0],
19498
- setTimer = _useState10[1];
19503
+ var _useState13 = useState(null),
19504
+ _useState14 = _slicedToArray(_useState13, 2),
19505
+ timer = _useState14[0],
19506
+ setTimer = _useState14[1];
19499
19507
 
19500
19508
  var optionRefs = useRef(_toConsumableArray(Array(options.length)).map(function () {
19501
19509
  return /*#__PURE__*/createRef();
@@ -19511,6 +19519,10 @@ var Dropdown = function Dropdown(_ref9) {
19511
19519
  };
19512
19520
 
19513
19521
  var onKeyDown = function onKeyDown(e) {
19522
+ var _optionRefs$current$l, _optionRefs$current;
19523
+
19524
+ console.log("key down event is", e.target);
19525
+ console.log("key down event value is", e.target.value);
19514
19526
  var key = e.key,
19515
19527
  keyCode = e.keyCode;
19516
19528
  var focus = document.activeElement;
@@ -19566,16 +19578,30 @@ var Dropdown = function Dropdown(_ref9) {
19566
19578
  e.preventDefault();
19567
19579
  setInputValue(inputValue.slice(0, -1));
19568
19580
  break;
19569
- }
19570
19581
 
19571
- if (keyCode > 64 && keyCode < 91 || keyCode == 32 || keyCode == 189) {
19572
- e.preventDefault();
19573
- setInputValue(inputValue + key);
19582
+ case "Home":
19583
+ e.preventDefault();
19584
+ optionRefs.current[0].current.focus();
19585
+ break;
19586
+
19587
+ case "End":
19588
+ e.preventDefault();
19589
+ 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();
19590
+ break;
19574
19591
  }
19575
19592
  };
19576
19593
 
19577
19594
  useEffect$1(function () {
19578
- if (isOpen && optionRefs.current[0].current) {
19595
+ console.log("option refs in isopen useffect", optionRefs);
19596
+ console.log("option ref current in isopen useffect", optionRefs.current[0].current);
19597
+ console.log("selected refs in isopen useffect", selectedRef);
19598
+ console.log("value in isopen useffect", value);
19599
+
19600
+ if (isOpen && selectedRef !== undefined && selectedRef.current !== null) {
19601
+ // WAI-ARIA requires the selected option to receive focus
19602
+ selectedRef.current.focus();
19603
+ } else if (isOpen && optionRefs.current[0].current) {
19604
+ // If no selected option, first option receives focus
19579
19605
  optionRefs.current[0].current.focus();
19580
19606
  }
19581
19607
 
@@ -19583,16 +19609,21 @@ var Dropdown = function Dropdown(_ref9) {
19583
19609
  setInputValue("");
19584
19610
  }, [isOpen]);
19585
19611
  useEffect$1(function () {
19586
- clearTimeout(timer);
19587
- setTimer(setTimeout(function () {
19588
- return setInputValue("");
19589
- }, 2000));
19612
+ if (autoEraseTypeAhead) {
19613
+ clearTimeout(timer);
19614
+ setTimer(setTimeout(function () {
19615
+ return setInputValue("");
19616
+ }, 3000));
19617
+ }
19618
+
19590
19619
  setFilteredOptions(options.filter(function (option) {
19591
19620
  return option.value.toLowerCase().startsWith(inputValue.toLowerCase()) || option.text.toLowerCase().startsWith(inputValue.toLowerCase());
19592
19621
  }));
19593
19622
  }, [inputValue]);
19594
19623
  useEffect$1(function () {
19595
19624
  if (!isOpen && filteredOptions[0] && !disabledValues.includes(filteredOptions[0].value) && filteredOptions[0].text != placeholder) {
19625
+ console.log("filtered options are", filteredOptions);
19626
+ console.log("option refs are", optionRefs);
19596
19627
  onSelect(filteredOptions[0].value);
19597
19628
  }
19598
19629
 
@@ -19602,70 +19633,91 @@ var Dropdown = function Dropdown(_ref9) {
19602
19633
  dropdownRef.current.focus();
19603
19634
  }
19604
19635
  }, [filteredOptions]);
19605
- return /*#__PURE__*/React.createElement(Box, {
19606
- onKeyDown: onKeyDown,
19607
- onClick: onClick,
19608
- padding: "0",
19609
- width: "100%",
19610
- hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19611
- "aria-expanded": isOpen,
19612
- extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
19613
- title: hasTitles ? getSelection() : null
19636
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Stack, {
19637
+ direction: "row",
19638
+ bottomItem: 2,
19639
+ extraStyles: "position: relative;"
19614
19640
  }, /*#__PURE__*/React.createElement(Box, {
19615
- as: "button",
19641
+ as: "input",
19642
+ "aria-multiline": "false",
19643
+ "aria-autocomplete": "list",
19644
+ "aria-controls": "".concat(ariaLabelledby, "_listbox"),
19645
+ "aria-activedescendant": "focused_option",
19646
+ "aria-owns": "".concat(ariaLabelledby, "_listbox"),
19647
+ "aria-haspopup": "listbox",
19648
+ "aria-labelledby": ariaLabelledby,
19649
+ "aria-expanded": isOpen,
19650
+ autocomplete: autocompleteValue,
19616
19651
  background: isOpen ? themeValues.hoverColor : WHITE,
19617
- width: "100%",
19618
- padding: "12px",
19619
- hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19652
+ borderRadius: "2px",
19620
19653
  borderSize: "1px",
19621
19654
  borderColor: isError ? ERROR_COLOR : isOpen ? themeValues.selectedColor : GREY_CHATEAU,
19622
- borderRadius: "2px",
19623
- tabIndex: 0,
19624
- dataQa: placeholder,
19625
- extraStyles: "height: 48px;\n ".concat(disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;", "\n ")
19626
- }, /*#__PURE__*/React.createElement(Stack, {
19627
- direction: "row",
19628
- bottomItem: 2
19629
- }, isOpen ? /*#__PURE__*/React.createElement(SearchInput, {
19630
- "aria-label": inputValue || "Dropdown awaiting search value",
19655
+ extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
19656
+ hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19657
+ isOpen: isOpen,
19658
+ name: autocompleteValue,
19659
+ onKeyDown: onKeyDown,
19660
+ onClick: onClick,
19661
+ onFocus: onClick,
19662
+ onChange: function onChange(e) {
19663
+ console.log("input change event", e.target);
19664
+ console.log("input change event value", e.target.value);
19665
+ setInputValue(e.target.value);
19666
+ },
19667
+ padding: "12px",
19668
+ placeholder: getSelection(),
19669
+ role: "combobox",
19670
+ themeValues: themeValues,
19671
+ title: hasTitles ? getSelection() : null,
19672
+ type: "text",
19673
+ tabIndex: -1,
19631
19674
  value: inputValue,
19632
- onChange: noop,
19633
- themeValues: themeValues
19634
- }) : /*#__PURE__*/React.createElement(Text$1, {
19635
- variant: "p",
19636
- extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;"
19637
- }, getSelection()), /*#__PURE__*/React.createElement(IconWrapper, {
19638
- open: isOpen
19639
- }, /*#__PURE__*/React.createElement(DropdownIcon, null)))), isOpen ? /*#__PURE__*/React.createElement(DropdownContentWrapper, {
19675
+ width: "100%",
19676
+ dataQa: placeholder
19677
+ }, isOpen ? /*#__PURE__*/React.createElement(DropdownContentWrapper, {
19640
19678
  maxHeight: maxHeight,
19641
19679
  open: isOpen,
19642
19680
  ref: dropdownRef,
19643
19681
  widthFitOptions: widthFitOptions,
19644
- tabIndex: 0
19682
+ tabIndex: 0,
19683
+ role: "listbox",
19684
+ id: "".concat(ariaLabelledby, "_listbox")
19645
19685
  }, /*#__PURE__*/React.createElement(Stack, {
19646
19686
  childGap: "0"
19647
19687
  }, filteredOptions.map(function (choice, i) {
19688
+ if (choice.value === value && selectedRef !== optionRefs.current[i]) {
19689
+ setSelectedRef(optionRefs.current[i]);
19690
+ }
19691
+
19648
19692
  return /*#__PURE__*/React.createElement(DropdownItemWrapper, {
19693
+ id: focusedRef === optionRefs.current[i] ? "focused_option" : choice.value,
19649
19694
  key: choice.value,
19650
19695
  ref: optionRefs.current[i],
19651
- as: "button",
19652
19696
  tabIndex: -1,
19653
19697
  onClick: disabledValues.includes(choice.value) ? function (evt) {
19654
19698
  return evt.preventDefault();
19655
19699
  } : function () {
19656
- return onSelect(choice.value);
19700
+ setSelectedRef(optionRefs.current[i]);
19701
+ onSelect(choice.value);
19657
19702
  },
19658
19703
  selected: choice.value === value,
19704
+ "aria-selected": choice.value === value,
19659
19705
  disabled: disabledValues.includes(choice.value),
19660
19706
  "data-qa": choice.text,
19661
19707
  themeValues: themeValues,
19662
- title: hasTitles ? choice.text : null
19708
+ title: hasTitles ? choice.text : null,
19709
+ role: "option",
19710
+ onFocus: function onFocus() {
19711
+ return setFocusedRef(optionRefs.current[i]);
19712
+ }
19663
19713
  }, /*#__PURE__*/React.createElement(Text$1, {
19664
19714
  variant: "p",
19665
19715
  color: choice.value === value ? WHITE : disabledValues.includes(choice.value) ? STORM_GREY : MINESHAFT_GREY,
19666
19716
  extraStyles: "padding-left: 16px; \n cursor: ".concat(disabledValues.includes(choice.value) ? "default" : "pointer", "; \n white-space: nowrap; \n overflow: hidden; \n text-overflow: ellipsis;")
19667
19717
  }, choice.text));
19668
- }))) : /*#__PURE__*/React.createElement(Fragment, null));
19718
+ }))) : /*#__PURE__*/React.createElement(Fragment, null)), /*#__PURE__*/React.createElement(IconWrapper, {
19719
+ open: isOpen
19720
+ }, /*#__PURE__*/React.createElement(DropdownIcon, null))));
19669
19721
  };
19670
19722
 
19671
19723
  var Dropdown$1 = themeComponent(Dropdown, "Dropdown", fallbackValues$e);
@@ -19766,7 +19818,8 @@ var FormSelect = function FormSelect(_ref) {
19766
19818
  disabled = _ref.disabled,
19767
19819
  themeValues = _ref.themeValues,
19768
19820
  _ref$hasTitles = _ref.hasTitles,
19769
- hasTitles = _ref$hasTitles === void 0 ? false : _ref$hasTitles;
19821
+ hasTitles = _ref$hasTitles === void 0 ? false : _ref$hasTitles,
19822
+ autocompleteValue = _ref.autocompleteValue;
19770
19823
 
19771
19824
  var _useState = useState(false),
19772
19825
  _useState2 = _slicedToArray(_useState, 2),
@@ -19804,7 +19857,7 @@ var FormSelect = function FormSelect(_ref) {
19804
19857
  extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
19805
19858
  id: labelTextWhenNoError.replace(/\s+/g, "-")
19806
19859
  }, labelTextWhenNoError))), /*#__PURE__*/React.createElement(Dropdown$1, {
19807
- "aria-labelledby": labelTextWhenNoError.replace(/\s+/g, "-"),
19860
+ ariaLabelledby: labelTextWhenNoError.replace(/\s+/g, "-"),
19808
19861
  maxHeight: dropdownMaxHeight,
19809
19862
  hasTitles: hasTitles,
19810
19863
  placeholder: options[0] ? options[0].text : "",
@@ -19821,7 +19874,8 @@ var FormSelect = function FormSelect(_ref) {
19821
19874
  onClick: function onClick() {
19822
19875
  return setOpen(!open);
19823
19876
  },
19824
- disabled: disabled
19877
+ disabled: disabled,
19878
+ autocompleteValue: autocompleteValue
19825
19879
  }), /*#__PURE__*/React.createElement(Stack, {
19826
19880
  direction: "row",
19827
19881
  justify: "space-between"
@@ -20594,7 +20648,8 @@ var CountryDropdown = function CountryDropdown(_ref) {
20594
20648
  labelTextWhenNoError: labelTextWhenNoError,
20595
20649
  errorMessages: errorMessages,
20596
20650
  showErrors: showErrors,
20597
- onChange: onChange
20651
+ onChange: onChange,
20652
+ autocompleteValue: "country-name"
20598
20653
  });
20599
20654
  };
20600
20655
 
@@ -33010,7 +33065,8 @@ var FormStateDropdown = function FormStateDropdown(_ref) {
33010
33065
  fieldActions: fieldActions,
33011
33066
  labelTextWhenNoError: labelTextWhenNoError,
33012
33067
  errorMessages: errorMessages,
33013
- showErrors: showErrors
33068
+ showErrors: showErrors,
33069
+ autocompleteValue: "address-level1"
33014
33070
  });
33015
33071
  };
33016
33072