File tree Expand file tree Collapse file tree 2 files changed +19
-11
lines changed
components/dataform/stories Expand file tree Collapse file tree 2 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ const fields = [
71
71
label : 'Date as options' ,
72
72
type : 'datetime' as const ,
73
73
elements : [
74
+ { value : '' , label : 'Select a date' } ,
74
75
{ value : '1970-02-23T12:00:00' , label : "Jane's birth date" } ,
75
76
{ value : '1950-02-23T12:00:00' , label : "John's birth date" } ,
76
77
] ,
Original file line number Diff line number Diff line change @@ -26,17 +26,24 @@ export default function Select< Item >( {
26
26
[ id , onChange ]
27
27
) ;
28
28
29
- const elements = [
30
- /*
31
- * Value can be undefined when:
32
- *
33
- * - the field is not required
34
- * - in bulk editing
35
- *
36
- */
37
- { label : __ ( 'Select item' ) , value : '' } ,
38
- ...( field ?. elements ?? [ ] ) ,
39
- ] ;
29
+ const fieldElements = field ?. elements ?? [ ] ;
30
+ const hasEmptyValue = fieldElements . some (
31
+ ( { value : elementValue } ) => elementValue === ''
32
+ ) ;
33
+
34
+ const elements = hasEmptyValue
35
+ ? fieldElements
36
+ : [
37
+ /*
38
+ * Value can be undefined when:
39
+ *
40
+ * - the field is not required
41
+ * - in bulk editing
42
+ *
43
+ */
44
+ { label : __ ( 'Select item' ) , value : '' } ,
45
+ ...fieldElements ,
46
+ ] ;
40
47
41
48
return (
42
49
< SelectControl
You can’t perform that action at this time.
0 commit comments