@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, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { FormControl, Autocomplete, TextField, InputLabel, } from '@mui/material';
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 (_jsxs(FormControl, { children: [_jsx(InputLabel, { htmlFor: id, required: required, children: label }), _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, 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)
40
- ? option.some((o) => o.disabled)
41
- : option.disabled, renderInput: (params) => (_jsx(TextField, Object.assign({}, params, { inputProps: Object.assign(Object.assign({}, params.inputProps), (inputProps !== null && inputProps !== void 0 ? inputProps : {})) }))), onChange: (_event, selected) => {
42
- if (Array.isArray(selected)) {
43
- const val = selected
44
- .map((item) => {
45
- if (item && typeof item === 'object' && 'value' in item) {
46
- return item.value;
47
- }
48
- // this case cover a wrong setup, we just return undefined
49
- return undefined;
50
- })
51
- .filter((v) => v !== undefined);
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
- if (selected && typeof selected === 'object' && 'value' in selected) {
55
- return onChange(selected.value === '' ? options.emptyValue : selected.value);
56
- }
57
- return onChange(options.emptyValue);
58
- }, disableClearable: true }, otherUiSchema))] }));
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",
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-20T21:22:31.290Z"
115
+ "publishedAt": "2024-06-24T16:12:09.860Z"
116
116
  }
117
117
  }