@rjsf/semantic-ui 6.4.1 → 6.5.0

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": "6.4.1",
3
+ "version": "6.5.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -67,10 +67,10 @@
67
67
  "semantic-ui-react": "^2.1.3"
68
68
  },
69
69
  "devDependencies": {
70
- "@rjsf/core": "6.4.1",
71
- "@rjsf/snapshot-tests": "6.4.1",
72
- "@rjsf/utils": "6.4.1",
73
- "@rjsf/validator-ajv8": "6.4.1",
70
+ "@rjsf/core": "6.5.0",
71
+ "@rjsf/snapshot-tests": "6.5.0",
72
+ "@rjsf/utils": "6.5.0",
73
+ "@rjsf/validator-ajv8": "6.5.0",
74
74
  "atob": "^2.1.2",
75
75
  "eslint": "^8.57.1",
76
76
  "semantic-ui-react": "^2.1.5"
@@ -1,8 +1,10 @@
1
1
  import { FormEvent } from 'react';
2
2
  import {
3
3
  ariaDescribedByIds,
4
+ enumOptionValueDecoder,
5
+ enumOptionValueEncoder,
4
6
  enumOptionsIsSelected,
5
- enumOptionsValueForIndex,
7
+ getOptionValueFormat,
6
8
  optionId,
7
9
  FormContextType,
8
10
  RJSFSchema,
@@ -36,13 +38,14 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
36
38
  rawErrors = [],
37
39
  } = props;
38
40
  const { enumOptions, enumDisabled, emptyValue } = options;
41
+ const optionValueFormat = getOptionValueFormat(options);
39
42
  const semanticProps = getSemanticProps<T, S, F>({
40
43
  formContext: registry.formContext,
41
44
  options,
42
45
  uiSchema,
43
46
  });
44
47
  const _onChange = (_: FormEvent<HTMLInputElement>, { value: eventValue }: CheckboxProps) => {
45
- return onChange(enumOptionsValueForIndex<S>(eventValue!, enumOptions, emptyValue));
48
+ return onChange(enumOptionValueDecoder<S>(String(eventValue!), enumOptions, optionValueFormat, emptyValue));
46
49
  };
47
50
 
48
51
  const _onBlur = () => onBlur(id, value);
@@ -65,7 +68,7 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
65
68
  onBlur={_onBlur}
66
69
  onChange={_onChange}
67
70
  label={option.label}
68
- value={String(index)}
71
+ value={enumOptionValueEncoder(option.value, index, optionValueFormat)}
69
72
  error={rawErrors.length > 0}
70
73
  key={index}
71
74
  checked={checked}
@@ -1,11 +1,14 @@
1
1
  import { FocusEvent, SyntheticEvent } from 'react';
2
2
  import {
3
3
  ariaDescribedByIds,
4
- enumOptionsIndexForValue,
5
- enumOptionsValueForIndex,
4
+ enumOptionSelectedValue,
5
+ enumOptionValueDecoder,
6
+ enumOptionValueEncoder,
7
+ getOptionValueFormat,
6
8
  labelValue,
7
9
  EnumOptionsType,
8
10
  FormContextType,
11
+ OptionValueFormat,
9
12
  RJSFSchema,
10
13
  StrictRJSFSchema,
11
14
  WidgetProps,
@@ -28,13 +31,14 @@ function createDefaultValueOptionsForDropDown<S extends StrictRJSFSchema = RJSFS
28
31
  enumDisabled?: UIOptionsType['enumDisabled'],
29
32
  showPlaceholderOption?: boolean,
30
33
  placeholder?: string,
34
+ format: OptionValueFormat = 'indexed',
31
35
  ) {
32
36
  const disabledOptions = enumDisabled || [];
33
37
  const options: DropdownItemProps[] = map(enumOptions, ({ label, value }, index) => ({
34
38
  disabled: disabledOptions.indexOf(value) !== -1,
35
39
  key: label,
36
40
  text: label,
37
- value: String(index),
41
+ value: enumOptionValueEncoder(value, index, format),
38
42
  }));
39
43
  if (showPlaceholderOption) {
40
44
  options.unshift({ value: '', text: placeholder || '' });
@@ -85,22 +89,22 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
85
89
  });
86
90
  const { enumDisabled, enumOptions, emptyValue: optEmptyVal } = options;
87
91
  const emptyValue = multiple ? [] : '';
92
+ const optionValueFormat = getOptionValueFormat(options);
88
93
  const showPlaceholderOption = !multiple && schema.default === undefined;
89
94
  const dropdownOptions = createDefaultValueOptionsForDropDown<S>(
90
95
  enumOptions,
91
96
  enumDisabled,
92
97
  showPlaceholderOption,
93
98
  placeholder,
99
+ optionValueFormat,
94
100
  );
95
101
  const _onChange = (_: SyntheticEvent<HTMLElement>, { value }: DropdownProps) =>
96
- onChange(enumOptionsValueForIndex<S>(value as string[], enumOptions, optEmptyVal));
102
+ onChange(enumOptionValueDecoder<S>(value as string[], enumOptions, optionValueFormat, optEmptyVal));
97
103
  // eslint-disable-next-line no-shadow
98
104
  const _onBlur = (_: FocusEvent<HTMLElement>, { target }: DropdownProps) =>
99
- onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, optEmptyVal));
105
+ onBlur(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, optEmptyVal));
100
106
  const _onFocus = (_: FocusEvent<HTMLElement>, { target }: DropdownProps) =>
101
- onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, optEmptyVal));
102
- const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, multiple);
103
-
107
+ onFocus(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, optEmptyVal));
104
108
  return (
105
109
  <Form.Dropdown
106
110
  key={id}
@@ -108,7 +112,7 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
108
112
  name={htmlName || id}
109
113
  label={labelValue(label || undefined, hideLabel, false)}
110
114
  multiple={typeof multiple === 'undefined' ? false : multiple}
111
- value={typeof value === 'undefined' ? emptyValue : selectedIndexes}
115
+ value={enumOptionSelectedValue<S>(value, enumOptions, !!multiple, optionValueFormat, emptyValue)}
112
116
  error={rawErrors.length > 0}
113
117
  disabled={disabled}
114
118
  placeholder={placeholder}
@@ -60,6 +60,7 @@ export default function WrapIfAdditionalTemplate<
60
60
  <Grid.Column width={7} className='form-additional'>
61
61
  <Form.Group widths='equal' grouped>
62
62
  <Form.Input
63
+ key={label}
63
64
  className='form-group'
64
65
  hasFeedback
65
66
  fluid