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

fix(VerticalLayout): remove div element causing flex issues #101

Merged
merged 3 commits into from
Oct 3, 2024
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
7 changes: 6 additions & 1 deletion src/layouts/HorizontalLayout.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { test } from "vitest"
import { test, expect } from "vitest"
import { screen } from "@testing-library/react"
import { render } from "../common/test-render"

import {
numericMagnitudeSchema,
numericHorizontalUISchema,
} from "../testSchemas/numericSchema"
import { HORIZONTAL_LAYOUT_FORM_TEST_ID } from "./HorizontalLayout"

test("Horizontal layout renders", async () => {
render({
schema: numericMagnitudeSchema,
uischema: numericHorizontalUISchema,
})
await screen.findByRole("spinbutton")
// since we are wrapped in a form no wrapper element should be introduced
expect(
screen.queryByTestId(HORIZONTAL_LAYOUT_FORM_TEST_ID),
).not.toBeInTheDocument()
})
8 changes: 7 additions & 1 deletion src/layouts/HorizontalLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { HorizontalLayoutUISchema } from "../ui-schema"
import { Form, Row } from "antd"
import { withJsonFormsLayoutProps } from "@jsonforms/react"

export const HORIZONTAL_LAYOUT_FORM_TEST_ID = "horizontal-layout-form"

export function HorizontalLayout({
uischema,
schema,
Expand All @@ -25,7 +27,11 @@ export function HorizontalLayout({
}
const form = Form.useFormInstance()
return (
<Form component={form ? false : "form"} form={form}>
<Form
data-testid={HORIZONTAL_LAYOUT_FORM_TEST_ID}
component={form ? false : "form"}
form={form}
>
{!isEmpty(groupLayout.label) && groupLayout.label}
<Row justify="space-between" gutter={12} align="middle">
<AntDLayout
Expand Down
8 changes: 7 additions & 1 deletion src/layouts/VerticalLayout.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { test } from "vitest"
import { test, expect } from "vitest"
import { screen } from "@testing-library/react"
import { render } from "../common/test-render"

import {
numericMagnitudeSchema,
numericVerticalUISchema,
} from "../testSchemas/numericSchema"
import { VERTICAL_LAYOUT_FORM_TEST_ID } from "./VerticalLayout"

test("Vertical layout renders", async () => {
render({
schema: numericMagnitudeSchema,
uischema: numericVerticalUISchema,
})
await screen.findByRole("spinbutton")

// since we are wrapped in a form no wrapper element should be introduced
expect(
screen.queryByTestId(VERTICAL_LAYOUT_FORM_TEST_ID),
).not.toBeInTheDocument()
})
28 changes: 12 additions & 16 deletions src/layouts/VerticalLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { LayoutProps, GroupLayout } from "@jsonforms/core"
import { LayoutProps } from "@jsonforms/core"
import { AntDLayout, AntDLayoutProps } from "./LayoutRenderer"
import { Form, FormInstance, FormProps } from "antd"
import { Form } from "antd"
import { VerticalLayoutUISchema } from "../ui-schema"
import { withJsonFormsLayoutProps } from "@jsonforms/react"

export const VERTICAL_LAYOUT_FORM_TEST_ID = "vertical-layout-form"

export function VerticalLayout({
uischema,
schema,
Expand All @@ -13,31 +15,25 @@ export function VerticalLayout({
renderers,
cells,
}: LayoutProps) {
const verticalLayout = uischema as VerticalLayoutUISchema<unknown>
const groupLayout = uischema as GroupLayout
const { elements } = uischema as VerticalLayoutUISchema<unknown>
const childProps: AntDLayoutProps = {
DrewHoo marked this conversation as resolved.
Show resolved Hide resolved
elements: verticalLayout.elements,
elements,
schema,
path,
enabled,
visible,
}
const form = Form.useFormInstance()
return (
<Form {...getFormLayoutOptions(form)} form={form}>
{!groupLayout.label && (
<div>{groupLayout.label}</div> // this was SubtitleSemiBold
DrewHoo marked this conversation as resolved.
Show resolved Hide resolved
)}
<Form
data-testid={VERTICAL_LAYOUT_FORM_TEST_ID}
component={form ? false : "form"}
scrollToFirstError
form={form}
>
<AntDLayout {...childProps} renderers={renderers} cells={cells} />
</Form>
)
}

function getFormLayoutOptions(form: FormInstance): Partial<FormProps> {
return {
scrollToFirstError: true,
component: form ? "div" : "form",
}
}

export const VerticalLayoutRenderer = withJsonFormsLayoutProps(VerticalLayout)
Loading