@etsoo/react 1.4.86 → 1.4.87

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.
@@ -5,6 +5,10 @@ import { AutocompleteExtendedProps } from './AutocompleteExtendedProps';
5
5
  * ComboBox props
6
6
  */
7
7
  export interface ComboBoxProps<T extends {}> extends AutocompleteExtendedProps<T> {
8
+ /**
9
+ * Auto add blank item
10
+ */
11
+ autoAddBlankItem?: boolean;
8
12
  /**
9
13
  * Data readonly
10
14
  */
@@ -12,7 +12,7 @@ import { SearchField } from './SearchField';
12
12
  */
13
13
  export function ComboBox(props) {
14
14
  // Destruct
15
- const { search = false, idField = 'id', idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, defaultValue, label, labelField = 'label', loadData, onLoadData, name, inputAutoComplete = 'off', options, dataReadonly = true, readOnly, onChange, openOnFocus = true, value, getOptionLabel = (option) => String(Reflect.get(option, labelField)), sx = { minWidth: '150px' }, ...rest } = props;
15
+ const { search = false, autoAddBlankItem = search, idField = 'id', idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, defaultValue, label, labelField = 'label', loadData, onLoadData, name, inputAutoComplete = 'off', options, dataReadonly = true, readOnly, onChange, openOnFocus = true, value, getOptionLabel = (option) => String(Reflect.get(option, labelField)), sx = { minWidth: '150px' }, ...rest } = props;
16
16
  // Value input ref
17
17
  const inputRef = React.createRef();
18
18
  // Options state
@@ -82,7 +82,7 @@ export function ComboBox(props) {
82
82
  return;
83
83
  if (onLoadData)
84
84
  onLoadData(result);
85
- if (search) {
85
+ if (autoAddBlankItem) {
86
86
  SharedUtils.addBlankItem(result, idField, labelField);
87
87
  }
88
88
  setOptions(result);
@@ -9,13 +9,13 @@ import { SelectEx } from './SelectEx';
9
9
  */
10
10
  export function SelectBool(props) {
11
11
  // Destruct
12
- const { search = true, ...rest } = props;
12
+ const { search = true, autoAddBlankItem = search, ...rest } = props;
13
13
  // Options
14
14
  const options = [
15
15
  { id: 'false', label: globalApp.get('no') },
16
16
  { id: 'true', label: globalApp.get('yes') }
17
17
  ];
18
- if (search)
18
+ if (autoAddBlankItem)
19
19
  Utils.addBlankItem(options);
20
20
  // Layout
21
21
  return React.createElement(SelectEx, { options: options, search: search, ...rest });
@@ -5,6 +5,10 @@ import { IdLabelDto } from '@etsoo/appscript';
5
5
  * Extended select component props
6
6
  */
7
7
  export interface SelectExProps<T extends {}> extends Omit<SelectProps, 'labelId' | 'input' | 'native'> {
8
+ /**
9
+ * Auto add blank item
10
+ */
11
+ autoAddBlankItem?: boolean;
8
12
  /**
9
13
  * Id field, default is id
10
14
  */
@@ -12,7 +12,7 @@ import { Utils } from '@etsoo/shared';
12
12
  export function SelectEx(props) {
13
13
  var _a;
14
14
  // Destruct
15
- const { defaultValue, idField = 'id', itemIconRenderer, label, labelField = 'label', loadData, onItemClick, onLoadData, multiple = false, name, options = [], search = false, value, onChange, ...rest } = props;
15
+ const { defaultValue, idField = 'id', itemIconRenderer, label, labelField = 'label', loadData, onItemClick, onLoadData, multiple = false, name, options = [], search = false, autoAddBlankItem = search, value, onChange, ...rest } = props;
16
16
  // Options state
17
17
  const [localOptions, setOptions] = React.useState(options);
18
18
  const isMounted = React.useRef(true);
@@ -97,7 +97,7 @@ export function SelectEx(props) {
97
97
  return;
98
98
  if (onLoadData)
99
99
  onLoadData(result);
100
- if (search) {
100
+ if (autoAddBlankItem) {
101
101
  Utils.addBlankItem(result, idField, labelField);
102
102
  }
103
103
  setOptions(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.86",
3
+ "version": "1.4.87",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -13,6 +13,11 @@ import { SearchField } from './SearchField';
13
13
  */
14
14
  export interface ComboBoxProps<T extends {}>
15
15
  extends AutocompleteExtendedProps<T> {
16
+ /**
17
+ * Auto add blank item
18
+ */
19
+ autoAddBlankItem?: boolean;
20
+
16
21
  /**
17
22
  * Data readonly
18
23
  */
@@ -48,6 +53,7 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
48
53
  // Destruct
49
54
  const {
50
55
  search = false,
56
+ autoAddBlankItem = search,
51
57
  idField = 'id',
52
58
  idValue,
53
59
  inputError,
@@ -156,7 +162,7 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
156
162
  loadData().then((result) => {
157
163
  if (result == null || !isMounted.current) return;
158
164
  if (onLoadData) onLoadData(result);
159
- if (search) {
165
+ if (autoAddBlankItem) {
160
166
  SharedUtils.addBlankItem(result, idField, labelField);
161
167
  }
162
168
  setOptions(result);
@@ -17,7 +17,7 @@ export interface SelectBoolProps
17
17
  */
18
18
  export function SelectBool(props: SelectBoolProps) {
19
19
  // Destruct
20
- const { search = true, ...rest } = props;
20
+ const { search = true, autoAddBlankItem = search, ...rest } = props;
21
21
 
22
22
  // Options
23
23
  const options: IdLabelDto<string>[] = [
@@ -25,7 +25,7 @@ export function SelectBool(props: SelectBoolProps) {
25
25
  { id: 'true', label: globalApp.get('yes')! }
26
26
  ];
27
27
 
28
- if (search) Utils.addBlankItem(options);
28
+ if (autoAddBlankItem) Utils.addBlankItem(options);
29
29
 
30
30
  // Layout
31
31
  return <SelectEx options={options} search={search} {...rest} />;
@@ -21,6 +21,11 @@ import { Utils } from '@etsoo/shared';
21
21
  */
22
22
  export interface SelectExProps<T extends {}>
23
23
  extends Omit<SelectProps, 'labelId' | 'input' | 'native'> {
24
+ /**
25
+ * Auto add blank item
26
+ */
27
+ autoAddBlankItem?: boolean;
28
+
24
29
  /**
25
30
  * Id field, default is id
26
31
  */
@@ -82,6 +87,7 @@ export function SelectEx<T extends {} = IdLabelDto>(props: SelectExProps<T>) {
82
87
  name,
83
88
  options = [],
84
89
  search = false,
90
+ autoAddBlankItem = search,
85
91
  value,
86
92
  onChange,
87
93
  ...rest
@@ -172,7 +178,7 @@ export function SelectEx<T extends {} = IdLabelDto>(props: SelectExProps<T>) {
172
178
  loadData().then((result) => {
173
179
  if (result == null || !isMounted.current) return;
174
180
  if (onLoadData) onLoadData(result);
175
- if (search) {
181
+ if (autoAddBlankItem) {
176
182
  Utils.addBlankItem(result, idField, labelField);
177
183
  }
178
184
  setOptions(result);