@etsoo/react 1.4.51 → 1.4.52

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
+ * Data readonly
10
+ */
11
+ dataReadonly?: boolean;
8
12
  /**
9
13
  * Label field
10
14
  */
@@ -1,3 +1,4 @@
1
+ import { Keyboard } from '@etsoo/shared';
1
2
  import { Autocomplete } from '@mui/material';
2
3
  import React from 'react';
3
4
  import { Utils } from '../app/Utils';
@@ -10,7 +11,7 @@ import { SearchField } from './SearchField';
10
11
  */
11
12
  export function ComboBox(props) {
12
13
  // Destruct
13
- const { search = false, idField = 'id', idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, defaultValue, label, labelField = 'label', loadData, onLoadData, name, inputAutoComplete = 'off', options, readOnly = true, onChange, value, getOptionLabel = (option) => String(Reflect.get(option, labelField)), sx = { minWidth: '150px' }, ...rest } = props;
14
+ 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;
14
15
  // Value input ref
15
16
  const inputRef = React.createRef();
16
17
  // Options state
@@ -47,6 +48,13 @@ export function ComboBox(props) {
47
48
  Object.assign(params.inputProps, { 'data-reset': true });
48
49
  }
49
50
  }
51
+ if (dataReadonly) {
52
+ params.inputProps.onKeyDown = (event) => {
53
+ if (Keyboard.isTypingContent(event.key)) {
54
+ event.preventDefault();
55
+ }
56
+ };
57
+ }
50
58
  // https://stackoverflow.com/questions/15738259/disabling-chrome-autofill
51
59
  // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html
52
60
  Object.assign(params.inputProps, { autoComplete: inputAutoComplete });
@@ -89,5 +97,5 @@ export function ComboBox(props) {
89
97
  // Custom
90
98
  if (onChange != null)
91
99
  onChange(event, value, reason, details);
92
- }, sx: sx, renderInput: (params) => search ? (React.createElement(SearchField, { ...addReadOnly(params), label: label, name: name + 'Input', margin: inputMargin, variant: inputVariant, required: inputRequired, error: inputError, helperText: inputHelperText })) : (React.createElement(InputField, { ...addReadOnly(params), label: label, name: name + 'Input', margin: inputMargin, variant: inputVariant, required: inputRequired, error: inputError, helperText: inputHelperText })), options: localOptions, ...rest })));
100
+ }, openOnFocus: openOnFocus, sx: sx, renderInput: (params) => search ? (React.createElement(SearchField, { ...addReadOnly(params), label: label, name: name + 'Input', margin: inputMargin, variant: inputVariant, required: inputRequired, error: inputError, helperText: inputHelperText })) : (React.createElement(InputField, { ...addReadOnly(params), label: label, name: name + 'Input', margin: inputMargin, variant: inputVariant, required: inputRequired, error: inputError, helperText: inputHelperText })), options: localOptions, ...rest })));
93
101
  }
@@ -3,6 +3,7 @@ import { IconButton, InputAdornment, TextField } from '@mui/material';
3
3
  import { MUGlobal } from './MUGlobal';
4
4
  import { Clear, Visibility } from '@mui/icons-material';
5
5
  import useCombinedRefs from '../uses/useCombinedRefs';
6
+ import { Keyboard } from '@etsoo/shared';
6
7
  export const TextFieldEx = React.forwardRef((props, ref) => {
7
8
  // Destructure
8
9
  const { changeDelay, error, fullWidth = true, helperText, InputProps = {}, onChange, onKeyPress, onEnter, inputRef, readOnly, showClear, showPassword, type, variant = MUGlobal.textFieldVariant, ...rest } = props;
@@ -71,7 +72,7 @@ export const TextFieldEx = React.forwardRef((props, ref) => {
71
72
  const onKeyPressEx = onEnter == null
72
73
  ? onKeyPress
73
74
  : (e) => {
74
- if (e.key === 'Enter') {
75
+ if (e.key === Keyboard.Keys.Enter) {
75
76
  // Enter press callback
76
77
  onEnter(e);
77
78
  }
package/lib/mu/Tiplist.js CHANGED
@@ -11,7 +11,7 @@ import { SearchField } from './SearchField';
11
11
  */
12
12
  export function Tiplist(props) {
13
13
  // Destruct
14
- const { search = false, idField = 'id', idValue, inputAutoComplete = 'off', inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, label, loadData, defaultValue, value, name, readOnly, onChange, sx = { minWidth: '180px' }, ...rest } = props;
14
+ const { search = false, idField = 'id', idValue, inputAutoComplete = 'off', inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, label, loadData, defaultValue, value, name, readOnly, onChange, openOnFocus = true, sx = { minWidth: '180px' }, ...rest } = props;
15
15
  // Value input ref
16
16
  const inputRef = React.createRef();
17
17
  // Local value
@@ -145,7 +145,7 @@ export function Tiplist(props) {
145
145
  stateUpdate({ options: [] });
146
146
  loadDataDirect();
147
147
  }
148
- }, open: states.open, onOpen: () => {
148
+ }, open: states.open, openOnFocus: openOnFocus, onOpen: () => {
149
149
  // Should load
150
150
  const loading = states.loading
151
151
  ? true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.51",
3
+ "version": "1.4.52",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -52,7 +52,7 @@
52
52
  "@emotion/styled": "^11.6.0",
53
53
  "@etsoo/appscript": "^1.2.25",
54
54
  "@etsoo/notificationbase": "^1.1.0",
55
- "@etsoo/shared": "^1.1.5",
55
+ "@etsoo/shared": "^1.1.6",
56
56
  "@mui/icons-material": "^5.3.0",
57
57
  "@mui/material": "^5.3.0",
58
58
  "@reach/router": "^1.3.4",
@@ -1,4 +1,5 @@
1
1
  import { IdLabelDto } from '@etsoo/appscript';
2
+ import { Keyboard } from '@etsoo/shared';
2
3
  import { Autocomplete, AutocompleteRenderInputParams } from '@mui/material';
3
4
  import React from 'react';
4
5
  import { Utils } from '../app/Utils';
@@ -11,6 +12,11 @@ import { SearchField } from './SearchField';
11
12
  */
12
13
  export interface ComboBoxProps<T extends {}>
13
14
  extends AutocompleteExtendedProps<T> {
15
+ /**
16
+ * Data readonly
17
+ */
18
+ dataReadonly?: boolean;
19
+
14
20
  /**
15
21
  * Label field
16
22
  */
@@ -57,8 +63,10 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
57
63
  name,
58
64
  inputAutoComplete = 'off',
59
65
  options,
60
- readOnly = true,
66
+ dataReadonly = true,
67
+ readOnly,
61
68
  onChange,
69
+ openOnFocus = true,
62
70
  value,
63
71
  getOptionLabel = (option: T) => String(Reflect.get(option, labelField)),
64
72
  sx = { minWidth: '150px' },
@@ -109,6 +117,14 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
109
117
  }
110
118
  }
111
119
 
120
+ if (dataReadonly) {
121
+ params.inputProps.onKeyDown = (event) => {
122
+ if (Keyboard.isTypingContent(event.key)) {
123
+ event.preventDefault();
124
+ }
125
+ };
126
+ }
127
+
112
128
  // https://stackoverflow.com/questions/15738259/disabling-chrome-autofill
113
129
  // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html
114
130
  Object.assign(params.inputProps, { autoComplete: inputAutoComplete });
@@ -176,6 +192,7 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
176
192
  if (onChange != null)
177
193
  onChange(event, value, reason, details);
178
194
  }}
195
+ openOnFocus={openOnFocus}
179
196
  sx={sx}
180
197
  renderInput={(params) =>
181
198
  search ? (
@@ -8,6 +8,7 @@ import {
8
8
  import { MUGlobal } from './MUGlobal';
9
9
  import { Clear, Visibility } from '@mui/icons-material';
10
10
  import useCombinedRefs from '../uses/useCombinedRefs';
11
+ import { Keyboard } from '@etsoo/shared';
11
12
 
12
13
  /**
13
14
  * Extended text field props
@@ -166,7 +167,7 @@ export const TextFieldEx = React.forwardRef<
166
167
  onEnter == null
167
168
  ? onKeyPress
168
169
  : (e: React.KeyboardEvent<HTMLDivElement>) => {
169
- if (e.key === 'Enter') {
170
+ if (e.key === Keyboard.Keys.Enter) {
170
171
  // Enter press callback
171
172
  onEnter(e);
172
173
  }
@@ -54,6 +54,7 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
54
54
  name,
55
55
  readOnly,
56
56
  onChange,
57
+ openOnFocus = true,
57
58
  sx = { minWidth: '180px' },
58
59
  ...rest
59
60
  } = props;
@@ -242,6 +243,7 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
242
243
  }
243
244
  }}
244
245
  open={states.open}
246
+ openOnFocus={openOnFocus}
245
247
  onOpen={() => {
246
248
  // Should load
247
249
  const loading = states.loading