@rjsf/semantic-ui 5.19.2 → 5.19.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/semantic-ui",
3
- "version": "5.19.2",
3
+ "version": "5.19.3",
4
4
  "main": "dist/index.js",
5
5
  "module": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -45,10 +45,10 @@
45
45
  "@babel/preset-env": "^7.23.9",
46
46
  "@babel/preset-react": "^7.23.3",
47
47
  "@babel/preset-typescript": "^7.23.3",
48
- "@rjsf/core": "^5.19.2",
49
- "@rjsf/snapshot-tests": "^5.19.2",
50
- "@rjsf/utils": "^5.19.2",
51
- "@rjsf/validator-ajv8": "^5.19.2",
48
+ "@rjsf/core": "^5.19.3",
49
+ "@rjsf/snapshot-tests": "^5.19.3",
50
+ "@rjsf/utils": "^5.19.3",
51
+ "@rjsf/validator-ajv8": "^5.19.3",
52
52
  "@types/jest": "^29.5.12",
53
53
  "@types/lodash": "^4.14.202",
54
54
  "@types/react": "^18.2.58",
@@ -95,5 +95,5 @@
95
95
  "dependencies": {
96
96
  "semantic-ui-css": "^2.5.0"
97
97
  },
98
- "gitHead": "dfdb9f6f35fa22d79b0502b85241b031a61adecc"
98
+ "gitHead": "3d0a309c23e6f6da116b350faead174dade7ca40"
99
99
  }
@@ -12,26 +12,33 @@ import {
12
12
  UIOptionsType,
13
13
  } from '@rjsf/utils';
14
14
  import map from 'lodash/map';
15
- import { Form, DropdownProps } from 'semantic-ui-react';
15
+ import { Form, DropdownProps, DropdownItemProps } from 'semantic-ui-react';
16
16
  import { getSemanticProps } from '../util';
17
17
 
18
18
  /**
19
19
  * Returns and creates an array format required for semantic drop down
20
- * @param {array} enumOptions- array of items for the dropdown
20
+ * @param {array} enumOptions - array of items for the dropdown
21
21
  * @param {array} enumDisabled - array of enum option values to disable
22
+ * @param {boolean} showPlaceholderOption - whether to show a placeholder option
23
+ * @param {string} placeholder - placeholder option label
22
24
  * @returns {*}
23
25
  */
24
26
  function createDefaultValueOptionsForDropDown<S extends StrictRJSFSchema = RJSFSchema>(
25
27
  enumOptions?: EnumOptionsType<S>[],
26
- enumDisabled?: UIOptionsType['enumDisabled']
28
+ enumDisabled?: UIOptionsType['enumDisabled'],
29
+ showPlaceholderOption?: boolean,
30
+ placeholder?: string
27
31
  ) {
28
32
  const disabledOptions = enumDisabled || [];
29
- const options = map(enumOptions, ({ label, value }, index) => ({
33
+ const options: DropdownItemProps[] = map(enumOptions, ({ label, value }, index) => ({
30
34
  disabled: disabledOptions.indexOf(value) !== -1,
31
35
  key: label,
32
36
  text: label,
33
37
  value: String(index),
34
38
  }));
39
+ if (showPlaceholderOption) {
40
+ options.unshift({ value: '', text: placeholder || '' });
41
+ }
35
42
  return options;
36
43
  }
37
44
 
@@ -61,6 +68,7 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
61
68
  onBlur,
62
69
  onFocus,
63
70
  rawErrors = [],
71
+ schema,
64
72
  } = props;
65
73
  const semanticProps = getSemanticProps<T, S, F>({
66
74
  uiSchema,
@@ -76,7 +84,13 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
76
84
  });
77
85
  const { enumDisabled, enumOptions, emptyValue: optEmptyVal } = options;
78
86
  const emptyValue = multiple ? [] : '';
79
- const dropdownOptions = createDefaultValueOptionsForDropDown<S>(enumOptions, enumDisabled);
87
+ const showPlaceholderOption = !multiple && schema.default === undefined;
88
+ const dropdownOptions = createDefaultValueOptionsForDropDown<S>(
89
+ enumOptions,
90
+ enumDisabled,
91
+ showPlaceholderOption,
92
+ placeholder
93
+ );
80
94
  const _onChange = (_: SyntheticEvent<HTMLElement>, { value }: DropdownProps) =>
81
95
  onChange(enumOptionsValueForIndex<S>(value as string[], enumOptions, optEmptyVal));
82
96
  // eslint-disable-next-line no-shadow