@thecb/components 6.0.0-beta.0 → 6.0.0-beta.11

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
@@ -19422,7 +19422,7 @@ var DropdownContentWrapper = styled__default.div.withConfig({
19422
19422
  var maxHeight = _ref3.maxHeight;
19423
19423
  return maxHeight || "400px";
19424
19424
  });
19425
- var DropdownItemWrapper = styled__default.div.withConfig({
19425
+ var DropdownItemWrapper = styled__default.li.withConfig({
19426
19426
  displayName: "Dropdown__DropdownItemWrapper",
19427
19427
  componentId: "sc-pn6m0h-2"
19428
19428
  })(["background-color:", ";text-align:start;border-width:0px;border-color:transparent;box-shadow:none;padding:1rem;box-sizing:border-box;width:100%;cursor:", ";&:hover{background-color:", ";}&:focus{background-color:", ";outline:none;}"], function (_ref4) {
@@ -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,9 +19527,14 @@ 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;
19537
+ console.log("dropdown value is", value);
19525
19538
  console.log("focus is", focus);
19526
19539
  console.log("option refs are", optionRefs.current);
19527
19540
  var optionEl = optionRefs.current.find(function (ref) {
@@ -19573,16 +19586,37 @@ var Dropdown = function Dropdown(_ref9) {
19573
19586
  e.preventDefault();
19574
19587
  setInputValue(inputValue.slice(0, -1));
19575
19588
  break;
19576
- }
19577
19589
 
19578
- if (keyCode > 64 && keyCode < 91 || keyCode == 32 || keyCode == 189) {
19579
- e.preventDefault();
19580
- 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;
19599
+
19600
+ case "Escape":
19601
+ if (isOpen) {
19602
+ onClick();
19603
+ }
19604
+
19605
+ break;
19581
19606
  }
19582
19607
  };
19583
19608
 
19584
19609
  React.useEffect(function () {
19585
- if (isOpen && optionRefs.current[0].current) {
19610
+ console.log("option refs in isopen useffect", optionRefs);
19611
+ console.log("option ref current in isopen useffect", optionRefs.current[0].current);
19612
+ console.log("selected refs in isopen useffect", selectedRef);
19613
+ console.log("value in isopen useffect", value);
19614
+
19615
+ if (isOpen && selectedRef !== undefined && selectedRef.current !== null) {
19616
+ // WAI-ARIA requires the selected option to receive focus
19617
+ selectedRef.current.focus();
19618
+ } else if (isOpen && optionRefs.current[0].current) {
19619
+ // If no selected option, first option receives focus
19586
19620
  optionRefs.current[0].current.focus();
19587
19621
  }
19588
19622
 
@@ -19590,16 +19624,21 @@ var Dropdown = function Dropdown(_ref9) {
19590
19624
  setInputValue("");
19591
19625
  }, [isOpen]);
19592
19626
  React.useEffect(function () {
19593
- clearTimeout(timer);
19594
- setTimer(setTimeout(function () {
19595
- return setInputValue("");
19596
- }, 2000));
19627
+ if (autoEraseTypeAhead) {
19628
+ clearTimeout(timer);
19629
+ setTimer(setTimeout(function () {
19630
+ return setInputValue("");
19631
+ }, 3000));
19632
+ }
19633
+
19597
19634
  setFilteredOptions(options.filter(function (option) {
19598
19635
  return option.value.toLowerCase().startsWith(inputValue.toLowerCase()) || option.text.toLowerCase().startsWith(inputValue.toLowerCase());
19599
19636
  }));
19600
19637
  }, [inputValue]);
19601
19638
  React.useEffect(function () {
19602
19639
  if (!isOpen && filteredOptions[0] && !disabledValues.includes(filteredOptions[0].value) && filteredOptions[0].text != placeholder) {
19640
+ console.log("filtered options are", filteredOptions);
19641
+ console.log("option refs are", optionRefs);
19603
19642
  onSelect(filteredOptions[0].value);
19604
19643
  }
19605
19644
 
@@ -19609,70 +19648,92 @@ var Dropdown = function Dropdown(_ref9) {
19609
19648
  dropdownRef.current.focus();
19610
19649
  }
19611
19650
  }, [filteredOptions]);
19612
- return /*#__PURE__*/React__default.createElement(Box, {
19613
- onKeyDown: onKeyDown,
19614
- onClick: onClick,
19615
- padding: "0",
19616
- width: "100%",
19617
- hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19618
- "aria-expanded": isOpen,
19619
- extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
19620
- title: hasTitles ? getSelection() : null
19651
+ return /*#__PURE__*/React__default.createElement(React.Fragment, null, /*#__PURE__*/React__default.createElement(Stack, {
19652
+ direction: "row",
19653
+ bottomItem: 2,
19654
+ extraStyles: "position: relative;"
19621
19655
  }, /*#__PURE__*/React__default.createElement(Box, {
19622
- as: "button",
19656
+ as: "input",
19657
+ "aria-multiline": "false",
19658
+ "aria-autocomplete": "list",
19659
+ "aria-controls": "".concat(ariaLabelledby, "_listbox"),
19660
+ "aria-activedescendant": "focused_option",
19661
+ "aria-owns": "".concat(ariaLabelledby, "_listbox"),
19662
+ "aria-haspopup": "listbox",
19663
+ "aria-labelledby": ariaLabelledby,
19664
+ "aria-expanded": isOpen,
19665
+ autocomplete: autocompleteValue,
19623
19666
  background: isOpen ? themeValues.hoverColor : WHITE,
19624
- width: "100%",
19625
- padding: "12px",
19626
- hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19667
+ borderRadius: "2px",
19627
19668
  borderSize: "1px",
19628
19669
  borderColor: isError ? ERROR_COLOR : isOpen ? themeValues.selectedColor : GREY_CHATEAU,
19629
- borderRadius: "2px",
19630
- tabIndex: 0,
19631
- dataQa: placeholder,
19632
- extraStyles: "height: 48px;\n ".concat(disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;", "\n ")
19633
- }, /*#__PURE__*/React__default.createElement(Stack, {
19634
- direction: "row",
19635
- bottomItem: 2
19636
- }, isOpen ? /*#__PURE__*/React__default.createElement(SearchInput, {
19637
- "aria-label": inputValue || "Dropdown awaiting search value",
19670
+ extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
19671
+ hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19672
+ isOpen: isOpen,
19673
+ name: autocompleteValue,
19674
+ onKeyDown: onKeyDown,
19675
+ onClick: onClick,
19676
+ onFocus: onClick,
19677
+ onChange: function onChange(e) {
19678
+ console.log("input change event", e.target);
19679
+ console.log("input change event value", e.target.value);
19680
+ setInputValue(e.target.value);
19681
+ },
19682
+ padding: "12px",
19683
+ placeholder: getSelection(),
19684
+ role: "combobox",
19685
+ themeValues: themeValues,
19686
+ title: hasTitles ? getSelection() : null,
19687
+ type: "text",
19688
+ tabIndex: -1,
19638
19689
  value: inputValue,
19639
- onChange: noop,
19640
- themeValues: themeValues
19641
- }) : /*#__PURE__*/React__default.createElement(Text$1, {
19642
- variant: "p",
19643
- extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;"
19644
- }, getSelection()), /*#__PURE__*/React__default.createElement(IconWrapper, {
19690
+ width: "100%",
19691
+ dataQa: placeholder
19692
+ }), /*#__PURE__*/React__default.createElement(IconWrapper, {
19645
19693
  open: isOpen
19646
- }, /*#__PURE__*/React__default.createElement(DropdownIcon, null)))), isOpen ? /*#__PURE__*/React__default.createElement(DropdownContentWrapper, {
19694
+ }, /*#__PURE__*/React__default.createElement(DropdownIcon, null))), /*#__PURE__*/React__default.createElement(React.Fragment, null, isOpen ? /*#__PURE__*/React__default.createElement(DropdownContentWrapper, {
19647
19695
  maxHeight: maxHeight,
19648
19696
  open: isOpen,
19649
19697
  ref: dropdownRef,
19650
19698
  widthFitOptions: widthFitOptions,
19651
- tabIndex: 0
19699
+ tabIndex: 0,
19700
+ role: "listbox",
19701
+ id: "".concat(ariaLabelledby, "_listbox")
19652
19702
  }, /*#__PURE__*/React__default.createElement(Stack, {
19653
- childGap: "0"
19703
+ childGap: "0",
19704
+ as: "ul"
19654
19705
  }, filteredOptions.map(function (choice, i) {
19706
+ if (choice.value === value && selectedRef !== optionRefs.current[i]) {
19707
+ setSelectedRef(optionRefs.current[i]);
19708
+ }
19709
+
19655
19710
  return /*#__PURE__*/React__default.createElement(DropdownItemWrapper, {
19711
+ id: focusedRef === optionRefs.current[i] ? "focused_option" : choice.value,
19656
19712
  key: choice.value,
19657
19713
  ref: optionRefs.current[i],
19658
- as: "button",
19659
19714
  tabIndex: -1,
19660
19715
  onClick: disabledValues.includes(choice.value) ? function (evt) {
19661
19716
  return evt.preventDefault();
19662
19717
  } : function () {
19663
- return onSelect(choice.value);
19718
+ setSelectedRef(optionRefs.current[i]);
19719
+ onSelect(choice.value);
19664
19720
  },
19665
19721
  selected: choice.value === value,
19722
+ "aria-selected": choice.value === value,
19666
19723
  disabled: disabledValues.includes(choice.value),
19667
19724
  "data-qa": choice.text,
19668
19725
  themeValues: themeValues,
19669
- title: hasTitles ? choice.text : null
19726
+ title: hasTitles ? choice.text : null,
19727
+ role: "option",
19728
+ onFocus: function onFocus() {
19729
+ return setFocusedRef(optionRefs.current[i]);
19730
+ }
19670
19731
  }, /*#__PURE__*/React__default.createElement(Text$1, {
19671
19732
  variant: "p",
19672
19733
  color: choice.value === value ? WHITE : disabledValues.includes(choice.value) ? STORM_GREY : MINESHAFT_GREY,
19673
19734
  extraStyles: "padding-left: 16px; \n cursor: ".concat(disabledValues.includes(choice.value) ? "default" : "pointer", "; \n white-space: nowrap; \n overflow: hidden; \n text-overflow: ellipsis;")
19674
19735
  }, choice.text));
19675
- }))) : /*#__PURE__*/React__default.createElement(React.Fragment, null));
19736
+ }))) : /*#__PURE__*/React__default.createElement(React.Fragment, null)));
19676
19737
  };
19677
19738
 
19678
19739
  var Dropdown$1 = themeComponent(Dropdown, "Dropdown", fallbackValues$e);
@@ -19773,7 +19834,8 @@ var FormSelect = function FormSelect(_ref) {
19773
19834
  disabled = _ref.disabled,
19774
19835
  themeValues = _ref.themeValues,
19775
19836
  _ref$hasTitles = _ref.hasTitles,
19776
- hasTitles = _ref$hasTitles === void 0 ? false : _ref$hasTitles;
19837
+ hasTitles = _ref$hasTitles === void 0 ? false : _ref$hasTitles,
19838
+ autocompleteValue = _ref.autocompleteValue;
19777
19839
 
19778
19840
  var _useState = React.useState(false),
19779
19841
  _useState2 = _slicedToArray(_useState, 2),
@@ -19811,7 +19873,7 @@ var FormSelect = function FormSelect(_ref) {
19811
19873
  extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
19812
19874
  id: labelTextWhenNoError.replace(/\s+/g, "-")
19813
19875
  }, labelTextWhenNoError))), /*#__PURE__*/React__default.createElement(Dropdown$1, {
19814
- "aria-labelledby": labelTextWhenNoError.replace(/\s+/g, "-"),
19876
+ ariaLabelledby: labelTextWhenNoError.replace(/\s+/g, "-"),
19815
19877
  maxHeight: dropdownMaxHeight,
19816
19878
  hasTitles: hasTitles,
19817
19879
  placeholder: options[0] ? options[0].text : "",
@@ -19828,7 +19890,8 @@ var FormSelect = function FormSelect(_ref) {
19828
19890
  onClick: function onClick() {
19829
19891
  return setOpen(!open);
19830
19892
  },
19831
- disabled: disabled
19893
+ disabled: disabled,
19894
+ autocompleteValue: autocompleteValue
19832
19895
  }), /*#__PURE__*/React__default.createElement(Stack, {
19833
19896
  direction: "row",
19834
19897
  justify: "space-between"
@@ -20601,7 +20664,8 @@ var CountryDropdown = function CountryDropdown(_ref) {
20601
20664
  labelTextWhenNoError: labelTextWhenNoError,
20602
20665
  errorMessages: errorMessages,
20603
20666
  showErrors: showErrors,
20604
- onChange: onChange
20667
+ onChange: onChange,
20668
+ autocompleteValue: "country-name"
20605
20669
  });
20606
20670
  };
20607
20671
 
@@ -33017,7 +33081,8 @@ var FormStateDropdown = function FormStateDropdown(_ref) {
33017
33081
  fieldActions: fieldActions,
33018
33082
  labelTextWhenNoError: labelTextWhenNoError,
33019
33083
  errorMessages: errorMessages,
33020
- showErrors: showErrors
33084
+ showErrors: showErrors,
33085
+ autocompleteValue: "address-level1"
33021
33086
  });
33022
33087
  };
33023
33088