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

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
@@ -6372,7 +6372,7 @@ var Box = function Box(_ref) {
6372
6372
  onFocus: onFocus,
6373
6373
  onBlur: onBlur,
6374
6374
  onTouchEnd: onTouchEnd
6375
- }, rest), safeChildren(children, /*#__PURE__*/React.createElement(Fragment, null)));
6375
+ }, rest), children && safeChildren(children, /*#__PURE__*/React.createElement(Fragment, null)));
6376
6376
  };
6377
6377
 
6378
6378
  var CenterWrapper = styled.div.withConfig({
@@ -19414,7 +19414,7 @@ var DropdownContentWrapper = styled.div.withConfig({
19414
19414
  var maxHeight = _ref3.maxHeight;
19415
19415
  return maxHeight || "400px";
19416
19416
  });
19417
- var DropdownItemWrapper = styled.div.withConfig({
19417
+ var DropdownItemWrapper = styled.li.withConfig({
19418
19418
  displayName: "Dropdown__DropdownItemWrapper",
19419
19419
  componentId: "sc-pn6m0h-2"
19420
19420
  })(["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) {
@@ -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,37 @@ 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;
19591
+
19592
+ case "Escape":
19593
+ if (isOpen) {
19594
+ onClick();
19595
+ }
19596
+
19597
+ break;
19574
19598
  }
19575
19599
  };
19576
19600
 
19577
19601
  useEffect$1(function () {
19578
- if (isOpen && optionRefs.current[0].current) {
19602
+ console.log("option refs in isopen useffect", optionRefs);
19603
+ console.log("option ref current in isopen useffect", optionRefs.current[0].current);
19604
+ console.log("selected refs in isopen useffect", selectedRef);
19605
+ console.log("value in isopen useffect", value);
19606
+
19607
+ if (isOpen && selectedRef !== undefined && selectedRef.current !== null) {
19608
+ // WAI-ARIA requires the selected option to receive focus
19609
+ selectedRef.current.focus();
19610
+ } else if (isOpen && optionRefs.current[0].current) {
19611
+ // If no selected option, first option receives focus
19579
19612
  optionRefs.current[0].current.focus();
19580
19613
  }
19581
19614
 
@@ -19583,16 +19616,21 @@ var Dropdown = function Dropdown(_ref9) {
19583
19616
  setInputValue("");
19584
19617
  }, [isOpen]);
19585
19618
  useEffect$1(function () {
19586
- clearTimeout(timer);
19587
- setTimer(setTimeout(function () {
19588
- return setInputValue("");
19589
- }, 2000));
19619
+ if (autoEraseTypeAhead) {
19620
+ clearTimeout(timer);
19621
+ setTimer(setTimeout(function () {
19622
+ return setInputValue("");
19623
+ }, 3000));
19624
+ }
19625
+
19590
19626
  setFilteredOptions(options.filter(function (option) {
19591
19627
  return option.value.toLowerCase().startsWith(inputValue.toLowerCase()) || option.text.toLowerCase().startsWith(inputValue.toLowerCase());
19592
19628
  }));
19593
19629
  }, [inputValue]);
19594
19630
  useEffect$1(function () {
19595
19631
  if (!isOpen && filteredOptions[0] && !disabledValues.includes(filteredOptions[0].value) && filteredOptions[0].text != placeholder) {
19632
+ console.log("filtered options are", filteredOptions);
19633
+ console.log("option refs are", optionRefs);
19596
19634
  onSelect(filteredOptions[0].value);
19597
19635
  }
19598
19636
 
@@ -19602,70 +19640,92 @@ var Dropdown = function Dropdown(_ref9) {
19602
19640
  dropdownRef.current.focus();
19603
19641
  }
19604
19642
  }, [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
19643
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Stack, {
19644
+ direction: "row",
19645
+ bottomItem: 2,
19646
+ extraStyles: "position: relative;"
19614
19647
  }, /*#__PURE__*/React.createElement(Box, {
19615
- as: "button",
19648
+ as: "input",
19649
+ "aria-multiline": "false",
19650
+ "aria-autocomplete": "list",
19651
+ "aria-controls": "".concat(ariaLabelledby, "_listbox"),
19652
+ "aria-activedescendant": "focused_option",
19653
+ "aria-owns": "".concat(ariaLabelledby, "_listbox"),
19654
+ "aria-haspopup": "listbox",
19655
+ "aria-labelledby": ariaLabelledby,
19656
+ "aria-expanded": isOpen,
19657
+ autocomplete: autocompleteValue,
19616
19658
  background: isOpen ? themeValues.hoverColor : WHITE,
19617
- width: "100%",
19618
- padding: "12px",
19619
- hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19659
+ borderRadius: "2px",
19620
19660
  borderSize: "1px",
19621
19661
  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",
19662
+ extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
19663
+ hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
19664
+ isOpen: isOpen,
19665
+ name: autocompleteValue,
19666
+ onKeyDown: onKeyDown,
19667
+ onClick: onClick,
19668
+ onFocus: onClick,
19669
+ onChange: function onChange(e) {
19670
+ console.log("input change event", e.target);
19671
+ console.log("input change event value", e.target.value);
19672
+ setInputValue(e.target.value);
19673
+ },
19674
+ padding: "12px",
19675
+ placeholder: getSelection(),
19676
+ role: "combobox",
19677
+ themeValues: themeValues,
19678
+ title: hasTitles ? getSelection() : null,
19679
+ type: "text",
19680
+ tabIndex: -1,
19631
19681
  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, {
19682
+ width: "100%",
19683
+ dataQa: placeholder
19684
+ }), /*#__PURE__*/React.createElement(IconWrapper, {
19638
19685
  open: isOpen
19639
- }, /*#__PURE__*/React.createElement(DropdownIcon, null)))), isOpen ? /*#__PURE__*/React.createElement(DropdownContentWrapper, {
19686
+ }, /*#__PURE__*/React.createElement(DropdownIcon, null))), /*#__PURE__*/React.createElement(Fragment, null, isOpen ? /*#__PURE__*/React.createElement(DropdownContentWrapper, {
19640
19687
  maxHeight: maxHeight,
19641
19688
  open: isOpen,
19642
19689
  ref: dropdownRef,
19643
19690
  widthFitOptions: widthFitOptions,
19644
- tabIndex: 0
19691
+ tabIndex: 0,
19692
+ role: "listbox",
19693
+ id: "".concat(ariaLabelledby, "_listbox")
19645
19694
  }, /*#__PURE__*/React.createElement(Stack, {
19646
- childGap: "0"
19695
+ childGap: "0",
19696
+ as: "ul"
19647
19697
  }, filteredOptions.map(function (choice, i) {
19698
+ if (choice.value === value && selectedRef !== optionRefs.current[i]) {
19699
+ setSelectedRef(optionRefs.current[i]);
19700
+ }
19701
+
19648
19702
  return /*#__PURE__*/React.createElement(DropdownItemWrapper, {
19703
+ id: focusedRef === optionRefs.current[i] ? "focused_option" : choice.value,
19649
19704
  key: choice.value,
19650
19705
  ref: optionRefs.current[i],
19651
- as: "button",
19652
19706
  tabIndex: -1,
19653
19707
  onClick: disabledValues.includes(choice.value) ? function (evt) {
19654
19708
  return evt.preventDefault();
19655
19709
  } : function () {
19656
- return onSelect(choice.value);
19710
+ setSelectedRef(optionRefs.current[i]);
19711
+ onSelect(choice.value);
19657
19712
  },
19658
19713
  selected: choice.value === value,
19714
+ "aria-selected": choice.value === value,
19659
19715
  disabled: disabledValues.includes(choice.value),
19660
19716
  "data-qa": choice.text,
19661
19717
  themeValues: themeValues,
19662
- title: hasTitles ? choice.text : null
19718
+ title: hasTitles ? choice.text : null,
19719
+ role: "option",
19720
+ onFocus: function onFocus() {
19721
+ return setFocusedRef(optionRefs.current[i]);
19722
+ }
19663
19723
  }, /*#__PURE__*/React.createElement(Text$1, {
19664
19724
  variant: "p",
19665
19725
  color: choice.value === value ? WHITE : disabledValues.includes(choice.value) ? STORM_GREY : MINESHAFT_GREY,
19666
19726
  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
19727
  }, choice.text));
19668
- }))) : /*#__PURE__*/React.createElement(Fragment, null));
19728
+ }))) : /*#__PURE__*/React.createElement(Fragment, null)));
19669
19729
  };
19670
19730
 
19671
19731
  var Dropdown$1 = themeComponent(Dropdown, "Dropdown", fallbackValues$e);
@@ -19766,7 +19826,8 @@ var FormSelect = function FormSelect(_ref) {
19766
19826
  disabled = _ref.disabled,
19767
19827
  themeValues = _ref.themeValues,
19768
19828
  _ref$hasTitles = _ref.hasTitles,
19769
- hasTitles = _ref$hasTitles === void 0 ? false : _ref$hasTitles;
19829
+ hasTitles = _ref$hasTitles === void 0 ? false : _ref$hasTitles,
19830
+ autocompleteValue = _ref.autocompleteValue;
19770
19831
 
19771
19832
  var _useState = useState(false),
19772
19833
  _useState2 = _slicedToArray(_useState, 2),
@@ -19804,7 +19865,7 @@ var FormSelect = function FormSelect(_ref) {
19804
19865
  extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
19805
19866
  id: labelTextWhenNoError.replace(/\s+/g, "-")
19806
19867
  }, labelTextWhenNoError))), /*#__PURE__*/React.createElement(Dropdown$1, {
19807
- "aria-labelledby": labelTextWhenNoError.replace(/\s+/g, "-"),
19868
+ ariaLabelledby: labelTextWhenNoError.replace(/\s+/g, "-"),
19808
19869
  maxHeight: dropdownMaxHeight,
19809
19870
  hasTitles: hasTitles,
19810
19871
  placeholder: options[0] ? options[0].text : "",
@@ -19821,7 +19882,8 @@ var FormSelect = function FormSelect(_ref) {
19821
19882
  onClick: function onClick() {
19822
19883
  return setOpen(!open);
19823
19884
  },
19824
- disabled: disabled
19885
+ disabled: disabled,
19886
+ autocompleteValue: autocompleteValue
19825
19887
  }), /*#__PURE__*/React.createElement(Stack, {
19826
19888
  direction: "row",
19827
19889
  justify: "space-between"
@@ -20594,7 +20656,8 @@ var CountryDropdown = function CountryDropdown(_ref) {
20594
20656
  labelTextWhenNoError: labelTextWhenNoError,
20595
20657
  errorMessages: errorMessages,
20596
20658
  showErrors: showErrors,
20597
- onChange: onChange
20659
+ onChange: onChange,
20660
+ autocompleteValue: "country-name"
20598
20661
  });
20599
20662
  };
20600
20663
 
@@ -33010,7 +33073,8 @@ var FormStateDropdown = function FormStateDropdown(_ref) {
33010
33073
  fieldActions: fieldActions,
33011
33074
  labelTextWhenNoError: labelTextWhenNoError,
33012
33075
  errorMessages: errorMessages,
33013
- showErrors: showErrors
33076
+ showErrors: showErrors,
33077
+ autocompleteValue: "address-level1"
33014
33078
  });
33015
33079
  };
33016
33080