Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take into account implicitly defined types when rendering labels for fields #2502

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/core/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,17 @@ export function getUiOptions(uiSchema) {
export function getDisplayLabel(schema, uiSchema, rootSchema) {
const uiOptions = getUiOptions(uiSchema);
let { label: displayLabel = true } = uiOptions;
if (schema.type === "array") {
const schemaType = getSchemaType(schema);

if (schemaType === "array") {
displayLabel =
isMultiSelect(schema, rootSchema) ||
isFilesArray(schema, uiSchema, rootSchema);
}
if (schema.type === "object") {
if (schemaType === "object") {
displayLabel = false;
}
if (schema.type === "boolean" && !uiSchema["ui:widget"]) {
if (schemaType === "boolean" && !uiSchema["ui:widget"]) {
displayLabel = false;
}
if (uiSchema["ui:field"]) {
Expand Down
11 changes: 11 additions & 0 deletions packages/core/test/SchemaField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ describe("SchemaField", () => {
const { node } = createFormComponent({ schema, uiSchema });
expect(node.querySelectorAll("label")).to.have.length.of(0);
});

it("should render label even when type object is missing", () => {
const schema = {
title: "test",
properties: {
foo: { type: "string" },
},
};
const { node } = createFormComponent({ schema });
expect(node.querySelectorAll("label")).to.have.length.of(1);
});
});

describe("description support", () => {
Expand Down