@rjsf/antd 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/dist/antd.esm.js +20 -7
- package/dist/antd.esm.js.map +3 -3
- package/dist/antd.umd.js +19 -7
- package/dist/index.js +20 -7
- package/dist/index.js.map +3 -3
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/widgets/SelectWidget/index.d.ts +1 -1
- package/lib/widgets/SelectWidget/index.js +15 -5
- package/lib/widgets/SelectWidget/index.js.map +1 -1
- package/package.json +6 -6
- package/src/widgets/SelectWidget/index.tsx +24 -10
|
@@ -4,4 +4,4 @@ import { FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from '@rjs
|
|
|
4
4
|
*
|
|
5
5
|
* @param props - The `WidgetProps` for this component
|
|
6
6
|
*/
|
|
7
|
-
export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({ autofocus, disabled, formContext, id, multiple, onBlur, onChange, onFocus, options, placeholder, readonly, value, }: WidgetProps<T, S, F>): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({ autofocus, disabled, formContext, id, multiple, onBlur, onChange, onFocus, options, placeholder, readonly, value, schema, }: WidgetProps<T, S, F>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { Select } from 'antd';
|
|
3
3
|
import { ariaDescribedByIds, enumOptionsIndexForValue, enumOptionsValueForIndex, } from '@rjsf/utils';
|
|
4
4
|
import isString from 'lodash/isString';
|
|
5
|
+
import { useMemo } from 'react';
|
|
5
6
|
const SELECT_STYLE = {
|
|
6
7
|
width: '100%',
|
|
7
8
|
};
|
|
@@ -10,7 +11,7 @@ const SELECT_STYLE = {
|
|
|
10
11
|
*
|
|
11
12
|
* @param props - The `WidgetProps` for this component
|
|
12
13
|
*/
|
|
13
|
-
export default function SelectWidget({ autofocus, disabled, formContext = {}, id, multiple, onBlur, onChange, onFocus, options, placeholder, readonly, value, }) {
|
|
14
|
+
export default function SelectWidget({ autofocus, disabled, formContext = {}, id, multiple, onBlur, onChange, onFocus, options, placeholder, readonly, value, schema, }) {
|
|
14
15
|
const { readonlyAsDisabled = true } = formContext;
|
|
15
16
|
const { enumOptions, enumDisabled, emptyValue } = options;
|
|
16
17
|
const handleChange = (nextValue) => onChange(enumOptionsValueForIndex(nextValue, enumOptions, emptyValue));
|
|
@@ -30,13 +31,22 @@ export default function SelectWidget({ autofocus, disabled, formContext = {}, id
|
|
|
30
31
|
const extraProps = {
|
|
31
32
|
name: id,
|
|
32
33
|
};
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
const showPlaceholderOption = !multiple && schema.default === undefined;
|
|
35
|
+
const selectOptions = useMemo(() => {
|
|
36
|
+
if (Array.isArray(enumOptions)) {
|
|
37
|
+
const options = enumOptions.map(({ value: optionValue, label: optionLabel }, index) => ({
|
|
35
38
|
disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(optionValue) !== -1,
|
|
36
39
|
key: String(index),
|
|
37
40
|
value: String(index),
|
|
38
41
|
label: optionLabel,
|
|
39
|
-
}))
|
|
40
|
-
|
|
42
|
+
}));
|
|
43
|
+
if (showPlaceholderOption) {
|
|
44
|
+
options.unshift({ value: '', label: placeholder || '' });
|
|
45
|
+
}
|
|
46
|
+
return options;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}, [enumDisabled, enumOptions, placeholder, showPlaceholderOption]);
|
|
50
|
+
return (_jsx(Select, { autoFocus: autofocus, disabled: disabled || (readonlyAsDisabled && readonly), getPopupContainer: getPopupContainer, id: id, mode: multiple ? 'multiple' : undefined, onBlur: !readonly ? handleBlur : undefined, onChange: !readonly ? handleChange : undefined, onFocus: !readonly ? handleFocus : undefined, placeholder: placeholder, style: SELECT_STYLE, value: selectedIndexes, ...extraProps, filterOption: filterOption, "aria-describedby": ariaDescribedByIds(id), options: selectOptions }));
|
|
41
51
|
}
|
|
42
52
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/widgets/SelectWidget/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,MAAM,CAAC;AAC3C,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,GAMzB,MAAM,aAAa,CAAC;AACrB,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAEvC,MAAM,YAAY,GAAG;IACnB,KAAK,EAAE,MAAM;CACd,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAIlC,EACA,SAAS,EACT,QAAQ,EACR,WAAW,GAAG,EAAO,EACrB,EAAE,EACF,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,OAAO,EACP,OAAO,EACP,WAAW,EACX,QAAQ,EACR,KAAK,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/widgets/SelectWidget/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,MAAM,CAAC;AAC3C,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,GAMzB,MAAM,aAAa,CAAC;AACrB,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,MAAM,YAAY,GAAG;IACnB,KAAK,EAAE,MAAM;CACd,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAIlC,EACA,SAAS,EACT,QAAQ,EACR,WAAW,GAAG,EAAO,EACrB,EAAE,EACF,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,OAAO,EACP,OAAO,EACP,WAAW,EACX,QAAQ,EACR,KAAK,EACL,MA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AE,WAAW,EACxB,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE,eAAe,KAClB,UAAU,EACd,YAAY,EAAE,YAAY,sBACR,kBAAkB,CAAI,EAAE,CAAC,EAC3C,OAAO,EAAE,aAAa,GACtB,CACH,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/antd",
|
|
3
|
-
"version": "5.19.
|
|
3
|
+
"version": "5.19.3",
|
|
4
4
|
"description": "Ant Design theme, fields and widgets for react-jsonschema-form",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
"@babel/preset-env": "^7.23.9",
|
|
57
57
|
"@babel/preset-react": "^7.23.3",
|
|
58
58
|
"@babel/preset-typescript": "^7.23.3",
|
|
59
|
-
"@rjsf/core": "^5.19.
|
|
60
|
-
"@rjsf/snapshot-tests": "^5.19.
|
|
61
|
-
"@rjsf/utils": "^5.19.
|
|
62
|
-
"@rjsf/validator-ajv8": "^5.19.
|
|
59
|
+
"@rjsf/core": "^5.19.3",
|
|
60
|
+
"@rjsf/snapshot-tests": "^5.19.3",
|
|
61
|
+
"@rjsf/utils": "^5.19.3",
|
|
62
|
+
"@rjsf/validator-ajv8": "^5.19.3",
|
|
63
63
|
"@rollup/plugin-replace": "^5.0.5",
|
|
64
64
|
"@types/jest": "^29.5.12",
|
|
65
65
|
"@types/lodash": "^4.14.202",
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
"publishConfig": {
|
|
107
107
|
"access": "public"
|
|
108
108
|
},
|
|
109
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "3d0a309c23e6f6da116b350faead174dade7ca40"
|
|
110
110
|
}
|
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
WidgetProps,
|
|
11
11
|
} from '@rjsf/utils';
|
|
12
12
|
import isString from 'lodash/isString';
|
|
13
|
+
import { DefaultOptionType } from 'antd/es/select';
|
|
14
|
+
import { useMemo } from 'react';
|
|
13
15
|
|
|
14
16
|
const SELECT_STYLE = {
|
|
15
17
|
width: '100%',
|
|
@@ -37,6 +39,7 @@ export default function SelectWidget<
|
|
|
37
39
|
placeholder,
|
|
38
40
|
readonly,
|
|
39
41
|
value,
|
|
42
|
+
schema,
|
|
40
43
|
}: WidgetProps<T, S, F>) {
|
|
41
44
|
const { readonlyAsDisabled = true } = formContext as GenericObjectType;
|
|
42
45
|
|
|
@@ -65,6 +68,26 @@ export default function SelectWidget<
|
|
|
65
68
|
const extraProps = {
|
|
66
69
|
name: id,
|
|
67
70
|
};
|
|
71
|
+
|
|
72
|
+
const showPlaceholderOption = !multiple && schema.default === undefined;
|
|
73
|
+
|
|
74
|
+
const selectOptions: DefaultOptionType[] | undefined = useMemo(() => {
|
|
75
|
+
if (Array.isArray(enumOptions)) {
|
|
76
|
+
const options: DefaultOptionType[] = enumOptions.map(({ value: optionValue, label: optionLabel }, index) => ({
|
|
77
|
+
disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(optionValue) !== -1,
|
|
78
|
+
key: String(index),
|
|
79
|
+
value: String(index),
|
|
80
|
+
label: optionLabel,
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
if (showPlaceholderOption) {
|
|
84
|
+
options.unshift({ value: '', label: placeholder || '' });
|
|
85
|
+
}
|
|
86
|
+
return options;
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}, [enumDisabled, enumOptions, placeholder, showPlaceholderOption]);
|
|
90
|
+
|
|
68
91
|
return (
|
|
69
92
|
<Select
|
|
70
93
|
autoFocus={autofocus}
|
|
@@ -81,16 +104,7 @@ export default function SelectWidget<
|
|
|
81
104
|
{...extraProps}
|
|
82
105
|
filterOption={filterOption}
|
|
83
106
|
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
84
|
-
options={
|
|
85
|
-
Array.isArray(enumOptions)
|
|
86
|
-
? enumOptions.map(({ value: optionValue, label: optionLabel }, index) => ({
|
|
87
|
-
disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(optionValue) !== -1,
|
|
88
|
-
key: String(index),
|
|
89
|
-
value: String(index),
|
|
90
|
-
label: optionLabel,
|
|
91
|
-
}))
|
|
92
|
-
: undefined
|
|
93
|
-
}
|
|
107
|
+
options={selectOptions}
|
|
94
108
|
/>
|
|
95
109
|
);
|
|
96
110
|
}
|