Просмотр исходного кода

Fix enum dropdown showing a selection for unset fields

Avoid matching an unset field value to an enum item with an undefined label.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu 1 неделя назад
Родитель
Сommit
0bb1780d44
1 измененных файлов с 9 добавлено и 6 удалено
  1. 9 6
      src/components/ui/FieldInput/FieldInput.tsx

+ 9 - 6
src/components/ui/FieldInput/FieldInput.tsx

@@ -320,12 +320,15 @@ class FieldInput extends React.Component<Props> {
       ];
     }
 
-    const selectedItem = items.find(
-      i =>
-        !isEnumSeparator(i) &&
-        // The default value might be set to an item's label instead of its value
-        (i.value === this.props.value || i.label === this.props.value),
-    );
+    const selectedItem =
+      this.props.value === undefined
+        ? undefined
+        : items.find(
+            i =>
+              !isEnumSeparator(i) &&
+              // The default value might be set to an item's label instead of its value
+              (i.value === this.props.value || i.label === this.props.value),
+          );
     const commonProps = {
       width: this.props.width,
       required: this.props.layout === "page" ? false : this.props.required,