@rjsf/mantine 6.4.2 → 6.5.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.
Files changed (42) hide show
  1. package/dist/index.cjs +59 -45
  2. package/dist/index.cjs.map +2 -2
  3. package/dist/mantine.esm.js +69 -49
  4. package/dist/mantine.esm.js.map +3 -3
  5. package/dist/mantine.umd.js +59 -45
  6. package/lib/Form/index.js +1 -1
  7. package/lib/Theme/index.js +2 -2
  8. package/lib/index.d.ts +4 -4
  9. package/lib/index.js +4 -4
  10. package/lib/templates/BaseInputTemplate.js +3 -2
  11. package/lib/templates/BaseInputTemplate.js.map +1 -1
  12. package/lib/templates/ButtonTemplates/AddButton.js +2 -2
  13. package/lib/templates/ButtonTemplates/IconButton.js +1 -1
  14. package/lib/templates/ButtonTemplates/index.js +3 -3
  15. package/lib/templates/ErrorList.js +1 -1
  16. package/lib/templates/OptionalDataControlsTemplate.js +2 -2
  17. package/lib/templates/WrapIfAdditionalTemplate.js +1 -1
  18. package/lib/templates/WrapIfAdditionalTemplate.js.map +1 -1
  19. package/lib/templates/index.js +16 -16
  20. package/lib/tsconfig.tsbuildinfo +1 -1
  21. package/lib/widgets/CheckboxesWidget.js +10 -9
  22. package/lib/widgets/CheckboxesWidget.js.map +1 -1
  23. package/lib/widgets/ColorWidget.js +1 -1
  24. package/lib/widgets/DateTime/DateTimeWidget.js +1 -1
  25. package/lib/widgets/DateTime/DateWidget.js +1 -1
  26. package/lib/widgets/DateTime/index.d.ts +5 -5
  27. package/lib/widgets/DateTime/index.js +5 -5
  28. package/lib/widgets/FileWidget.js +1 -1
  29. package/lib/widgets/PasswordWidget.js +1 -1
  30. package/lib/widgets/RadioWidget.js +10 -9
  31. package/lib/widgets/RadioWidget.js.map +1 -1
  32. package/lib/widgets/RangeWidget.js +1 -1
  33. package/lib/widgets/SelectWidget.js +30 -13
  34. package/lib/widgets/SelectWidget.js.map +1 -1
  35. package/lib/widgets/TextareaWidget.js +1 -1
  36. package/lib/widgets/index.js +10 -10
  37. package/package.json +10 -10
  38. package/src/templates/BaseInputTemplate.tsx +5 -1
  39. package/src/templates/WrapIfAdditionalTemplate.tsx +1 -0
  40. package/src/widgets/CheckboxesWidget.tsx +11 -8
  41. package/src/widgets/RadioWidget.tsx +11 -8
  42. package/src/widgets/SelectWidget.tsx +40 -32
@@ -1,8 +1,10 @@
1
1
  import { FocusEvent, useCallback, useMemo } 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
  FormContextType,
8
10
  RJSFSchema,
@@ -41,70 +43,76 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
41
43
  } = props;
42
44
 
43
45
  const { enumOptions, enumDisabled, emptyValue } = options;
46
+ const optionValueFormat = getOptionValueFormat(options);
44
47
  const themeProps = cleanupOptions(options);
45
48
 
46
49
  const handleChange = useCallback(
47
50
  (nextValue: any) => {
48
51
  if (!disabled && !readonly && onChange) {
49
- onChange(enumOptionsValueForIndex<S>(nextValue, enumOptions, emptyValue));
52
+ onChange(enumOptionValueDecoder<S>(nextValue, enumOptions, optionValueFormat, emptyValue));
50
53
  }
51
54
  },
52
- [onChange, disabled, readonly, enumOptions, emptyValue],
55
+ [onChange, disabled, readonly, enumOptions, emptyValue, optionValueFormat],
53
56
  );
54
57
 
55
58
  const handleBlur = useCallback(
56
59
  ({ target }: FocusEvent<HTMLInputElement>) => {
57
60
  if (onBlur) {
58
- onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
61
+ onBlur(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, emptyValue));
59
62
  }
60
63
  },
61
- [onBlur, id, enumOptions, emptyValue],
64
+ [onBlur, id, enumOptions, emptyValue, optionValueFormat],
62
65
  );
63
66
 
64
67
  const handleFocus = useCallback(
65
68
  ({ target }: FocusEvent<HTMLInputElement>) => {
66
69
  if (onFocus) {
67
- onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
70
+ onFocus(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, emptyValue));
68
71
  }
69
72
  },
70
- [onFocus, id, enumOptions, emptyValue],
73
+ [onFocus, id, enumOptions, emptyValue, optionValueFormat],
71
74
  );
72
75
 
73
- const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, multiple);
74
-
75
76
  const selectOptions = useMemo(() => {
76
77
  if (Array.isArray(enumOptions)) {
77
78
  return enumOptions.map((option, index) => ({
78
79
  key: String(index),
79
- value: String(index),
80
+ value: enumOptionValueEncoder(option.value, index, optionValueFormat),
80
81
  label: option.label,
81
82
  disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1,
82
83
  }));
83
84
  }
84
85
  return [];
85
- }, [enumDisabled, enumOptions]);
86
+ }, [enumDisabled, enumOptions, optionValueFormat]);
86
87
 
87
- const Component = multiple ? MultiSelect : Select;
88
+ const sharedProps = {
89
+ id,
90
+ name: htmlName || id,
91
+ label: labelValue(label || undefined, hideLabel, false),
92
+ data: selectOptions,
93
+ onChange: !readonly ? handleChange : undefined,
94
+ onBlur: !readonly ? handleBlur : undefined,
95
+ onFocus: !readonly ? handleFocus : undefined,
96
+ autoFocus: autofocus,
97
+ placeholder,
98
+ disabled: disabled || readonly,
99
+ required,
100
+ error: rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined,
101
+ searchable: true,
102
+ 'aria-describedby': ariaDescribedByIds(id),
103
+ comboboxProps: { withinPortal: false },
104
+ ...themeProps,
105
+ };
88
106
 
89
- return (
90
- <Component
91
- id={id}
92
- name={htmlName || id}
93
- label={labelValue(label || undefined, hideLabel, false)}
94
- data={selectOptions}
95
- value={multiple ? (selectedIndexes as any) : (selectedIndexes as string)}
96
- onChange={!readonly ? handleChange : undefined}
97
- onBlur={!readonly ? handleBlur : undefined}
98
- onFocus={!readonly ? handleFocus : undefined}
99
- autoFocus={autofocus}
100
- placeholder={placeholder}
101
- disabled={disabled || readonly}
102
- required={required}
103
- error={rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined}
104
- searchable
105
- {...themeProps}
106
- aria-describedby={ariaDescribedByIds(id)}
107
- comboboxProps={{ withinPortal: false }}
107
+ return multiple ? (
108
+ <MultiSelect
109
+ {...sharedProps}
110
+ value={enumOptionSelectedValue<S>(value, enumOptions, true, optionValueFormat, []) as string[]}
111
+ />
112
+ ) : (
113
+ <Select
114
+ {...sharedProps}
115
+ value={enumOptionSelectedValue<S>(value, enumOptions, false, optionValueFormat, null) as string | null}
108
116
  />
109
117
  );
110
118
  }