@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.cjs.js CHANGED
@@ -19443,32 +19443,30 @@ var DropdownItemWrapper = styled__default.div.withConfig({
19443
19443
  themeValues = _ref7.themeValues;
19444
19444
  return selected ? themeValues.selectedColor : disabled ? WHITE : themeValues.hoverColor;
19445
19445
  });
19446
- var SearchInput = styled__default.input.withConfig({
19447
- displayName: "Dropdown__SearchInput",
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
19446
 
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;
19447
+ var Dropdown = function Dropdown(_ref8) {
19448
+ var placeholder = _ref8.placeholder,
19449
+ options = _ref8.options,
19450
+ value = _ref8.value,
19451
+ isOpen = _ref8.isOpen,
19452
+ isError = _ref8.isError,
19453
+ onSelect = _ref8.onSelect,
19454
+ _ref8$disabledValues = _ref8.disabledValues,
19455
+ disabledValues = _ref8$disabledValues === void 0 ? [] : _ref8$disabledValues,
19456
+ _ref8$onClick = _ref8.onClick,
19457
+ onClick = _ref8$onClick === void 0 ? noop : _ref8$onClick,
19458
+ themeValues = _ref8.themeValues,
19459
+ maxHeight = _ref8.maxHeight,
19460
+ _ref8$widthFitOptions = _ref8.widthFitOptions,
19461
+ widthFitOptions = _ref8$widthFitOptions === void 0 ? false : _ref8$widthFitOptions,
19462
+ disabled = _ref8.disabled,
19463
+ _ref8$hasTitles = _ref8.hasTitles,
19464
+ hasTitles = _ref8$hasTitles === void 0 ? false : _ref8$hasTitles,
19465
+ _ref8$autoEraseTypeAh = _ref8.autoEraseTypeAhead,
19466
+ autoEraseTypeAhead = _ref8$autoEraseTypeAh === void 0 ? true : _ref8$autoEraseTypeAh,
19467
+ ariaLabelledby = _ref8.ariaLabelledby,
19468
+ _ref8$autocompleteVal = _ref8.autocompleteValue,
19469
+ autocompleteValue = _ref8$autocompleteVal === void 0 ? "" : _ref8$autocompleteVal;
19472
19470
 
19473
19471
  var _useState = React.useState(""),
19474
19472
  _useState2 = _slicedToArray(_useState, 2),
@@ -19490,6 +19488,16 @@ var Dropdown = function Dropdown(_ref9) {
19490
19488
  optionsChanged = _useState8[0],
19491
19489
  setOptionsChanged = _useState8[1];
19492
19490
 
19491
+ var _useState9 = React.useState(undefined),
19492
+ _useState10 = _slicedToArray(_useState9, 2),
19493
+ selectedRef = _useState10[0],
19494
+ setSelectedRef = _useState10[1];
19495
+
19496
+ var _useState11 = React.useState(undefined),
19497
+ _useState12 = _slicedToArray(_useState11, 2),
19498
+ focusedRef = _useState12[0],
19499
+ setFocusedRef = _useState12[1];
19500
+
19493
19501
  if (optionsState !== options) {
19494
19502
  setOptionsState(options);
19495
19503
  setOptionsChanged(true);
@@ -19500,10 +19508,10 @@ var Dropdown = function Dropdown(_ref9) {
19500
19508
  setOptionsChanged(false);
19501
19509
  }
19502
19510
 
19503
- var _useState9 = React.useState(null),
19504
- _useState10 = _slicedToArray(_useState9, 2),
19505
- timer = _useState10[0],
19506
- setTimer = _useState10[1];
19511
+ var _useState13 = React.useState(null),
19512
+ _useState14 = _slicedToArray(_useState13, 2),
19513
+ timer = _useState14[0],
19514
+ setTimer = _useState14[1];
19507
19515
 
19508
19516
  var optionRefs = React.useRef(_toConsumableArray(Array(options.length)).map(function () {
19509
19517
  return /*#__PURE__*/React.createRef();
@@ -19519,6 +19527,10 @@ var Dropdown = function Dropdown(_ref9) {
19519
19527
  };
19520
19528
 
19521
19529
  var onKeyDown = function onKeyDown(e) {
19530
+ var _optionRefs$current$l, _optionRefs$current;
19531
+
19532
+ console.log("key down event is", e.target);
19533
+ console.log("key down event value is", e.target.value);
19522
19534
  var key = e.key,
19523
19535
  keyCode = e.keyCode;
19524
19536
  var focus = document.activeElement;
@@ -19574,16 +19586,30 @@ var Dropdown = function Dropdown(_ref9) {
19574
19586
  e.preventDefault();
19575
19587
  setInputValue(inputValue.slice(0, -1));
19576
19588
  break;
19577
- }
19578
19589
 
19579
- if (keyCode > 64 && keyCode < 91 || keyCode == 32 || keyCode == 189) {
19580
- e.preventDefault();
19581
- setInputValue(inputValue + key);
19590
+ case "Home":
19591
+ e.preventDefault();
19592
+ optionRefs.current[0].current.focus();
19593
+ break;
19594
+
19595
+ case "End":
19596
+ e.preventDefault();
19597
+ 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();
19598
+ break;
19582
19599
  }
19583
19600
  };
19584
19601
 
19585
19602
  React.useEffect(function () {
19586
- if (isOpen && optionRefs.current[0].current) {
19603
+ console.log("option refs in isopen useffect", optionRefs);
19604
+ console.log("option ref current in isopen useffect", optionRefs.current[0].current);
19605
+ console.log("selected refs in isopen useffect", selectedRef);
19606
+ console.log("value in isopen useffect", value);
19607
+
19608
+ if (isOpen && selectedRef !== undefined && selectedRef.current !== null) {
19609
+ // WAI-ARIA requires the selected option to receive focus
19610
+ selectedRef.current.focus();
19611
+ } else if (isOpen && optionRefs.current[0].current) {
19612
+ // If no selected option, first option receives focus
19587
19613
  optionRefs.current[0].current.focus();
19588
19614
  }
19589
19615
 
@@ -19591,16 +19617,21 @@ var Dropdown = function Dropdown(_ref9) {
19591
19617
  setInputValue("");
19592
19618
  }, [isOpen]);
19593
19619
  React.useEffect(function () {
19594
- clearTimeout(timer);
19595
- setTimer(setTimeout(function () {
19596
- return setInputValue("");
19597
- }, 2000));
19620
+ if (autoEraseTypeAhead) {
19621
+ clearTimeout(timer);
19622
+ setTimer(setTimeout(function () {
19623
+ return setInputValue("");
19624
+ }, 3000));
19625
+ }
19626
+
19598
19627
  setFilteredOptions(options.filter(function (option) {
19599
19628
  return option.value.toLowerCase().startsWith(inputValue.toLowerCase()) || option.text.toLowerCase().startsWith(inputValue.toLowerCase());
19600
19629
  }));
19601
19630
  }, [inputValue]);
19602
19631
  React.useEffect(function () {
19603
19632
  if (!isOpen && filteredOptions[0] && !disabledValues.includes(filteredOptions[0].value) && filteredOptions[0].text != placeholder) {
19633
+ console.log("filtered options are", filteredOptions);
19634
+ console.log("option refs are", optionRefs);
19604
19635
  onSelect(filteredOptions[0].value);
19605
19636
  }
19606
19637
 
@@ -19610,70 +19641,91 @@ var Dropdown = function Dropdown(_ref9) {
19610
19641
  dropdownRef.current.focus();
19611
19642
  }
19612
19643
  }, [filteredOptions]);
19613
- return /*#__PURE__*/React__default.createElement(Box, {
19614
- onKeyDown: onKeyDown,
19615
- onClick: onClick,
19616
- padding: "0",
19617
- width: "100%",
19618
- hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19619
- "aria-expanded": isOpen,
19620
- extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
19621
- title: hasTitles ? getSelection() : null
19644
+ return /*#__PURE__*/React__default.createElement(React.Fragment, null, /*#__PURE__*/React__default.createElement(Stack, {
19645
+ direction: "row",
19646
+ bottomItem: 2,
19647
+ extraStyles: "position: relative;"
19622
19648
  }, /*#__PURE__*/React__default.createElement(Box, {
19623
- as: "button",
19649
+ as: "input",
19650
+ "aria-multiline": "false",
19651
+ "aria-autocomplete": "list",
19652
+ "aria-controls": "".concat(ariaLabelledby, "_listbox"),
19653
+ "aria-activedescendant": "focused_option",
19654
+ "aria-owns": "".concat(ariaLabelledby, "_listbox"),
19655
+ "aria-haspopup": "listbox",
19656
+ "aria-labelledby": ariaLabelledby,
19657
+ "aria-expanded": isOpen,
19658
+ autocomplete: autocompleteValue,
19624
19659
  background: isOpen ? themeValues.hoverColor : WHITE,
19625
- width: "100%",
19626
- padding: "12px",
19627
- hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19660
+ borderRadius: "2px",
19628
19661
  borderSize: "1px",
19629
19662
  borderColor: isError ? ERROR_COLOR : isOpen ? themeValues.selectedColor : GREY_CHATEAU,
19630
- borderRadius: "2px",
19631
- tabIndex: 0,
19632
- dataQa: placeholder,
19633
- extraStyles: "height: 48px;\n ".concat(disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;", "\n ")
19634
- }, /*#__PURE__*/React__default.createElement(Stack, {
19635
- direction: "row",
19636
- bottomItem: 2
19637
- }, isOpen ? /*#__PURE__*/React__default.createElement(SearchInput, {
19638
- "aria-label": inputValue || "Dropdown awaiting search value",
19663
+ extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
19664
+ hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19665
+ isOpen: isOpen,
19666
+ name: autocompleteValue,
19667
+ onKeyDown: onKeyDown,
19668
+ onClick: onClick,
19669
+ onFocus: onClick,
19670
+ onChange: function onChange(e) {
19671
+ console.log("input change event", e.target);
19672
+ console.log("input change event value", e.target.value);
19673
+ setInputValue(e.target.value);
19674
+ },
19675
+ padding: "12px",
19676
+ placeholder: getSelection(),
19677
+ role: "combobox",
19678
+ themeValues: themeValues,
19679
+ title: hasTitles ? getSelection() : null,
19680
+ type: "text",
19681
+ tabIndex: -1,
19639
19682
  value: inputValue,
19640
- onChange: noop,
19641
- themeValues: themeValues
19642
- }) : /*#__PURE__*/React__default.createElement(Text$1, {
19643
- variant: "p",
19644
- extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;"
19645
- }, getSelection()), /*#__PURE__*/React__default.createElement(IconWrapper, {
19646
- open: isOpen
19647
- }, /*#__PURE__*/React__default.createElement(DropdownIcon, null)))), isOpen ? /*#__PURE__*/React__default.createElement(DropdownContentWrapper, {
19683
+ width: "100%",
19684
+ dataQa: placeholder
19685
+ }, isOpen ? /*#__PURE__*/React__default.createElement(DropdownContentWrapper, {
19648
19686
  maxHeight: maxHeight,
19649
19687
  open: isOpen,
19650
19688
  ref: dropdownRef,
19651
19689
  widthFitOptions: widthFitOptions,
19652
- tabIndex: 0
19690
+ tabIndex: 0,
19691
+ role: "listbox",
19692
+ id: "".concat(ariaLabelledby, "_listbox")
19653
19693
  }, /*#__PURE__*/React__default.createElement(Stack, {
19654
19694
  childGap: "0"
19655
19695
  }, filteredOptions.map(function (choice, i) {
19696
+ if (choice.value === value && selectedRef !== optionRefs.current[i]) {
19697
+ setSelectedRef(optionRefs.current[i]);
19698
+ }
19699
+
19656
19700
  return /*#__PURE__*/React__default.createElement(DropdownItemWrapper, {
19701
+ id: focusedRef === optionRefs.current[i] ? "focused_option" : choice.value,
19657
19702
  key: choice.value,
19658
19703
  ref: optionRefs.current[i],
19659
- as: "button",
19660
19704
  tabIndex: -1,
19661
19705
  onClick: disabledValues.includes(choice.value) ? function (evt) {
19662
19706
  return evt.preventDefault();
19663
19707
  } : function () {
19664
- return onSelect(choice.value);
19708
+ setSelectedRef(optionRefs.current[i]);
19709
+ onSelect(choice.value);
19665
19710
  },
19666
19711
  selected: choice.value === value,
19712
+ "aria-selected": choice.value === value,
19667
19713
  disabled: disabledValues.includes(choice.value),
19668
19714
  "data-qa": choice.text,
19669
19715
  themeValues: themeValues,
19670
- title: hasTitles ? choice.text : null
19716
+ title: hasTitles ? choice.text : null,
19717
+ role: "option",
19718
+ onFocus: function onFocus() {
19719
+ return setFocusedRef(optionRefs.current[i]);
19720
+ }
19671
19721
  }, /*#__PURE__*/React__default.createElement(Text$1, {
19672
19722
  variant: "p",
19673
19723
  color: choice.value === value ? WHITE : disabledValues.includes(choice.value) ? STORM_GREY : MINESHAFT_GREY,
19674
19724
  extraStyles: "padding-left: 16px; \n cursor: ".concat(disabledValues.includes(choice.value) ? "default" : "pointer", "; \n white-space: nowrap; \n overflow: hidden; \n text-overflow: ellipsis;")
19675
19725
  }, choice.text));
19676
- }))) : /*#__PURE__*/React__default.createElement(React.Fragment, null));
19726
+ }))) : /*#__PURE__*/React__default.createElement(React.Fragment, null)), /*#__PURE__*/React__default.createElement(IconWrapper, {
19727
+ open: isOpen
19728
+ }, /*#__PURE__*/React__default.createElement(DropdownIcon, null))));
19677
19729
  };
19678
19730
 
19679
19731
  var Dropdown$1 = themeComponent(Dropdown, "Dropdown", fallbackValues$e);
@@ -19774,7 +19826,8 @@ var FormSelect = function FormSelect(_ref) {
19774
19826
  disabled = _ref.disabled,
19775
19827
  themeValues = _ref.themeValues,
19776
19828
  _ref$hasTitles = _ref.hasTitles,
19777
- hasTitles = _ref$hasTitles === void 0 ? false : _ref$hasTitles;
19829
+ hasTitles = _ref$hasTitles === void 0 ? false : _ref$hasTitles,
19830
+ autocompleteValue = _ref.autocompleteValue;
19778
19831
 
19779
19832
  var _useState = React.useState(false),
19780
19833
  _useState2 = _slicedToArray(_useState, 2),
@@ -19812,7 +19865,7 @@ var FormSelect = function FormSelect(_ref) {
19812
19865
  extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
19813
19866
  id: labelTextWhenNoError.replace(/\s+/g, "-")
19814
19867
  }, labelTextWhenNoError))), /*#__PURE__*/React__default.createElement(Dropdown$1, {
19815
- "aria-labelledby": labelTextWhenNoError.replace(/\s+/g, "-"),
19868
+ ariaLabelledby: labelTextWhenNoError.replace(/\s+/g, "-"),
19816
19869
  maxHeight: dropdownMaxHeight,
19817
19870
  hasTitles: hasTitles,
19818
19871
  placeholder: options[0] ? options[0].text : "",
@@ -19829,7 +19882,8 @@ var FormSelect = function FormSelect(_ref) {
19829
19882
  onClick: function onClick() {
19830
19883
  return setOpen(!open);
19831
19884
  },
19832
- disabled: disabled
19885
+ disabled: disabled,
19886
+ autocompleteValue: autocompleteValue
19833
19887
  }), /*#__PURE__*/React__default.createElement(Stack, {
19834
19888
  direction: "row",
19835
19889
  justify: "space-between"
@@ -20602,7 +20656,8 @@ var CountryDropdown = function CountryDropdown(_ref) {
20602
20656
  labelTextWhenNoError: labelTextWhenNoError,
20603
20657
  errorMessages: errorMessages,
20604
20658
  showErrors: showErrors,
20605
- onChange: onChange
20659
+ onChange: onChange,
20660
+ autocompleteValue: "country-name"
20606
20661
  });
20607
20662
  };
20608
20663
 
@@ -33018,7 +33073,8 @@ var FormStateDropdown = function FormStateDropdown(_ref) {
33018
33073
  fieldActions: fieldActions,
33019
33074
  labelTextWhenNoError: labelTextWhenNoError,
33020
33075
  errorMessages: errorMessages,
33021
- showErrors: showErrors
33076
+ showErrors: showErrors,
33077
+ autocompleteValue: "address-level1"
33022
33078
  });
33023
33079
  };
33024
33080