Skip to content

Commit c936652

Browse files
committed
Move the change to optionsList utils
1 parent b834181 commit c936652

File tree

18 files changed

+272
-291
lines changed

18 files changed

+272
-291
lines changed

packages/antd/src/widgets/SelectWidget/index.tsx

+10-21
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import {
1010
WidgetProps,
1111
} from '@rjsf/utils';
1212
import isString from 'lodash/isString';
13-
import { DefaultOptionType } from 'antd/es/select';
14-
import { useMemo } from 'react';
1513

1614
const SELECT_STYLE = {
1715
width: '100%',
@@ -39,7 +37,6 @@ export default function SelectWidget<
3937
placeholder,
4038
readonly,
4139
value,
42-
schema,
4340
}: WidgetProps<T, S, F>) {
4441
const { readonlyAsDisabled = true } = formContext as GenericObjectType;
4542

@@ -68,23 +65,6 @@ export default function SelectWidget<
6865
const extraProps = {
6966
name: id,
7067
};
71-
72-
const selectOptions: DefaultOptionType[] | undefined = useMemo(() => {
73-
if (Array.isArray(enumOptions)) {
74-
const options = [...enumOptions];
75-
if (!multiple && schema.default === undefined) {
76-
options.unshift({ value: '', label: placeholder || '' });
77-
}
78-
return options.map(({ value: optionValue, label: optionLabel }, index) => ({
79-
disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(optionValue) !== -1,
80-
key: String(index),
81-
value: String(index),
82-
label: optionLabel,
83-
}));
84-
}
85-
return undefined;
86-
}, [enumDisabled, enumOptions, multiple, placeholder, schema.default]);
87-
8868
return (
8969
<Select
9070
autoFocus={autofocus}
@@ -101,7 +81,16 @@ export default function SelectWidget<
10181
{...extraProps}
10282
filterOption={filterOption}
10383
aria-describedby={ariaDescribedByIds<T>(id)}
104-
options={selectOptions}
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+
}
10594
/>
10695
);
10796
}

packages/antd/test/__snapshots__/Form.test.tsx.snap

+78-132
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ exports[`single fields format color 1`] = `
878878
onFocus={[Function]}
879879
onKeyDown={[Function]}
880880
placeholder=""
881-
type="color"
881+
type="text"
882882
value=""
883883
/>
884884
<span
@@ -935,61 +935,35 @@ exports[`single fields format date 1`] = `
935935
<div
936936
className="ant-form-item-control-input-content"
937937
>
938-
<div
939-
className="ant-picker ant-picker-outlined ant-picker-has-feedback css-dev-only-do-not-override-1b0bdye"
938+
<span
939+
className="ant-input-affix-wrapper css-dev-only-do-not-override-1b0bdye ant-input-outlined"
940940
onClick={[Function]}
941941
style={
942942
{
943943
"width": "100%",
944944
}
945945
}
946946
>
947-
<div
948-
className="ant-picker-input"
949-
>
950-
<input
951-
aria-describedby="root__error root__description root__help"
952-
autoComplete="off"
953-
disabled={false}
954-
id="root"
955-
name="root"
956-
onBlur={[Function]}
957-
onChange={[Function]}
958-
onFocus={[Function]}
959-
onKeyDown={[Function]}
960-
onMouseDown={[Function]}
961-
placeholder=""
962-
readOnly={true}
963-
size={12}
964-
title=""
965-
value=""
966-
/>
967-
<span
968-
className="ant-picker-suffix"
969-
onMouseDown={[Function]}
970-
>
971-
<span
972-
aria-label="calendar"
973-
className="anticon anticon-calendar"
974-
role="img"
975-
>
976-
<svg
977-
aria-hidden="true"
978-
data-icon="calendar"
979-
fill="currentColor"
980-
focusable="false"
981-
height="1em"
982-
viewBox="64 64 896 896"
983-
width="1em"
984-
>
985-
<path
986-
d="M880 184H712v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H384v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H144c-17.7 0-32 14.3-32 32v664c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V216c0-17.7-14.3-32-32-32zm-40 656H184V460h656v380zM184 392V256h128v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h256v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h128v136H184z"
987-
/>
988-
</svg>
989-
</span>
990-
</span>
991-
</div>
992-
</div>
947+
<input
948+
aria-describedby="root__error root__description root__help"
949+
className="ant-input css-dev-only-do-not-override-1b0bdye"
950+
disabled={false}
951+
id="root"
952+
name="root"
953+
onBlur={[Function]}
954+
onChange={[Function]}
955+
onCompositionEnd={[Function]}
956+
onCompositionStart={[Function]}
957+
onFocus={[Function]}
958+
onKeyDown={[Function]}
959+
placeholder=""
960+
type="text"
961+
value=""
962+
/>
963+
<span
964+
className="ant-input-suffix"
965+
/>
966+
</span>
993967
</div>
994968
</div>
995969
</div>
@@ -1040,61 +1014,35 @@ exports[`single fields format datetime 1`] = `
10401014
<div
10411015
className="ant-form-item-control-input-content"
10421016
>
1043-
<div
1044-
className="ant-picker ant-picker-outlined ant-picker-has-feedback css-dev-only-do-not-override-1b0bdye"
1017+
<span
1018+
className="ant-input-affix-wrapper css-dev-only-do-not-override-1b0bdye ant-input-outlined"
10451019
onClick={[Function]}
10461020
style={
10471021
{
10481022
"width": "100%",
10491023
}
10501024
}
10511025
>
1052-
<div
1053-
className="ant-picker-input"
1054-
>
1055-
<input
1056-
aria-describedby="root__error root__description root__help"
1057-
autoComplete="off"
1058-
disabled={false}
1059-
id="root"
1060-
name="root"
1061-
onBlur={[Function]}
1062-
onChange={[Function]}
1063-
onFocus={[Function]}
1064-
onKeyDown={[Function]}
1065-
onMouseDown={[Function]}
1066-
placeholder=""
1067-
readOnly={true}
1068-
size={21}
1069-
title=""
1070-
value=""
1071-
/>
1072-
<span
1073-
className="ant-picker-suffix"
1074-
onMouseDown={[Function]}
1075-
>
1076-
<span
1077-
aria-label="calendar"
1078-
className="anticon anticon-calendar"
1079-
role="img"
1080-
>
1081-
<svg
1082-
aria-hidden="true"
1083-
data-icon="calendar"
1084-
fill="currentColor"
1085-
focusable="false"
1086-
height="1em"
1087-
viewBox="64 64 896 896"
1088-
width="1em"
1089-
>
1090-
<path
1091-
d="M880 184H712v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H384v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H144c-17.7 0-32 14.3-32 32v664c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V216c0-17.7-14.3-32-32-32zm-40 656H184V460h656v380zM184 392V256h128v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h256v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h128v136H184z"
1092-
/>
1093-
</svg>
1094-
</span>
1095-
</span>
1096-
</div>
1097-
</div>
1026+
<input
1027+
aria-describedby="root__error root__description root__help"
1028+
className="ant-input css-dev-only-do-not-override-1b0bdye"
1029+
disabled={false}
1030+
id="root"
1031+
name="root"
1032+
onBlur={[Function]}
1033+
onChange={[Function]}
1034+
onCompositionEnd={[Function]}
1035+
onCompositionStart={[Function]}
1036+
onFocus={[Function]}
1037+
onKeyDown={[Function]}
1038+
placeholder=""
1039+
type="text"
1040+
value=""
1041+
/>
1042+
<span
1043+
className="ant-input-suffix"
1044+
/>
1045+
</span>
10981046
</div>
10991047
</div>
11001048
</div>
@@ -1167,7 +1115,7 @@ exports[`single fields format time 1`] = `
11671115
onFocus={[Function]}
11681116
onKeyDown={[Function]}
11691117
placeholder=""
1170-
type="time"
1118+
type="text"
11711119
value=""
11721120
/>
11731121
<span
@@ -3354,9 +3302,9 @@ exports[`single fields select field single choice formData 1`] = `
33543302
</span>
33553303
<span
33563304
className="ant-select-selection-item"
3357-
title="foo"
3305+
title="bar"
33583306
>
3359-
foo
3307+
bar
33603308
</span>
33613309
</div>
33623310
<span
@@ -3542,37 +3490,35 @@ exports[`single fields string field format data-url 1`] = `
35423490
<div
35433491
className="ant-form-item-control-input-content"
35443492
>
3545-
<div>
3546-
<span
3547-
className="ant-input-affix-wrapper css-dev-only-do-not-override-1b0bdye ant-input-outlined"
3548-
onClick={[Function]}
3549-
style={
3550-
{
3551-
"width": "100%",
3552-
}
3493+
<span
3494+
className="ant-input-affix-wrapper css-dev-only-do-not-override-1b0bdye ant-input-outlined"
3495+
onClick={[Function]}
3496+
style={
3497+
{
3498+
"width": "100%",
35533499
}
3554-
>
3555-
<input
3556-
aria-describedby="root__error root__description root__help"
3557-
className="ant-input css-dev-only-do-not-override-1b0bdye"
3558-
disabled={false}
3559-
id="root"
3560-
name="root"
3561-
onBlur={[Function]}
3562-
onChange={[Function]}
3563-
onCompositionEnd={[Function]}
3564-
onCompositionStart={[Function]}
3565-
onFocus={[Function]}
3566-
onKeyDown={[Function]}
3567-
placeholder=""
3568-
type="file"
3569-
value=""
3570-
/>
3571-
<span
3572-
className="ant-input-suffix"
3573-
/>
3574-
</span>
3575-
</div>
3500+
}
3501+
>
3502+
<input
3503+
aria-describedby="root__error root__description root__help"
3504+
className="ant-input css-dev-only-do-not-override-1b0bdye"
3505+
disabled={false}
3506+
id="root"
3507+
name="root"
3508+
onBlur={[Function]}
3509+
onChange={[Function]}
3510+
onCompositionEnd={[Function]}
3511+
onCompositionStart={[Function]}
3512+
onFocus={[Function]}
3513+
onKeyDown={[Function]}
3514+
placeholder=""
3515+
type="text"
3516+
value=""
3517+
/>
3518+
<span
3519+
className="ant-input-suffix"
3520+
/>
3521+
</span>
35763522
</div>
35773523
</div>
35783524
</div>
@@ -3645,7 +3591,7 @@ exports[`single fields string field format email 1`] = `
36453591
onFocus={[Function]}
36463592
onKeyDown={[Function]}
36473593
placeholder=""
3648-
type="email"
3594+
type="text"
36493595
value=""
36503596
/>
36513597
<span
@@ -3724,7 +3670,7 @@ exports[`single fields string field format uri 1`] = `
37243670
onFocus={[Function]}
37253671
onKeyDown={[Function]}
37263672
placeholder=""
3727-
type="url"
3673+
type="text"
37283674
value=""
37293675
/>
37303676
<span

packages/bootstrap-4/src/SelectWidget/SelectWidget.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export default function SelectWidget<
1515
S extends StrictRJSFSchema = RJSFSchema,
1616
F extends FormContextType = any
1717
>({
18-
schema,
1918
id,
2019
options,
2120
required,
@@ -27,7 +26,6 @@ export default function SelectWidget<
2726
onChange,
2827
onBlur,
2928
onFocus,
30-
placeholder,
3129
rawErrors = [],
3230
}: WidgetProps<T, S, F>) {
3331
const { enumOptions, enumDisabled, emptyValue: optEmptyValue } = options;
@@ -78,7 +76,6 @@ export default function SelectWidget<
7876
}}
7977
aria-describedby={ariaDescribedByIds<T>(id)}
8078
>
81-
{!multiple && schema.default === undefined && <option value=''>{placeholder}</option>}
8279
{(enumOptions as any).map(({ value, label }: any, i: number) => {
8380
const disabled: any = Array.isArray(enumDisabled) && (enumDisabled as any).indexOf(value) != -1;
8481
return (

0 commit comments

Comments
 (0)