@spscommerce/ds-react 5.5.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.es.js CHANGED
@@ -610,29 +610,39 @@ const SpsFormComponentWrapper = React.forwardRef((props2, ref2) => {
610
610
  focusInputOnClick,
611
611
  formControl: formControl2,
612
612
  formMeta,
613
- inputRef: inputRefProp
613
+ inputRef: inputRefProp,
614
+ onClick
614
615
  } = _a, rest = __objRest(_a, [
615
616
  "className",
616
617
  "children",
617
618
  "focusInputOnClick",
618
619
  "formControl",
619
620
  "formMeta",
620
- "inputRef"
621
+ "inputRef",
622
+ "onClick"
621
623
  ]);
622
624
  const fallbackRef = React.useRef();
623
625
  const rootRef = ref2 || fallbackRef;
624
626
  const inputRef = inputRefProp || rootRef;
625
- function doFocusInput() {
627
+ function doFocusInputOnClick() {
626
628
  if (inputRef && inputRef !== ref2 && inputRef.current) {
627
629
  inputRef.current.focus();
628
630
  }
629
631
  }
630
632
  const classes = clsx("sps-form-group", (formControl2 && formControl2.isRequired() || formMeta && formMeta.isRequired()) && "sps-form-group--required", (formControl2 && !formControl2.isValid() || formMeta && formMeta.isVisibilyInvalid()) && "sps-form-group--error", className);
633
+ function handleOnClick(event) {
634
+ if (focusInputOnClick) {
635
+ doFocusInputOnClick();
636
+ }
637
+ if (onClick) {
638
+ onClick(event);
639
+ }
640
+ }
631
641
  return /* @__PURE__ */ React.createElement("div", __spreadProps(__spreadValues({}, rest), {
632
642
  className: classes,
633
643
  ref: ref2,
634
644
  tabIndex: -1,
635
- onClick: focusInputOnClick ? doFocusInput : null
645
+ onClick: handleOnClick
636
646
  }), children);
637
647
  });
638
648
  Object.assign(SpsFormComponentWrapper, {
@@ -1280,7 +1290,7 @@ function compareOptions(optionA, optionB, comparisonKey) {
1280
1290
  function isOptionDisabled(disabledOptions, comparisonKey, option) {
1281
1291
  return comparisonKey ? !!(disabledOptions == null ? void 0 : disabledOptions.find((opt) => {
1282
1292
  var _a;
1283
- 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]);
1284
1294
  })) : false;
1285
1295
  }
1286
1296
  const SpsOptionList = React.forwardRef((props2, ref2) => {
@@ -1405,7 +1415,10 @@ const SpsOptionList = React.forwardRef((props2, ref2) => {
1405
1415
  }
1406
1416
  }
1407
1417
  }, [isOpen, onSelfToggle]);
1408
- const selectOption = React.useCallback((option) => {
1418
+ const selectOption = React.useCallback((option, isDisabled) => {
1419
+ if (isDisabled) {
1420
+ return;
1421
+ }
1409
1422
  if (option && !option.disabled) {
1410
1423
  if (typeof option.value === "function") {
1411
1424
  option.value();
@@ -1417,10 +1430,12 @@ const SpsOptionList = React.forwardRef((props2, ref2) => {
1417
1430
  }
1418
1431
  }
1419
1432
  }, [onOptionSelected, closeSelf]);
1420
- const handleOptionClick = React.useCallback((event, option) => {
1433
+ const handleOptionClick = React.useCallback((event, option, isDisabled) => {
1421
1434
  event.stopPropagation();
1422
- selectOption(option);
1435
+ selectOption(option, isDisabled);
1423
1436
  }, [selectOption]);
1437
+ const disabledOptionsRef = React.useRef(disabledOptions || []);
1438
+ disabledOptionsRef.current = disabledOptions || [];
1424
1439
  const handleArrowKeyDown = React.useCallback((event) => {
1425
1440
  switch (event.key) {
1426
1441
  case "Tab":
@@ -1431,10 +1446,11 @@ const SpsOptionList = React.forwardRef((props2, ref2) => {
1431
1446
  if (highlightedOptionIndex > -1) {
1432
1447
  const highlightedOption = optionList[highlightedOptionIndex] || specialActionOption;
1433
1448
  event.preventDefault();
1434
- if (highlightedOption && typeof onOptionSelected === "function" && typeof highlightedOption.value === "function") {
1449
+ const isDisabled = !!highlightedOption && isOptionDisabled(disabledOptionsRef.current, comparisonKey, highlightedOption);
1450
+ if (!isDisabled && highlightedOption && typeof onOptionSelected === "function" && typeof highlightedOption.value === "function") {
1435
1451
  highlightedOption.value();
1436
1452
  } else if (highlightedOption) {
1437
- selectOption(highlightedOption);
1453
+ selectOption(highlightedOption, isDisabled);
1438
1454
  }
1439
1455
  }
1440
1456
  break;
@@ -1587,14 +1603,16 @@ const SpsOptionList = React.forwardRef((props2, ref2) => {
1587
1603
  className: "sps-option-list__loading"
1588
1604
  }, /* @__PURE__ */ React.createElement(SpsSpinner, null)), !loading && !searchState.pending && optionList.map((option, i2) => {
1589
1605
  const identifier = `${id2}-option-${i2}`;
1606
+ const comparisonResult = compareOptions(option.value, selectedOption, comparisonKey);
1607
+ const isOptionDisabledResult = isOptionDisabled(disabledOptionsRef.current, comparisonKey, option);
1590
1608
  return /* @__PURE__ */ React.createElement("a", {
1591
1609
  key: identifier,
1592
1610
  id: identifier,
1593
1611
  role: optionRole,
1594
- "aria-selected": compareOptions(option.value, selectedOption, comparisonKey),
1612
+ "aria-selected": comparisonResult,
1595
1613
  href: option.href,
1596
- 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", (compareOptions(option.value, selectedOption, comparisonKey) || isOptionDisabled(disabledOptions, comparisonKey, option)) && "sps-option-list__option--selected", highlightedOptionIndex === i2 && "sps-option-list__option--highlighted"),
1597
- 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),
1598
1616
  onMouseOver: () => setHighlightedOptionIndex(i2),
1599
1617
  tabIndex: -1,
1600
1618
  ref: highlightedOptionIndex === i2 ? highlightedOptionRef : null,
@@ -5473,6 +5491,7 @@ function SpsCheckbox(_m) {
5473
5491
  id: controlId,
5474
5492
  checked,
5475
5493
  disabled,
5494
+ "data-testId": `${testId}__checkbox-input`,
5476
5495
  onChange: handleChange
5477
5496
  }, rest)), /* @__PURE__ */ React.createElement("label", {
5478
5497
  className: "sps-checkable__label",
@@ -25178,7 +25197,8 @@ function SpsLabel(_o) {
25178
25197
  helpIcon = SpsIcon.QUESTION_CIRCLE,
25179
25198
  helpIconColor = "blue200",
25180
25199
  errors,
25181
- unsafelyReplaceClassName
25200
+ unsafelyReplaceClassName,
25201
+ "data-testid": testId
25182
25202
  } = _p, rest = __objRest(_p, [
25183
25203
  "children",
25184
25204
  "className",
@@ -25189,7 +25209,8 @@ function SpsLabel(_o) {
25189
25209
  "helpIcon",
25190
25210
  "helpIconColor",
25191
25211
  "errors",
25192
- "unsafelyReplaceClassName"
25212
+ "unsafelyReplaceClassName",
25213
+ "data-testid"
25193
25214
  ]);
25194
25215
  const { t: t2 } = React.useContext(I18nContext);
25195
25216
  const errorIcon = React.useRef();
@@ -25273,9 +25294,11 @@ function SpsLabel(_o) {
25273
25294
  formControl: formControl2
25274
25295
  }, /* @__PURE__ */ React.createElement("label", __spreadValues({
25275
25296
  htmlFor: forProp && "id" in forProp ? forProp.id : void 0,
25276
- className: classes
25297
+ className: classes,
25298
+ "data-testid": testId
25277
25299
  }, rest), /* @__PURE__ */ React.createElement("i", {
25278
25300
  ref: suggestedIcon,
25301
+ "data-testid": `${testId}__suggested-icon`,
25279
25302
  className: clsx("sps-icon", "sps-icon-exclamation-triangle", "orange200", "sps-form-group__label-suggested-icon", !stronglySuggested && "d-none"),
25280
25303
  onClick: handleSuggestedIconClick,
25281
25304
  onMouseEnter: () => {
@@ -25285,6 +25308,7 @@ function SpsLabel(_o) {
25285
25308
  onMouseLeave: delayedHideTooltips
25286
25309
  }), /* @__PURE__ */ React.createElement("i", {
25287
25310
  ref: errorIcon,
25311
+ "data-testid": `${testId}__error-icon`,
25288
25312
  className: clsx("sps-icon", "sps-icon-exclamation-circle", "sps-form-group__label--error-icon"),
25289
25313
  onClick: handleLabelClick,
25290
25314
  onMouseEnter: doShowPriorityTooltip,
@@ -25293,6 +25317,7 @@ function SpsLabel(_o) {
25293
25317
  className: "sps-form-group__label-content"
25294
25318
  }, children), /* @__PURE__ */ React.createElement("i", {
25295
25319
  ref: helpIconRef,
25320
+ "data-testid": `${testId}__help-icon`,
25296
25321
  className: clsx("sps-icon", `sps-icon-${helpIcon}`, helpIconColor, !help && "d-none"),
25297
25322
  onClick: handleHelpClick,
25298
25323
  onMouseEnter: () => {
@@ -25321,7 +25346,8 @@ function SpsLabel(_o) {
25321
25346
  showOn: TooltipShowTrigger.MANUAL,
25322
25347
  isShown: showSuggestedTip
25323
25348
  }, t2("design-system:label.stronglySuggested")), description && /* @__PURE__ */ React.createElement("div", {
25324
- className: "sps-form-control__description"
25349
+ className: "sps-form-control__description",
25350
+ "data-testid": `${testId}__description`
25325
25351
  }, description));
25326
25352
  }
25327
25353
  Object.assign(SpsLabel, {
@@ -28945,7 +28971,8 @@ function SpsMultiSelect(_w) {
28945
28971
  value,
28946
28972
  zeroState = "There are no matching options.",
28947
28973
  loading,
28948
- icon
28974
+ icon,
28975
+ "data-testid": testId
28949
28976
  } = _x, rest = __objRest(_x, [
28950
28977
  "action",
28951
28978
  "captionKey",
@@ -28967,7 +28994,8 @@ function SpsMultiSelect(_w) {
28967
28994
  "value",
28968
28995
  "zeroState",
28969
28996
  "loading",
28970
- "icon"
28997
+ "icon",
28998
+ "data-testid"
28971
28999
  ]);
28972
29000
  const meta = formMeta || formControl2;
28973
29001
  const { wrapperId, controlId } = useFormControlId(id2, meta);
@@ -29126,6 +29154,7 @@ function SpsMultiSelect(_w) {
29126
29154
  }, textKey ? opt[textKey] : opt)), /* @__PURE__ */ React.createElement("input", __spreadValues({
29127
29155
  type: "text",
29128
29156
  ref: textInput,
29157
+ "data-testid": `${testId}__option-list-input`,
29129
29158
  value: state.searchText,
29130
29159
  className: "sps-text-input__input",
29131
29160
  placeholder: value.length === 0 ? placeholder : void 0,
@@ -29144,6 +29173,7 @@ function SpsMultiSelect(_w) {
29144
29173
  }) : null)), /* @__PURE__ */ React.createElement(SpsOptionList, {
29145
29174
  id: `${wrapperId}_options`,
29146
29175
  ref: optionListRef,
29176
+ "data-testid": `${testId}__option-list`,
29147
29177
  attachTo: inputVisual,
29148
29178
  captionKey,
29149
29179
  disabledOptions: disableSelected ? value : null,
@@ -29515,6 +29545,7 @@ const SpsSelect = React.forwardRef((props2, ref2) => {
29515
29545
  notClearable,
29516
29546
  options,
29517
29547
  onChange,
29548
+ onClick,
29518
29549
  placeholder,
29519
29550
  searchDebounce,
29520
29551
  searchPlaceholder = "Search\u2026",
@@ -29540,6 +29571,7 @@ const SpsSelect = React.forwardRef((props2, ref2) => {
29540
29571
  "notClearable",
29541
29572
  "options",
29542
29573
  "onChange",
29574
+ "onClick",
29543
29575
  "placeholder",
29544
29576
  "searchDebounce",
29545
29577
  "searchPlaceholder",
@@ -29674,7 +29706,8 @@ const SpsSelect = React.forwardRef((props2, ref2) => {
29674
29706
  ref: rootElement,
29675
29707
  role: "listbox",
29676
29708
  "aria-owns": state.optionIds,
29677
- "data-testid": testId
29709
+ "data-testid": testId,
29710
+ onClick
29678
29711
  }, rest), /* @__PURE__ */ React.createElement("div", {
29679
29712
  className: clsx("sps-select__dropctrl", disabled && "disabled"),
29680
29713
  id: controlId,
@@ -31303,6 +31336,7 @@ function SpsRadioButton(_y) {
31303
31336
  type: "radio",
31304
31337
  ref: inputElement,
31305
31338
  className: "sps-checkable__input",
31339
+ "data-testid": `${testId}__radio-input`,
31306
31340
  id: controlId,
31307
31341
  name,
31308
31342
  checked,
@@ -34010,6 +34044,7 @@ function SpsTextarea(_I) {
34010
34044
  value: value || "",
34011
34045
  disabled
34012
34046
  }, rest)), value && !disabled && /* @__PURE__ */ React.createElement("i", {
34047
+ "data-testid": `${testId}__input_clear`,
34013
34048
  className: "sps-icon sps-icon-x-circle sps-form-control__clear-btn",
34014
34049
  onClick: clear
34015
34050
  })));
@@ -34684,7 +34719,8 @@ function SpsToggle(props2) {
34684
34719
  checked: active || false,
34685
34720
  disabled,
34686
34721
  onChange: handleChange,
34687
- "aria-describedby": `${statusLabelID},${descriptionID}`
34722
+ "aria-describedby": `${statusLabelID},${descriptionID}`,
34723
+ "data-testid": `${testId}__input`
34688
34724
  }, rest)), /* @__PURE__ */ React.createElement("span", {
34689
34725
  className: "sps-toggle__slider"
34690
34726
  }), label && /* @__PURE__ */ React.createElement("label", {
@@ -16,5 +16,5 @@ declare const propTypes: {
16
16
  unsafelyReplaceClassName: PropTypes.Requireable<string>;
17
17
  };
18
18
  export declare type SpsLabelProps = PropTypes.InferTS<typeof propTypes, HTMLLabelElement>;
19
- export declare function SpsLabel({ children, className, description, for: forProp, stronglySuggested, help, helpIcon, helpIconColor, errors, unsafelyReplaceClassName, ...rest }: SpsLabelProps): JSX.Element;
19
+ export declare function SpsLabel({ children, className, description, for: forProp, stronglySuggested, help, helpIcon, helpIconColor, errors, unsafelyReplaceClassName, "data-testid": testId, ...rest }: SpsLabelProps): JSX.Element;
20
20
  export {};
@@ -30,5 +30,5 @@ declare const propTypes: {
30
30
  unsafelyReplaceClassName: PropTypes.Requireable<string>;
31
31
  };
32
32
  export declare type SpsMultiSelectProps = PropTypes.InferTS<typeof propTypes, HTMLInputElement>;
33
- export declare function SpsMultiSelect({ action, captionKey, className, debounce, disabled, disableSelected, comparisonKey, formControl, formMeta, hideSelected, id, onChange, options, placeholder, tallOptionList, textKey, unsafelyReplaceClassName, value, zeroState, loading, icon, ...rest }: SpsMultiSelectProps): JSX.Element;
33
+ export declare function SpsMultiSelect({ action, captionKey, className, debounce, disabled, disableSelected, comparisonKey, formControl, formMeta, hideSelected, id, onChange, options, placeholder, tallOptionList, textKey, unsafelyReplaceClassName, value, zeroState, loading, icon, "data-testid": testId, ...rest }: SpsMultiSelectProps): JSX.Element;
34
34
  export {};
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.5.0",
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.5.0",
32
- "@spscommerce/ds-shared": "5.5.0",
33
- "@spscommerce/positioning": "5.5.0",
34
- "@spscommerce/utils": "5.5.0",
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,11 +39,10 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@react-stately/collections": "^3.3.3",
42
- "@spscommerce/ds-colors": "5.5.0",
43
- "@spscommerce/ds-shared": "5.5.0",
44
- "@spscommerce/positioning": "5.5.0",
45
- "@spscommerce/utils": "5.5.0",
46
- "@testing-library/jest-dom": "^4.2.4",
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",
47
46
  "@testing-library/react": "^9.3.2",
48
47
  "@types/prop-types": "^15.7.1",
49
48
  "@types/react": "^16.9.0",
@@ -1 +0,0 @@
1
- export {};