@thecb/components 6.0.0-beta.2 → 6.0.0-beta.5
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,9 +19446,10 @@ 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
|
-
|
|
19449
|
+
})(["border:none;background-color:", ";font-size:16px;height:24px;min-width:75%;"], function (_ref8) {
|
|
19450
|
+
var themeValues = _ref8.themeValues,
|
|
19451
|
+
isOpen = _ref8.isOpen;
|
|
19452
|
+
return isOpen ? themeValues.hoverColor && themeValues.hoverColor : "WHITE";
|
|
19452
19453
|
});
|
|
19453
19454
|
|
|
19454
19455
|
var Dropdown = function Dropdown(_ref9) {
|
|
@@ -19468,7 +19469,10 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19468
19469
|
widthFitOptions = _ref9$widthFitOptions === void 0 ? false : _ref9$widthFitOptions,
|
|
19469
19470
|
disabled = _ref9.disabled,
|
|
19470
19471
|
_ref9$hasTitles = _ref9.hasTitles,
|
|
19471
|
-
hasTitles = _ref9$hasTitles === void 0 ? false : _ref9$hasTitles
|
|
19472
|
+
hasTitles = _ref9$hasTitles === void 0 ? false : _ref9$hasTitles,
|
|
19473
|
+
_ref9$autoEraseTypeAh = _ref9.autoEraseTypeAhead,
|
|
19474
|
+
autoEraseTypeAhead = _ref9$autoEraseTypeAh === void 0 ? true : _ref9$autoEraseTypeAh,
|
|
19475
|
+
ariaLabelledby = _ref9.ariaLabelledby;
|
|
19472
19476
|
|
|
19473
19477
|
var _useState = React.useState(""),
|
|
19474
19478
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -19490,6 +19494,11 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19490
19494
|
optionsChanged = _useState8[0],
|
|
19491
19495
|
setOptionsChanged = _useState8[1];
|
|
19492
19496
|
|
|
19497
|
+
var _useState9 = React.useState(undefined),
|
|
19498
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
19499
|
+
selectedRef = _useState10[0],
|
|
19500
|
+
setSelectedRef = _useState10[1];
|
|
19501
|
+
|
|
19493
19502
|
if (optionsState !== options) {
|
|
19494
19503
|
setOptionsState(options);
|
|
19495
19504
|
setOptionsChanged(true);
|
|
@@ -19500,10 +19509,10 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19500
19509
|
setOptionsChanged(false);
|
|
19501
19510
|
}
|
|
19502
19511
|
|
|
19503
|
-
var
|
|
19504
|
-
|
|
19505
|
-
timer =
|
|
19506
|
-
setTimer =
|
|
19512
|
+
var _useState11 = React.useState(null),
|
|
19513
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
19514
|
+
timer = _useState12[0],
|
|
19515
|
+
setTimer = _useState12[1];
|
|
19507
19516
|
|
|
19508
19517
|
var optionRefs = React.useRef(_toConsumableArray(Array(options.length)).map(function () {
|
|
19509
19518
|
return /*#__PURE__*/React.createRef();
|
|
@@ -19519,6 +19528,8 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19519
19528
|
};
|
|
19520
19529
|
|
|
19521
19530
|
var onKeyDown = function onKeyDown(e) {
|
|
19531
|
+
var _optionRefs$current$l, _optionRefs$current;
|
|
19532
|
+
|
|
19522
19533
|
var key = e.key,
|
|
19523
19534
|
keyCode = e.keyCode;
|
|
19524
19535
|
var focus = document.activeElement;
|
|
@@ -19572,10 +19583,18 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19572
19583
|
|
|
19573
19584
|
case "Backspace" :
|
|
19574
19585
|
e.preventDefault();
|
|
19575
|
-
console.log("input value is", inputValue);
|
|
19576
|
-
console.log("new input value will be", inputValue.slice(0, -1));
|
|
19577
19586
|
setInputValue(inputValue.slice(0, -1));
|
|
19578
19587
|
break;
|
|
19588
|
+
|
|
19589
|
+
case "Home":
|
|
19590
|
+
e.preventDefault();
|
|
19591
|
+
optionRefs.current[0].current.focus();
|
|
19592
|
+
break;
|
|
19593
|
+
|
|
19594
|
+
case "End":
|
|
19595
|
+
e.preventDefault();
|
|
19596
|
+
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();
|
|
19597
|
+
break;
|
|
19579
19598
|
}
|
|
19580
19599
|
|
|
19581
19600
|
if (keyCode > 64 && keyCode < 91 || keyCode == 32 || keyCode == 189) {
|
|
@@ -19586,9 +19605,14 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19586
19605
|
|
|
19587
19606
|
React.useEffect(function () {
|
|
19588
19607
|
console.log("option refs in isopen useffect", optionRefs.current[0].current);
|
|
19608
|
+
console.log("selected refs in isopen useffect", selectedRef);
|
|
19589
19609
|
console.log("value in isopen useffect", value);
|
|
19590
19610
|
|
|
19591
|
-
if (isOpen &&
|
|
19611
|
+
if (isOpen && selectedRef !== undefined) {
|
|
19612
|
+
// WAI-ARIA requires the selected option to receive focus
|
|
19613
|
+
selectedRef.current.focus();
|
|
19614
|
+
} else if (isOpen && optionRefs.current[0].current) {
|
|
19615
|
+
// If no selected option, first option receives focus
|
|
19592
19616
|
optionRefs.current[0].current.focus();
|
|
19593
19617
|
}
|
|
19594
19618
|
|
|
@@ -19596,10 +19620,13 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19596
19620
|
setInputValue("");
|
|
19597
19621
|
}, [isOpen]);
|
|
19598
19622
|
React.useEffect(function () {
|
|
19599
|
-
|
|
19600
|
-
|
|
19601
|
-
|
|
19602
|
-
|
|
19623
|
+
if (autoEraseTypeAhead) {
|
|
19624
|
+
clearTimeout(timer);
|
|
19625
|
+
setTimer(setTimeout(function () {
|
|
19626
|
+
return setInputValue("");
|
|
19627
|
+
}, 2000));
|
|
19628
|
+
}
|
|
19629
|
+
|
|
19603
19630
|
setFilteredOptions(options.filter(function (option) {
|
|
19604
19631
|
return option.value.toLowerCase().startsWith(inputValue.toLowerCase()) || option.text.toLowerCase().startsWith(inputValue.toLowerCase());
|
|
19605
19632
|
}));
|
|
@@ -19622,6 +19649,10 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19622
19649
|
width: "100%",
|
|
19623
19650
|
hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
|
|
19624
19651
|
"aria-expanded": isOpen,
|
|
19652
|
+
role: "combobox",
|
|
19653
|
+
"aria-owns": "".concat(ariaLabelledby, "_listbox"),
|
|
19654
|
+
"aria-haspopup": "listbox",
|
|
19655
|
+
"aria-labelledby": ariaLabelledby,
|
|
19625
19656
|
extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
|
|
19626
19657
|
title: hasTitles ? getSelection() : null
|
|
19627
19658
|
}, /*#__PURE__*/React__default.createElement(Box, {
|
|
@@ -19639,26 +19670,38 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19639
19670
|
}, /*#__PURE__*/React__default.createElement(Stack, {
|
|
19640
19671
|
direction: "row",
|
|
19641
19672
|
bottomItem: 2
|
|
19642
|
-
},
|
|
19643
|
-
"aria-label":
|
|
19673
|
+
}, /*#__PURE__*/React__default.createElement(SearchInput, {
|
|
19674
|
+
"aria-label": getSelection(),
|
|
19675
|
+
placeholder: getSelection(),
|
|
19644
19676
|
value: inputValue,
|
|
19645
19677
|
onChange: noop,
|
|
19646
|
-
themeValues: themeValues
|
|
19647
|
-
|
|
19648
|
-
|
|
19649
|
-
|
|
19650
|
-
|
|
19678
|
+
themeValues: themeValues,
|
|
19679
|
+
role: "searchbox",
|
|
19680
|
+
type: "text",
|
|
19681
|
+
"aria-multiline": "false",
|
|
19682
|
+
"aria-autocomplete": "list",
|
|
19683
|
+
"aria-controls": "".concat(ariaLabelledby, "_listbox"),
|
|
19684
|
+
"aria-activedescendant": "selected_option",
|
|
19685
|
+
isOpen: isOpen
|
|
19686
|
+
}), /*#__PURE__*/React__default.createElement(IconWrapper, {
|
|
19651
19687
|
open: isOpen
|
|
19652
19688
|
}, /*#__PURE__*/React__default.createElement(DropdownIcon, null)))), isOpen ? /*#__PURE__*/React__default.createElement(DropdownContentWrapper, {
|
|
19653
19689
|
maxHeight: maxHeight,
|
|
19654
19690
|
open: isOpen,
|
|
19655
19691
|
ref: dropdownRef,
|
|
19656
19692
|
widthFitOptions: widthFitOptions,
|
|
19657
|
-
tabIndex: 0
|
|
19693
|
+
tabIndex: 0,
|
|
19694
|
+
role: "listbox",
|
|
19695
|
+
id: "".concat(ariaLabelledby, "_listbox")
|
|
19658
19696
|
}, /*#__PURE__*/React__default.createElement(Stack, {
|
|
19659
19697
|
childGap: "0"
|
|
19660
19698
|
}, filteredOptions.map(function (choice, i) {
|
|
19699
|
+
if (choice.value === value && selectedRef !== optionRefs.current[i]) {
|
|
19700
|
+
setSelectedRef(optionRefs.current[i]);
|
|
19701
|
+
}
|
|
19702
|
+
|
|
19661
19703
|
return /*#__PURE__*/React__default.createElement(DropdownItemWrapper, {
|
|
19704
|
+
id: choice.value === value ? "selected_option" : choice.value,
|
|
19662
19705
|
key: choice.value,
|
|
19663
19706
|
ref: optionRefs.current[i],
|
|
19664
19707
|
as: "button",
|
|
@@ -19666,13 +19709,16 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19666
19709
|
onClick: disabledValues.includes(choice.value) ? function (evt) {
|
|
19667
19710
|
return evt.preventDefault();
|
|
19668
19711
|
} : function () {
|
|
19669
|
-
|
|
19712
|
+
setSelectedRef(optionRefs.current[i]);
|
|
19713
|
+
onSelect(choice.value);
|
|
19670
19714
|
},
|
|
19671
19715
|
selected: choice.value === value,
|
|
19716
|
+
"aria-selected": choice.value === value,
|
|
19672
19717
|
disabled: disabledValues.includes(choice.value),
|
|
19673
19718
|
"data-qa": choice.text,
|
|
19674
19719
|
themeValues: themeValues,
|
|
19675
|
-
title: hasTitles ? choice.text : null
|
|
19720
|
+
title: hasTitles ? choice.text : null,
|
|
19721
|
+
role: "option"
|
|
19676
19722
|
}, /*#__PURE__*/React__default.createElement(Text$1, {
|
|
19677
19723
|
variant: "p",
|
|
19678
19724
|
color: choice.value === value ? WHITE : disabledValues.includes(choice.value) ? STORM_GREY : MINESHAFT_GREY,
|
|
@@ -19817,7 +19863,7 @@ var FormSelect = function FormSelect(_ref) {
|
|
|
19817
19863
|
extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
|
|
19818
19864
|
id: labelTextWhenNoError.replace(/\s+/g, "-")
|
|
19819
19865
|
}, labelTextWhenNoError))), /*#__PURE__*/React__default.createElement(Dropdown$1, {
|
|
19820
|
-
|
|
19866
|
+
ariaLabelledby: labelTextWhenNoError.replace(/\s+/g, "-"),
|
|
19821
19867
|
maxHeight: dropdownMaxHeight,
|
|
19822
19868
|
hasTitles: hasTitles,
|
|
19823
19869
|
placeholder: options[0] ? options[0].text : "",
|