@thecb/components 6.0.0-beta.1 → 6.0.0-beta.4
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
|
@@ -19460,7 +19460,10 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19460
19460
|
widthFitOptions = _ref9$widthFitOptions === void 0 ? false : _ref9$widthFitOptions,
|
|
19461
19461
|
disabled = _ref9.disabled,
|
|
19462
19462
|
_ref9$hasTitles = _ref9.hasTitles,
|
|
19463
|
-
hasTitles = _ref9$hasTitles === void 0 ? false : _ref9$hasTitles
|
|
19463
|
+
hasTitles = _ref9$hasTitles === void 0 ? false : _ref9$hasTitles,
|
|
19464
|
+
_ref9$autoEraseTypeAh = _ref9.autoEraseTypeAhead,
|
|
19465
|
+
autoEraseTypeAhead = _ref9$autoEraseTypeAh === void 0 ? true : _ref9$autoEraseTypeAh,
|
|
19466
|
+
ariaLabelledby = _ref9.ariaLabelledby;
|
|
19464
19467
|
|
|
19465
19468
|
var _useState = useState(""),
|
|
19466
19469
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -19482,6 +19485,11 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19482
19485
|
optionsChanged = _useState8[0],
|
|
19483
19486
|
setOptionsChanged = _useState8[1];
|
|
19484
19487
|
|
|
19488
|
+
var _useState9 = useState(undefined),
|
|
19489
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
19490
|
+
selectedRef = _useState10[0],
|
|
19491
|
+
setSelectedRef = _useState10[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
|
|
19496
|
-
|
|
19497
|
-
timer =
|
|
19498
|
-
setTimer =
|
|
19503
|
+
var _useState11 = useState(null),
|
|
19504
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
19505
|
+
timer = _useState12[0],
|
|
19506
|
+
setTimer = _useState12[1];
|
|
19499
19507
|
|
|
19500
19508
|
var optionRefs = useRef(_toConsumableArray(Array(options.length)).map(function () {
|
|
19501
19509
|
return /*#__PURE__*/createRef();
|
|
@@ -19511,6 +19519,8 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19511
19519
|
};
|
|
19512
19520
|
|
|
19513
19521
|
var onKeyDown = function onKeyDown(e) {
|
|
19522
|
+
var _optionRefs$current$l, _optionRefs$current;
|
|
19523
|
+
|
|
19514
19524
|
var key = e.key,
|
|
19515
19525
|
keyCode = e.keyCode;
|
|
19516
19526
|
var focus = document.activeElement;
|
|
@@ -19566,6 +19576,16 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19566
19576
|
e.preventDefault();
|
|
19567
19577
|
setInputValue(inputValue.slice(0, -1));
|
|
19568
19578
|
break;
|
|
19579
|
+
|
|
19580
|
+
case "Home":
|
|
19581
|
+
e.preventDefault();
|
|
19582
|
+
optionRefs.current[0].current.focus();
|
|
19583
|
+
break;
|
|
19584
|
+
|
|
19585
|
+
case "End":
|
|
19586
|
+
e.preventDefault();
|
|
19587
|
+
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();
|
|
19588
|
+
break;
|
|
19569
19589
|
}
|
|
19570
19590
|
|
|
19571
19591
|
if (keyCode > 64 && keyCode < 91 || keyCode == 32 || keyCode == 189) {
|
|
@@ -19575,7 +19595,15 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19575
19595
|
};
|
|
19576
19596
|
|
|
19577
19597
|
useEffect$1(function () {
|
|
19578
|
-
|
|
19598
|
+
console.log("option refs in isopen useffect", optionRefs.current[0].current);
|
|
19599
|
+
console.log("selected refs in isopen useffect", selectedRef);
|
|
19600
|
+
console.log("value in isopen useffect", value);
|
|
19601
|
+
|
|
19602
|
+
if (isOpen && selectedRef !== undefined) {
|
|
19603
|
+
// WAI-ARIA requires the selected option to receive focus
|
|
19604
|
+
selectedRef.current.focus();
|
|
19605
|
+
} else if (isOpen && optionRefs.current[0].current) {
|
|
19606
|
+
// If no selected option, first option receives focus
|
|
19579
19607
|
optionRefs.current[0].current.focus();
|
|
19580
19608
|
}
|
|
19581
19609
|
|
|
@@ -19583,10 +19611,13 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19583
19611
|
setInputValue("");
|
|
19584
19612
|
}, [isOpen]);
|
|
19585
19613
|
useEffect$1(function () {
|
|
19586
|
-
|
|
19587
|
-
|
|
19588
|
-
|
|
19589
|
-
|
|
19614
|
+
if (autoEraseTypeAhead) {
|
|
19615
|
+
clearTimeout(timer);
|
|
19616
|
+
setTimer(setTimeout(function () {
|
|
19617
|
+
return setInputValue("");
|
|
19618
|
+
}, 2000));
|
|
19619
|
+
}
|
|
19620
|
+
|
|
19590
19621
|
setFilteredOptions(options.filter(function (option) {
|
|
19591
19622
|
return option.value.toLowerCase().startsWith(inputValue.toLowerCase()) || option.text.toLowerCase().startsWith(inputValue.toLowerCase());
|
|
19592
19623
|
}));
|
|
@@ -19609,6 +19640,10 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19609
19640
|
width: "100%",
|
|
19610
19641
|
hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
|
|
19611
19642
|
"aria-expanded": isOpen,
|
|
19643
|
+
role: "combobox",
|
|
19644
|
+
"aria-owns": "".concat(ariaLabelledby, "_listbox"),
|
|
19645
|
+
"aria-haspopup": "listbox",
|
|
19646
|
+
"aria-labelledby": ariaLabelledby,
|
|
19612
19647
|
extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
|
|
19613
19648
|
title: hasTitles ? getSelection() : null
|
|
19614
19649
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
@@ -19620,32 +19655,43 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19620
19655
|
borderSize: "1px",
|
|
19621
19656
|
borderColor: isError ? ERROR_COLOR : isOpen ? themeValues.selectedColor : GREY_CHATEAU,
|
|
19622
19657
|
borderRadius: "2px",
|
|
19623
|
-
tabIndex: 0,
|
|
19624
19658
|
dataQa: placeholder,
|
|
19625
19659
|
extraStyles: "height: 48px;\n ".concat(disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;", "\n ")
|
|
19626
19660
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
19627
19661
|
direction: "row",
|
|
19628
19662
|
bottomItem: 2
|
|
19629
|
-
},
|
|
19630
|
-
"aria-label":
|
|
19663
|
+
}, /*#__PURE__*/React.createElement(SearchInput, {
|
|
19664
|
+
"aria-label": getSelection(),
|
|
19665
|
+
placeholder: getSelection(),
|
|
19631
19666
|
value: inputValue,
|
|
19632
19667
|
onChange: noop,
|
|
19633
|
-
themeValues: themeValues
|
|
19634
|
-
|
|
19635
|
-
|
|
19636
|
-
|
|
19637
|
-
|
|
19668
|
+
themeValues: themeValues,
|
|
19669
|
+
role: "searchbox",
|
|
19670
|
+
type: "text",
|
|
19671
|
+
"aria-multiline": "false",
|
|
19672
|
+
"aria-autocomplete": "list",
|
|
19673
|
+
"aria-controls": "".concat(ariaLabelledby, "_listbox"),
|
|
19674
|
+
"aria-activedescendant": "selected_option",
|
|
19675
|
+
tabIndex: 0
|
|
19676
|
+
}), /*#__PURE__*/React.createElement(IconWrapper, {
|
|
19638
19677
|
open: isOpen
|
|
19639
19678
|
}, /*#__PURE__*/React.createElement(DropdownIcon, null)))), isOpen ? /*#__PURE__*/React.createElement(DropdownContentWrapper, {
|
|
19640
19679
|
maxHeight: maxHeight,
|
|
19641
19680
|
open: isOpen,
|
|
19642
19681
|
ref: dropdownRef,
|
|
19643
19682
|
widthFitOptions: widthFitOptions,
|
|
19644
|
-
tabIndex: 0
|
|
19683
|
+
tabIndex: 0,
|
|
19684
|
+
role: "listbox",
|
|
19685
|
+
id: "".concat(ariaLabelledby, "_listbox")
|
|
19645
19686
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
19646
19687
|
childGap: "0"
|
|
19647
19688
|
}, filteredOptions.map(function (choice, i) {
|
|
19689
|
+
if (selectedRef === undefined && choice.value === value) {
|
|
19690
|
+
setSelectedRef(optionRefs.current[i]);
|
|
19691
|
+
}
|
|
19692
|
+
|
|
19648
19693
|
return /*#__PURE__*/React.createElement(DropdownItemWrapper, {
|
|
19694
|
+
id: choice.value === value ? "selected_option" : choice.value,
|
|
19649
19695
|
key: choice.value,
|
|
19650
19696
|
ref: optionRefs.current[i],
|
|
19651
19697
|
as: "button",
|
|
@@ -19656,10 +19702,12 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19656
19702
|
return onSelect(choice.value);
|
|
19657
19703
|
},
|
|
19658
19704
|
selected: choice.value === value,
|
|
19705
|
+
"aria-selected": choice.value === value,
|
|
19659
19706
|
disabled: disabledValues.includes(choice.value),
|
|
19660
19707
|
"data-qa": choice.text,
|
|
19661
19708
|
themeValues: themeValues,
|
|
19662
|
-
title: hasTitles ? choice.text : null
|
|
19709
|
+
title: hasTitles ? choice.text : null,
|
|
19710
|
+
role: "option"
|
|
19663
19711
|
}, /*#__PURE__*/React.createElement(Text$1, {
|
|
19664
19712
|
variant: "p",
|
|
19665
19713
|
color: choice.value === value ? WHITE : disabledValues.includes(choice.value) ? STORM_GREY : MINESHAFT_GREY,
|
|
@@ -19804,7 +19852,7 @@ var FormSelect = function FormSelect(_ref) {
|
|
|
19804
19852
|
extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
|
|
19805
19853
|
id: labelTextWhenNoError.replace(/\s+/g, "-")
|
|
19806
19854
|
}, labelTextWhenNoError))), /*#__PURE__*/React.createElement(Dropdown$1, {
|
|
19807
|
-
|
|
19855
|
+
ariaLabelledby: labelTextWhenNoError.replace(/\s+/g, "-"),
|
|
19808
19856
|
maxHeight: dropdownMaxHeight,
|
|
19809
19857
|
hasTitles: hasTitles,
|
|
19810
19858
|
placeholder: options[0] ? options[0].text : "",
|