@balena/ui-shared-components 6.1.3 → 6.1.4-build-selectwidget-filterselected-for-multiple-469d47abec00bb1e7a028e71c581353fa628518e-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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
-
import { jsx as _jsx
|
|
3
|
-
import {
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Autocomplete, TextField } from '@mui/material';
|
|
4
4
|
import isEqual from 'lodash/isEqual';
|
|
5
5
|
export const SelectWidget = ({ id, label, value, disabled, name, placeholder, onChange, multiple, options, required, uiSchema, }) => {
|
|
6
6
|
const _a = uiSchema !== null && uiSchema !== void 0 ? uiSchema : {}, { inputProps } = _a, otherUiSchema = __rest(_a, ["inputProps"]);
|
|
@@ -28,32 +28,37 @@ export const SelectWidget = ({ id, label, value, disabled, name, placeholder, on
|
|
|
28
28
|
// label: string;
|
|
29
29
|
// schema?: RJSFSchema | undefined;
|
|
30
30
|
// }[]
|
|
31
|
-
return (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return onChange(val.length > 0 ? val : options.emptyValue);
|
|
31
|
+
return (_jsx(Autocomplete, Object.assign({ fullWidth: true, id: id, value: Array.isArray(value)
|
|
32
|
+
? selectOptions.filter((option) => value.some((v) => isEqual(option.value, v)))
|
|
33
|
+
: value !== undefined
|
|
34
|
+
? selectOptions.find((option) => isEqual(option.value, value))
|
|
35
|
+
: undefined, name,
|
|
36
|
+
placeholder,
|
|
37
|
+
multiple, filterSelectedOptions: multiple, disabled: disabled, options: selectOptions, isOptionEqualToValue: (option, value) => isEqual(option, value), getOptionLabel: (option) => Array.isArray(option)
|
|
38
|
+
? option.map((o) => o.label).join(', ')
|
|
39
|
+
: option.label, getOptionDisabled: (option) => Array.isArray(option) ? option.some((o) => o.disabled) : option.disabled, renderInput: (params) => (_jsx(TextField, Object.assign({}, params, { inputProps: Object.assign(Object.assign({}, params.inputProps), (inputProps !== null && inputProps !== void 0 ? inputProps : {})) }, (multiple && {
|
|
40
|
+
onKeyDown: (e) => {
|
|
41
|
+
// Prevent deleting the last chip with backspace or delete https://github.com/mui/material-ui/issues/21129#issuecomment-636919142
|
|
42
|
+
if (e.key === 'Backspace' || e.key === 'Delete') {
|
|
43
|
+
e.stopPropagation();
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
}), { label: label, required: required }))), onChange: (_event, selected) => {
|
|
47
|
+
if (Array.isArray(selected)) {
|
|
48
|
+
const val = selected
|
|
49
|
+
.map((item) => {
|
|
50
|
+
if (item && typeof item === 'object' && 'value' in item) {
|
|
51
|
+
return item.value;
|
|
53
52
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
// this case cover a wrong setup, we just return undefined
|
|
54
|
+
return undefined;
|
|
55
|
+
})
|
|
56
|
+
.filter((v) => v !== undefined);
|
|
57
|
+
return onChange(val.length > 0 ? val : options.emptyValue);
|
|
58
|
+
}
|
|
59
|
+
if (selected && typeof selected === 'object' && 'value' in selected) {
|
|
60
|
+
return onChange(selected.value === '' ? options.emptyValue : selected.value);
|
|
61
|
+
}
|
|
62
|
+
return onChange(options.emptyValue);
|
|
63
|
+
}, disableClearable: true }, otherUiSchema)));
|
|
59
64
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@balena/ui-shared-components",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.4-build-selectwidget-filterselected-for-multiple-469d47abec00bb1e7a028e71c581353fa628518e-1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -112,6 +112,6 @@
|
|
|
112
112
|
},
|
|
113
113
|
"homepage": "https://github.com/balena-io/ui-shared-components#readme",
|
|
114
114
|
"versionist": {
|
|
115
|
-
"publishedAt": "2024-06-
|
|
115
|
+
"publishedAt": "2024-06-24T16:12:09.860Z"
|
|
116
116
|
}
|
|
117
117
|
}
|