diff --git a/src/components/fields/SchemaField.js b/src/components/fields/SchemaField.js index 4c9b109cb7..0b3a0aeac0 100644 --- a/src/components/fields/SchemaField.js +++ b/src/components/fields/SchemaField.js @@ -8,6 +8,7 @@ import { getUiOptions, isFilesArray, deepEquals, + getSchemaType, } from "../../utils"; import UnsupportedField from "./UnsupportedField"; @@ -29,7 +30,8 @@ function getFieldComponent(schema, uiSchema, idSchema, fields) { if (typeof field === "string" && field in fields) { return fields[field]; } - const componentName = COMPONENT_TYPES[schema.type]; + + const componentName = COMPONENT_TYPES[getSchemaType(schema)]; return componentName in fields ? fields[componentName] : () => { diff --git a/src/utils.js b/src/utils.js index d57ab7761b..ec00332847 100644 --- a/src/utils.js +++ b/src/utils.js @@ -62,8 +62,16 @@ export function getDefaultRegistry() { }; } +export function getSchemaType(schema) { + let { type } = schema; + if (!type && schema.enum) { + type = "string"; + } + return type; +} + export function getWidget(schema, widget, registeredWidgets = {}) { - const { type } = schema; + const type = getSchemaType(schema); function mergeOptions(Widget) { // cache return value as property of widget for proper react reconciliation diff --git a/test/StringField_test.js b/test/StringField_test.js index e25af5b4bc..ef65f72daf 100644 --- a/test/StringField_test.js +++ b/test/StringField_test.js @@ -191,6 +191,16 @@ describe("StringField", () => { expect(node.querySelectorAll(".field select")).to.have.length.of(1); }); + it("should render a string field for an enum without a type", () => { + const { node } = createFormComponent({ + schema: { + enum: ["foo", "bar"], + }, + }); + + expect(node.querySelectorAll(".field select")).to.have.length.of(1); + }); + it("should render a string field with a label", () => { const { node } = createFormComponent({ schema: {