@dt-dds/react-select 1.0.0-beta.67 → 1.0.0-beta.69
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/CHANGELOG.md +30 -0
- package/README.md +1 -0
- package/dist/index.d.mts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +60 -48
- package/dist/index.mjs +60 -48
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @dt-ui/react-select
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.69
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- feat: add accessibility to Dropdown
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- refactor: fix sonar issues on Dropdown and Select
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
- Updated dependencies [223664b]
|
|
15
|
+
- @dt-dds/react-dropdown@1.0.0-beta.78
|
|
16
|
+
- @dt-dds/react-box@1.0.0-beta.57
|
|
17
|
+
|
|
18
|
+
## 1.0.0-beta.68
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- feat: make select onChange optional
|
|
23
|
+
- feat: enable custom value label on Select
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- style: add width 100% to select
|
|
28
|
+
- fix: add optional chaining to isDisabled item
|
|
29
|
+
- Updated dependencies [223664b]
|
|
30
|
+
- @dt-dds/react-box@1.0.0-beta.56
|
|
31
|
+
- @dt-dds/react-dropdown@1.0.0-beta.77
|
|
32
|
+
|
|
3
33
|
## 1.0.0-beta.67
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -69,6 +69,7 @@ export const App = () => {
|
|
|
69
69
|
| ------------ | --------------------- | ------- | ------------------------------------------------------------ |
|
|
70
70
|
| `children` | `ReactNode` | — | Visible content of the option (the label shown to the user). |
|
|
71
71
|
| `value` | `string` | — | Option value. |
|
|
72
|
+
| `valueLabel` | `ReactNode` | — | This is a customizable option label on the input. |
|
|
72
73
|
| `index` | `number` | — | Option index in the list (used internally by Downshift). |
|
|
73
74
|
| `isDisabled` | `boolean` | `false` | Disables the option. |
|
|
74
75
|
| `style` | `React.CSSProperties` | — | Inline styles for the option. |
|
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { CustomTheme } from '@dt-dds/themes';
|
|
2
2
|
import { BaseProps, Scale } from '@dt-dds/react-core';
|
|
3
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
3
|
import { ReactNode } from 'react';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
6
|
interface SelectOptionProps extends BaseProps {
|
|
7
7
|
value: string;
|
|
8
8
|
index: number;
|
|
9
9
|
isDisabled?: boolean;
|
|
10
|
+
valueLabel?: ReactNode;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
type SelectOptionValue = {
|
|
13
14
|
value: string;
|
|
14
15
|
isDisabled?: boolean;
|
|
15
|
-
label?:
|
|
16
|
+
label?: ReactNode;
|
|
16
17
|
};
|
|
17
18
|
type SelectVariant = 'outlined' | 'bottom-line';
|
|
18
19
|
type SelectFill = 'default' | 'contrast' | 'light';
|
|
@@ -33,12 +34,12 @@ interface BaseSelectProps extends BaseProps {
|
|
|
33
34
|
interface SingleSelectProps extends BaseSelectProps {
|
|
34
35
|
isMulti?: false;
|
|
35
36
|
value?: string;
|
|
36
|
-
onChange
|
|
37
|
+
onChange?: (value: string) => void;
|
|
37
38
|
}
|
|
38
39
|
interface MultiSelectProps extends BaseSelectProps {
|
|
39
40
|
isMulti: true;
|
|
40
41
|
value?: string[];
|
|
41
|
-
onChange
|
|
42
|
+
onChange?: (value: string[]) => void;
|
|
42
43
|
}
|
|
43
44
|
type SelectProps = SingleSelectProps | MultiSelectProps;
|
|
44
45
|
declare const Select: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { CustomTheme } from '@dt-dds/themes';
|
|
2
2
|
import { BaseProps, Scale } from '@dt-dds/react-core';
|
|
3
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
3
|
import { ReactNode } from 'react';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
6
|
interface SelectOptionProps extends BaseProps {
|
|
7
7
|
value: string;
|
|
8
8
|
index: number;
|
|
9
9
|
isDisabled?: boolean;
|
|
10
|
+
valueLabel?: ReactNode;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
type SelectOptionValue = {
|
|
13
14
|
value: string;
|
|
14
15
|
isDisabled?: boolean;
|
|
15
|
-
label?:
|
|
16
|
+
label?: ReactNode;
|
|
16
17
|
};
|
|
17
18
|
type SelectVariant = 'outlined' | 'bottom-line';
|
|
18
19
|
type SelectFill = 'default' | 'contrast' | 'light';
|
|
@@ -33,12 +34,12 @@ interface BaseSelectProps extends BaseProps {
|
|
|
33
34
|
interface SingleSelectProps extends BaseSelectProps {
|
|
34
35
|
isMulti?: false;
|
|
35
36
|
value?: string;
|
|
36
|
-
onChange
|
|
37
|
+
onChange?: (value: string) => void;
|
|
37
38
|
}
|
|
38
39
|
interface MultiSelectProps extends BaseSelectProps {
|
|
39
40
|
isMulti: true;
|
|
40
41
|
value?: string[];
|
|
41
|
-
onChange
|
|
42
|
+
onChange?: (value: string[]) => void;
|
|
42
43
|
}
|
|
43
44
|
type SelectProps = SingleSelectProps | MultiSelectProps;
|
|
44
45
|
declare const Select: {
|
package/dist/index.js
CHANGED
|
@@ -90,9 +90,7 @@ var SelectProvider = ({ children, value }) => {
|
|
|
90
90
|
const _a = value, { highlightedIndex, selectedItems } = _a, rest = __objRest(_a, ["highlightedIndex", "selectedItems"]);
|
|
91
91
|
const isItemHighlighted = (index) => index === highlightedIndex;
|
|
92
92
|
const isItemSelected = (item) => {
|
|
93
|
-
return !!selectedItems.find(
|
|
94
|
-
(selectedItem) => selectedItem.value === item.value
|
|
95
|
-
);
|
|
93
|
+
return !!selectedItems.find((selectedItem) => selectedItem.value === item);
|
|
96
94
|
};
|
|
97
95
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
98
96
|
SelectContext.Provider,
|
|
@@ -136,7 +134,7 @@ var SelectOption = ({
|
|
|
136
134
|
}) => {
|
|
137
135
|
const { getItemProps, isItemHighlighted, isItemSelected, isMulti } = useSelectContext();
|
|
138
136
|
const item = { value, isDisabled };
|
|
139
|
-
const isSelected = isItemSelected(
|
|
137
|
+
const isSelected = isItemSelected(value);
|
|
140
138
|
const isHighlighted = isItemHighlighted(index);
|
|
141
139
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
142
140
|
import_react_dropdown.Dropdown.Option,
|
|
@@ -150,10 +148,8 @@ var SelectOption = ({
|
|
|
150
148
|
children: isMulti ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
151
149
|
SelectCheckboxStyled,
|
|
152
150
|
{
|
|
153
|
-
"aria-hidden": "true",
|
|
154
151
|
isChecked: isSelected,
|
|
155
152
|
isDisabled,
|
|
156
|
-
role: "presentation",
|
|
157
153
|
tabIndex: -1,
|
|
158
154
|
children
|
|
159
155
|
}
|
|
@@ -185,9 +181,13 @@ var TypographyValueStyled = (0, import_styled2.default)(import_react_typography.
|
|
|
185
181
|
text-overflow: ellipsis;
|
|
186
182
|
white-space: nowrap;
|
|
187
183
|
|
|
188
|
-
${({ theme, scale, isFloatingLabel }) =>
|
|
189
|
-
|
|
190
|
-
|
|
184
|
+
${({ theme, scale, isFloatingLabel }) => {
|
|
185
|
+
const paddingTop = scale === "standard" ? theme.spacing.spacing_50 : theme.spacing.spacing_40;
|
|
186
|
+
const paddingBlock = scale === "standard" ? theme.spacing.spacing_30 : theme.spacing.spacing_20;
|
|
187
|
+
return `
|
|
188
|
+
${isFloatingLabel ? `padding-top: ${paddingTop};` : `padding-block: ${paddingBlock};`}
|
|
189
|
+
`;
|
|
190
|
+
}}
|
|
191
191
|
`;
|
|
192
192
|
var SelectContainerStyled = import_styled2.default.div`
|
|
193
193
|
transition: border 0.2s ease-in-out;
|
|
@@ -306,16 +306,17 @@ var Select = ({
|
|
|
306
306
|
};
|
|
307
307
|
const handleClearSelection = (e) => {
|
|
308
308
|
e.stopPropagation();
|
|
309
|
-
isMulti && onChange([]);
|
|
309
|
+
isMulti && (onChange == null ? void 0 : onChange([]));
|
|
310
310
|
};
|
|
311
311
|
const options = (0, import_react2.useMemo)(() => {
|
|
312
312
|
var _a2;
|
|
313
313
|
const tempOptions = import_react2.Children.map(children, (child) => {
|
|
314
|
+
var _a3, _b, _c;
|
|
314
315
|
if ((0, import_react2.isValidElement)(child) && child.props.value != void 0) {
|
|
315
316
|
return {
|
|
316
317
|
value: child.props.value,
|
|
317
318
|
isDisabled: child.props.isDisabled,
|
|
318
|
-
label: child.props.children
|
|
319
|
+
label: (_c = (_a3 = child.props) == null ? void 0 : _a3.valueLabel) != null ? _c : (_b = child.props) == null ? void 0 : _b.children
|
|
319
320
|
};
|
|
320
321
|
}
|
|
321
322
|
return null;
|
|
@@ -339,6 +340,41 @@ var Select = ({
|
|
|
339
340
|
}
|
|
340
341
|
return selectedItems.length > 1 ? `${selectedItems.length} options selected` : (_a2 = selectedItems[0]) == null ? void 0 : _a2.label;
|
|
341
342
|
};
|
|
343
|
+
const selectStateReducer = (state, actionAndChanges) => {
|
|
344
|
+
const { changes, type } = actionAndChanges;
|
|
345
|
+
switch (type) {
|
|
346
|
+
case useSelect.stateChangeTypes.ToggleButtonBlur:
|
|
347
|
+
return __spreadProps(__spreadValues({}, changes), {
|
|
348
|
+
isOpen: false,
|
|
349
|
+
selectedItem: state.selectedItem,
|
|
350
|
+
highlightedIndex: state.highlightedIndex
|
|
351
|
+
});
|
|
352
|
+
case useSelect.stateChangeTypes.ItemClick:
|
|
353
|
+
case useSelect.stateChangeTypes.ToggleButtonKeyDownEnter:
|
|
354
|
+
case useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
355
|
+
return isMulti ? __spreadProps(__spreadValues({}, changes), {
|
|
356
|
+
isOpen: true,
|
|
357
|
+
highlightedIndex: state.highlightedIndex
|
|
358
|
+
}) : changes;
|
|
359
|
+
default:
|
|
360
|
+
return changes;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
const handleSelectedItemChange = ({
|
|
364
|
+
selectedItem
|
|
365
|
+
}) => {
|
|
366
|
+
if (!selectedItem) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (isMulti) {
|
|
370
|
+
const currentValue = Array.isArray(value) ? value : [];
|
|
371
|
+
const isSelectedItem = selectedOptionsSet.has(selectedItem.value);
|
|
372
|
+
const nextValue = isSelectedItem ? currentValue.filter((v) => v !== selectedItem.value) : [...currentValue, selectedItem.value];
|
|
373
|
+
onChange == null ? void 0 : onChange(nextValue);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
onChange == null ? void 0 : onChange(selectedItem.value);
|
|
377
|
+
};
|
|
342
378
|
const {
|
|
343
379
|
isOpen,
|
|
344
380
|
closeMenu,
|
|
@@ -350,45 +386,20 @@ var Select = ({
|
|
|
350
386
|
} = useSelect({
|
|
351
387
|
items: options,
|
|
352
388
|
isItemDisabled(item) {
|
|
353
|
-
return !!item.isDisabled;
|
|
389
|
+
return !!(item == null ? void 0 : item.isDisabled);
|
|
354
390
|
},
|
|
355
391
|
defaultHighlightedIndex: isMulti || !(selectedItems == null ? void 0 : selectedItems[0]) ? 0 : void 0,
|
|
356
392
|
selectedItem: !isMulti ? (_a = selectedItems == null ? void 0 : selectedItems[0]) != null ? _a : null : null,
|
|
357
|
-
stateReducer
|
|
358
|
-
|
|
359
|
-
switch (type) {
|
|
360
|
-
case useSelect.stateChangeTypes.ToggleButtonBlur:
|
|
361
|
-
return __spreadProps(__spreadValues({}, changes), {
|
|
362
|
-
isOpen: false,
|
|
363
|
-
selectedItem: state.selectedItem,
|
|
364
|
-
highlightedIndex: state.highlightedIndex
|
|
365
|
-
});
|
|
366
|
-
case useSelect.stateChangeTypes.ItemClick:
|
|
367
|
-
case useSelect.stateChangeTypes.ToggleButtonKeyDownEnter:
|
|
368
|
-
case useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
369
|
-
return isMulti ? __spreadProps(__spreadValues({}, changes), {
|
|
370
|
-
isOpen: true,
|
|
371
|
-
highlightedIndex: state.highlightedIndex
|
|
372
|
-
}) : changes;
|
|
373
|
-
default:
|
|
374
|
-
return changes;
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
onSelectedItemChange: ({ selectedItem }) => {
|
|
378
|
-
if (!selectedItem) {
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
if (isMulti) {
|
|
382
|
-
const currentValue = Array.isArray(value) ? value : [];
|
|
383
|
-
const isSelectedItem = selectedOptionsSet.has(selectedItem.value);
|
|
384
|
-
const nextValue = isSelectedItem ? currentValue.filter((v) => v !== selectedItem.value) : [...currentValue, selectedItem.value];
|
|
385
|
-
onChange(nextValue);
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
onChange(selectedItem.value);
|
|
389
|
-
}
|
|
393
|
+
stateReducer: selectStateReducer,
|
|
394
|
+
onSelectedItemChange: handleSelectedItemChange
|
|
390
395
|
});
|
|
391
396
|
const disabled = isDisabled || options.length === 1;
|
|
397
|
+
const helperTextColor = (isDisabled2, hasError2) => {
|
|
398
|
+
if (isDisabled2) {
|
|
399
|
+
return "content.light";
|
|
400
|
+
}
|
|
401
|
+
return hasError2 ? "error.default" : "content.medium";
|
|
402
|
+
};
|
|
392
403
|
const toggleProps = getToggleButtonProps({
|
|
393
404
|
disabled,
|
|
394
405
|
tabIndex: disabled ? -1 : 0,
|
|
@@ -407,9 +418,9 @@ var Select = ({
|
|
|
407
418
|
import_react_box.Box,
|
|
408
419
|
{
|
|
409
420
|
dataTestId: dataTestId != null ? dataTestId : "select",
|
|
410
|
-
style: { alignItems: "start", gap: 4 },
|
|
421
|
+
style: __spreadValues({ alignItems: "start", gap: 4, width: "100%" }, style),
|
|
411
422
|
children: [
|
|
412
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(SelectStyled, {
|
|
423
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(SelectStyled, { children: [
|
|
413
424
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
414
425
|
import_react_label_field.LabelField,
|
|
415
426
|
__spreadProps(__spreadValues(__spreadProps(__spreadValues({}, getLabelProps()), {
|
|
@@ -480,7 +491,7 @@ var Select = ({
|
|
|
480
491
|
helperText ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
481
492
|
TypographyHelperTextStyled,
|
|
482
493
|
{
|
|
483
|
-
color: isDisabled
|
|
494
|
+
color: helperTextColor(!!isDisabled, hasError),
|
|
484
495
|
dataTestId: "select-helper-text",
|
|
485
496
|
element: "span",
|
|
486
497
|
fontStyles: "bodySmRegular",
|
|
@@ -494,6 +505,7 @@ var Select = ({
|
|
|
494
505
|
anchorRef,
|
|
495
506
|
"aria-multiselectable": isMulti,
|
|
496
507
|
as: "ul",
|
|
508
|
+
isFocusable: false,
|
|
497
509
|
isOpen,
|
|
498
510
|
onClose: closeMenu,
|
|
499
511
|
children
|
package/dist/index.mjs
CHANGED
|
@@ -62,9 +62,7 @@ var SelectProvider = ({ children, value }) => {
|
|
|
62
62
|
const _a = value, { highlightedIndex, selectedItems } = _a, rest = __objRest(_a, ["highlightedIndex", "selectedItems"]);
|
|
63
63
|
const isItemHighlighted = (index) => index === highlightedIndex;
|
|
64
64
|
const isItemSelected = (item) => {
|
|
65
|
-
return !!selectedItems.find(
|
|
66
|
-
(selectedItem) => selectedItem.value === item.value
|
|
67
|
-
);
|
|
65
|
+
return !!selectedItems.find((selectedItem) => selectedItem.value === item);
|
|
68
66
|
};
|
|
69
67
|
return /* @__PURE__ */ jsx(
|
|
70
68
|
SelectContext.Provider,
|
|
@@ -108,7 +106,7 @@ var SelectOption = ({
|
|
|
108
106
|
}) => {
|
|
109
107
|
const { getItemProps, isItemHighlighted, isItemSelected, isMulti } = useSelectContext();
|
|
110
108
|
const item = { value, isDisabled };
|
|
111
|
-
const isSelected = isItemSelected(
|
|
109
|
+
const isSelected = isItemSelected(value);
|
|
112
110
|
const isHighlighted = isItemHighlighted(index);
|
|
113
111
|
return /* @__PURE__ */ jsx2(
|
|
114
112
|
Dropdown.Option,
|
|
@@ -122,10 +120,8 @@ var SelectOption = ({
|
|
|
122
120
|
children: isMulti ? /* @__PURE__ */ jsx2(
|
|
123
121
|
SelectCheckboxStyled,
|
|
124
122
|
{
|
|
125
|
-
"aria-hidden": "true",
|
|
126
123
|
isChecked: isSelected,
|
|
127
124
|
isDisabled,
|
|
128
|
-
role: "presentation",
|
|
129
125
|
tabIndex: -1,
|
|
130
126
|
children
|
|
131
127
|
}
|
|
@@ -157,9 +153,13 @@ var TypographyValueStyled = styled2(Typography, {
|
|
|
157
153
|
text-overflow: ellipsis;
|
|
158
154
|
white-space: nowrap;
|
|
159
155
|
|
|
160
|
-
${({ theme, scale, isFloatingLabel }) =>
|
|
161
|
-
|
|
162
|
-
|
|
156
|
+
${({ theme, scale, isFloatingLabel }) => {
|
|
157
|
+
const paddingTop = scale === "standard" ? theme.spacing.spacing_50 : theme.spacing.spacing_40;
|
|
158
|
+
const paddingBlock = scale === "standard" ? theme.spacing.spacing_30 : theme.spacing.spacing_20;
|
|
159
|
+
return `
|
|
160
|
+
${isFloatingLabel ? `padding-top: ${paddingTop};` : `padding-block: ${paddingBlock};`}
|
|
161
|
+
`;
|
|
162
|
+
}}
|
|
163
163
|
`;
|
|
164
164
|
var SelectContainerStyled = styled2.div`
|
|
165
165
|
transition: border 0.2s ease-in-out;
|
|
@@ -278,16 +278,17 @@ var Select = ({
|
|
|
278
278
|
};
|
|
279
279
|
const handleClearSelection = (e) => {
|
|
280
280
|
e.stopPropagation();
|
|
281
|
-
isMulti && onChange([]);
|
|
281
|
+
isMulti && (onChange == null ? void 0 : onChange([]));
|
|
282
282
|
};
|
|
283
283
|
const options = useMemo(() => {
|
|
284
284
|
var _a2;
|
|
285
285
|
const tempOptions = Children.map(children, (child) => {
|
|
286
|
+
var _a3, _b, _c;
|
|
286
287
|
if (isValidElement(child) && child.props.value != void 0) {
|
|
287
288
|
return {
|
|
288
289
|
value: child.props.value,
|
|
289
290
|
isDisabled: child.props.isDisabled,
|
|
290
|
-
label: child.props.children
|
|
291
|
+
label: (_c = (_a3 = child.props) == null ? void 0 : _a3.valueLabel) != null ? _c : (_b = child.props) == null ? void 0 : _b.children
|
|
291
292
|
};
|
|
292
293
|
}
|
|
293
294
|
return null;
|
|
@@ -311,6 +312,41 @@ var Select = ({
|
|
|
311
312
|
}
|
|
312
313
|
return selectedItems.length > 1 ? `${selectedItems.length} options selected` : (_a2 = selectedItems[0]) == null ? void 0 : _a2.label;
|
|
313
314
|
};
|
|
315
|
+
const selectStateReducer = (state, actionAndChanges) => {
|
|
316
|
+
const { changes, type } = actionAndChanges;
|
|
317
|
+
switch (type) {
|
|
318
|
+
case useSelect.stateChangeTypes.ToggleButtonBlur:
|
|
319
|
+
return __spreadProps(__spreadValues({}, changes), {
|
|
320
|
+
isOpen: false,
|
|
321
|
+
selectedItem: state.selectedItem,
|
|
322
|
+
highlightedIndex: state.highlightedIndex
|
|
323
|
+
});
|
|
324
|
+
case useSelect.stateChangeTypes.ItemClick:
|
|
325
|
+
case useSelect.stateChangeTypes.ToggleButtonKeyDownEnter:
|
|
326
|
+
case useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
327
|
+
return isMulti ? __spreadProps(__spreadValues({}, changes), {
|
|
328
|
+
isOpen: true,
|
|
329
|
+
highlightedIndex: state.highlightedIndex
|
|
330
|
+
}) : changes;
|
|
331
|
+
default:
|
|
332
|
+
return changes;
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
const handleSelectedItemChange = ({
|
|
336
|
+
selectedItem
|
|
337
|
+
}) => {
|
|
338
|
+
if (!selectedItem) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (isMulti) {
|
|
342
|
+
const currentValue = Array.isArray(value) ? value : [];
|
|
343
|
+
const isSelectedItem = selectedOptionsSet.has(selectedItem.value);
|
|
344
|
+
const nextValue = isSelectedItem ? currentValue.filter((v) => v !== selectedItem.value) : [...currentValue, selectedItem.value];
|
|
345
|
+
onChange == null ? void 0 : onChange(nextValue);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
onChange == null ? void 0 : onChange(selectedItem.value);
|
|
349
|
+
};
|
|
314
350
|
const {
|
|
315
351
|
isOpen,
|
|
316
352
|
closeMenu,
|
|
@@ -322,45 +358,20 @@ var Select = ({
|
|
|
322
358
|
} = useSelect({
|
|
323
359
|
items: options,
|
|
324
360
|
isItemDisabled(item) {
|
|
325
|
-
return !!item.isDisabled;
|
|
361
|
+
return !!(item == null ? void 0 : item.isDisabled);
|
|
326
362
|
},
|
|
327
363
|
defaultHighlightedIndex: isMulti || !(selectedItems == null ? void 0 : selectedItems[0]) ? 0 : void 0,
|
|
328
364
|
selectedItem: !isMulti ? (_a = selectedItems == null ? void 0 : selectedItems[0]) != null ? _a : null : null,
|
|
329
|
-
stateReducer
|
|
330
|
-
|
|
331
|
-
switch (type) {
|
|
332
|
-
case useSelect.stateChangeTypes.ToggleButtonBlur:
|
|
333
|
-
return __spreadProps(__spreadValues({}, changes), {
|
|
334
|
-
isOpen: false,
|
|
335
|
-
selectedItem: state.selectedItem,
|
|
336
|
-
highlightedIndex: state.highlightedIndex
|
|
337
|
-
});
|
|
338
|
-
case useSelect.stateChangeTypes.ItemClick:
|
|
339
|
-
case useSelect.stateChangeTypes.ToggleButtonKeyDownEnter:
|
|
340
|
-
case useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
341
|
-
return isMulti ? __spreadProps(__spreadValues({}, changes), {
|
|
342
|
-
isOpen: true,
|
|
343
|
-
highlightedIndex: state.highlightedIndex
|
|
344
|
-
}) : changes;
|
|
345
|
-
default:
|
|
346
|
-
return changes;
|
|
347
|
-
}
|
|
348
|
-
},
|
|
349
|
-
onSelectedItemChange: ({ selectedItem }) => {
|
|
350
|
-
if (!selectedItem) {
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
if (isMulti) {
|
|
354
|
-
const currentValue = Array.isArray(value) ? value : [];
|
|
355
|
-
const isSelectedItem = selectedOptionsSet.has(selectedItem.value);
|
|
356
|
-
const nextValue = isSelectedItem ? currentValue.filter((v) => v !== selectedItem.value) : [...currentValue, selectedItem.value];
|
|
357
|
-
onChange(nextValue);
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
onChange(selectedItem.value);
|
|
361
|
-
}
|
|
365
|
+
stateReducer: selectStateReducer,
|
|
366
|
+
onSelectedItemChange: handleSelectedItemChange
|
|
362
367
|
});
|
|
363
368
|
const disabled = isDisabled || options.length === 1;
|
|
369
|
+
const helperTextColor = (isDisabled2, hasError2) => {
|
|
370
|
+
if (isDisabled2) {
|
|
371
|
+
return "content.light";
|
|
372
|
+
}
|
|
373
|
+
return hasError2 ? "error.default" : "content.medium";
|
|
374
|
+
};
|
|
364
375
|
const toggleProps = getToggleButtonProps({
|
|
365
376
|
disabled,
|
|
366
377
|
tabIndex: disabled ? -1 : 0,
|
|
@@ -379,9 +390,9 @@ var Select = ({
|
|
|
379
390
|
Box,
|
|
380
391
|
{
|
|
381
392
|
dataTestId: dataTestId != null ? dataTestId : "select",
|
|
382
|
-
style: { alignItems: "start", gap: 4 },
|
|
393
|
+
style: __spreadValues({ alignItems: "start", gap: 4, width: "100%" }, style),
|
|
383
394
|
children: [
|
|
384
|
-
/* @__PURE__ */ jsxs(SelectStyled, {
|
|
395
|
+
/* @__PURE__ */ jsxs(SelectStyled, { children: [
|
|
385
396
|
/* @__PURE__ */ jsx3(
|
|
386
397
|
LabelField,
|
|
387
398
|
__spreadProps(__spreadValues(__spreadProps(__spreadValues({}, getLabelProps()), {
|
|
@@ -452,7 +463,7 @@ var Select = ({
|
|
|
452
463
|
helperText ? /* @__PURE__ */ jsx3(
|
|
453
464
|
TypographyHelperTextStyled,
|
|
454
465
|
{
|
|
455
|
-
color: isDisabled
|
|
466
|
+
color: helperTextColor(!!isDisabled, hasError),
|
|
456
467
|
dataTestId: "select-helper-text",
|
|
457
468
|
element: "span",
|
|
458
469
|
fontStyles: "bodySmRegular",
|
|
@@ -466,6 +477,7 @@ var Select = ({
|
|
|
466
477
|
anchorRef,
|
|
467
478
|
"aria-multiselectable": isMulti,
|
|
468
479
|
as: "ul",
|
|
480
|
+
isFocusable: false,
|
|
469
481
|
isOpen,
|
|
470
482
|
onClose: closeMenu,
|
|
471
483
|
children
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dt-dds/react-select",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.69",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js"
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"test:update:snapshot": "jest -u"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dt-dds/react-box": "1.0.0-beta.
|
|
23
|
+
"@dt-dds/react-box": "1.0.0-beta.57",
|
|
24
24
|
"@dt-dds/react-checkbox": "1.0.0-beta.52",
|
|
25
25
|
"@dt-dds/react-core": "1.0.0-beta.51",
|
|
26
|
-
"@dt-dds/react-dropdown": "1.0.0-beta.
|
|
26
|
+
"@dt-dds/react-dropdown": "1.0.0-beta.78",
|
|
27
27
|
"@dt-dds/react-icon": "1.0.0-beta.54",
|
|
28
28
|
"@dt-dds/react-icon-button": "1.0.0-beta.20",
|
|
29
29
|
"@dt-dds/react-label-field": "1.0.0-beta.52",
|