@spscommerce/ds-react 5.8.0 → 5.8.1
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/lib/index.cjs.js +58 -58
- package/lib/index.es.js +17 -9
- package/package.json +9 -9
package/lib/index.es.js
CHANGED
|
@@ -1290,7 +1290,7 @@ function compareOptions(optionA, optionB, comparisonKey) {
|
|
|
1290
1290
|
function isOptionDisabled(disabledOptions, comparisonKey, option) {
|
|
1291
1291
|
return comparisonKey ? !!(disabledOptions == null ? void 0 : disabledOptions.find((opt) => {
|
|
1292
1292
|
var _a;
|
|
1293
|
-
return opt[comparisonKey] && opt[comparisonKey] === ((_a = option.value) == null ? void 0 : _a[comparisonKey]);
|
|
1293
|
+
return opt[comparisonKey] && opt[comparisonKey] === ((_a = option == null ? void 0 : option.value) == null ? void 0 : _a[comparisonKey]);
|
|
1294
1294
|
})) : false;
|
|
1295
1295
|
}
|
|
1296
1296
|
const SpsOptionList = React.forwardRef((props2, ref2) => {
|
|
@@ -1415,7 +1415,10 @@ const SpsOptionList = React.forwardRef((props2, ref2) => {
|
|
|
1415
1415
|
}
|
|
1416
1416
|
}
|
|
1417
1417
|
}, [isOpen, onSelfToggle]);
|
|
1418
|
-
const selectOption = React.useCallback((option) => {
|
|
1418
|
+
const selectOption = React.useCallback((option, isDisabled) => {
|
|
1419
|
+
if (isDisabled) {
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1419
1422
|
if (option && !option.disabled) {
|
|
1420
1423
|
if (typeof option.value === "function") {
|
|
1421
1424
|
option.value();
|
|
@@ -1427,10 +1430,12 @@ const SpsOptionList = React.forwardRef((props2, ref2) => {
|
|
|
1427
1430
|
}
|
|
1428
1431
|
}
|
|
1429
1432
|
}, [onOptionSelected, closeSelf]);
|
|
1430
|
-
const handleOptionClick = React.useCallback((event, option) => {
|
|
1433
|
+
const handleOptionClick = React.useCallback((event, option, isDisabled) => {
|
|
1431
1434
|
event.stopPropagation();
|
|
1432
|
-
selectOption(option);
|
|
1435
|
+
selectOption(option, isDisabled);
|
|
1433
1436
|
}, [selectOption]);
|
|
1437
|
+
const disabledOptionsRef = React.useRef(disabledOptions || []);
|
|
1438
|
+
disabledOptionsRef.current = disabledOptions || [];
|
|
1434
1439
|
const handleArrowKeyDown = React.useCallback((event) => {
|
|
1435
1440
|
switch (event.key) {
|
|
1436
1441
|
case "Tab":
|
|
@@ -1441,10 +1446,11 @@ const SpsOptionList = React.forwardRef((props2, ref2) => {
|
|
|
1441
1446
|
if (highlightedOptionIndex > -1) {
|
|
1442
1447
|
const highlightedOption = optionList[highlightedOptionIndex] || specialActionOption;
|
|
1443
1448
|
event.preventDefault();
|
|
1444
|
-
|
|
1449
|
+
const isDisabled = !!highlightedOption && isOptionDisabled(disabledOptionsRef.current, comparisonKey, highlightedOption);
|
|
1450
|
+
if (!isDisabled && highlightedOption && typeof onOptionSelected === "function" && typeof highlightedOption.value === "function") {
|
|
1445
1451
|
highlightedOption.value();
|
|
1446
1452
|
} else if (highlightedOption) {
|
|
1447
|
-
selectOption(highlightedOption);
|
|
1453
|
+
selectOption(highlightedOption, isDisabled);
|
|
1448
1454
|
}
|
|
1449
1455
|
}
|
|
1450
1456
|
break;
|
|
@@ -1597,14 +1603,16 @@ const SpsOptionList = React.forwardRef((props2, ref2) => {
|
|
|
1597
1603
|
className: "sps-option-list__loading"
|
|
1598
1604
|
}, /* @__PURE__ */ React.createElement(SpsSpinner, null)), !loading && !searchState.pending && optionList.map((option, i2) => {
|
|
1599
1605
|
const identifier = `${id2}-option-${i2}`;
|
|
1606
|
+
const comparisonResult = compareOptions(option.value, selectedOption, comparisonKey);
|
|
1607
|
+
const isOptionDisabledResult = isOptionDisabled(disabledOptionsRef.current, comparisonKey, option);
|
|
1600
1608
|
return /* @__PURE__ */ React.createElement("a", {
|
|
1601
1609
|
key: identifier,
|
|
1602
1610
|
id: identifier,
|
|
1603
1611
|
role: optionRole,
|
|
1604
|
-
"aria-selected":
|
|
1612
|
+
"aria-selected": comparisonResult,
|
|
1605
1613
|
href: option.href,
|
|
1606
|
-
className: clsx("sps-option-list__option", option.caption && "sps-option-list__option--has-caption", option.disabled && "sps-option-list__option--disabled", option.bold && "sps-option-list__option--bold", (
|
|
1607
|
-
onClick: (event) => handleOptionClick(event, option),
|
|
1614
|
+
className: clsx("sps-option-list__option", option.caption && "sps-option-list__option--has-caption", option.disabled && "sps-option-list__option--disabled", option.bold && "sps-option-list__option--bold", (comparisonResult || isOptionDisabledResult) && "sps-option-list__option--selected", highlightedOptionIndex === i2 && "sps-option-list__option--highlighted"),
|
|
1615
|
+
onClick: (event) => handleOptionClick(event, option, isOptionDisabledResult),
|
|
1608
1616
|
onMouseOver: () => setHighlightedOptionIndex(i2),
|
|
1609
1617
|
tabIndex: -1,
|
|
1610
1618
|
ref: highlightedOptionIndex === i2 ? highlightedOptionRef : null,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spscommerce/ds-react",
|
|
3
3
|
"description": "SPS Design System React components",
|
|
4
|
-
"version": "5.8.
|
|
4
|
+
"version": "5.8.1",
|
|
5
5
|
"author": "SPS Commerce",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": "https://github.com/spscommerce/design-system/tree/main/packages/@spscommerce/ds-react",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@react-stately/collections": "^3.3.3",
|
|
31
|
-
"@spscommerce/ds-colors": "5.8.
|
|
32
|
-
"@spscommerce/ds-shared": "5.8.
|
|
33
|
-
"@spscommerce/positioning": "5.8.
|
|
34
|
-
"@spscommerce/utils": "5.8.
|
|
31
|
+
"@spscommerce/ds-colors": "5.8.1",
|
|
32
|
+
"@spscommerce/ds-shared": "5.8.1",
|
|
33
|
+
"@spscommerce/positioning": "5.8.1",
|
|
34
|
+
"@spscommerce/utils": "5.8.1",
|
|
35
35
|
"moment": "^2.25.3",
|
|
36
36
|
"moment-timezone": "^0.5.28",
|
|
37
37
|
"react": "^16.9.0",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@react-stately/collections": "^3.3.3",
|
|
42
|
-
"@spscommerce/ds-colors": "5.8.
|
|
43
|
-
"@spscommerce/ds-shared": "5.8.
|
|
44
|
-
"@spscommerce/positioning": "5.8.
|
|
45
|
-
"@spscommerce/utils": "5.8.
|
|
42
|
+
"@spscommerce/ds-colors": "5.8.1",
|
|
43
|
+
"@spscommerce/ds-shared": "5.8.1",
|
|
44
|
+
"@spscommerce/positioning": "5.8.1",
|
|
45
|
+
"@spscommerce/utils": "5.8.1",
|
|
46
46
|
"@testing-library/react": "^9.3.2",
|
|
47
47
|
"@types/prop-types": "^15.7.1",
|
|
48
48
|
"@types/react": "^16.9.0",
|