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

feat: hide label on hidden input type #149

Merged
merged 3 commits into from
Sep 26, 2023
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
2 changes: 1 addition & 1 deletion src/react-components/input-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const InputField = ({
data-testid={dataTestid}
className={cn(className, gridStyle({ gap: 4 }))}
>
{title && (
{title && props.type !== "hidden" && (
<label
htmlFor={inputId}
className={typographyStyle({ size: "small", type: "regular" })}
Expand Down
28 changes: 28 additions & 0 deletions src/react-components/ory/helpers/node.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { test, expect } from "@playwright/experimental-ct-react"
import { Node } from "./node"

test("hidden input field shouldn't show label", async ({ mount }) => {
const component = await mount(
<Node
node={{
group: "default",
attributes: {
name: "name",
disabled: false,
type: "hidden",
node_type: "input",
label: {
type: "info",
text: "Hidden input",
id: 1234,
},
},
messages: [],
meta: {},
type: "input",
}}
/>,
)

await expect(component).toBeHidden()
})
31 changes: 26 additions & 5 deletions src/react-components/ory/sections/auth-code-section.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,33 @@ test("should render when ui nodes contain `code` group", async ({ mount }) => {
group: "code",
attributes: {
name: "resend",
node_type: "hidden",
type: "hidden",
node_type: "input",
type: "submit",
required: true,
disabled: false,
value: "code",
},
messages: [],
type: "input",
meta: {
label: {
id: 1070008,
text: "Resend Code",
type: "info",
},
},
},
{
group: "code",
attributes: {
name: "method",
node_type: "input",
type: "hidden",
disabled: false,
value: "code",
},
messages: [],
type: "input",
meta: {},
},
{
Expand All @@ -45,15 +64,14 @@ test("should render when ui nodes contain `code` group", async ({ mount }) => {
name: "method",
node_type: "input",
type: "submit",
required: true,
disabled: false,
value: "code",
},
messages: [],
type: "input",
meta: {
label: {
id: 1040006,
id: 1070005,
text: "Sign up with code",
type: "info",
},
Expand All @@ -63,7 +81,10 @@ test("should render when ui nodes contain `code` group", async ({ mount }) => {
/>,
)
await expect(container.locator("input[name=code]")).toBeVisible()
await expect(container.locator("input[name=resend]")).toBeHidden()
await expect(
container.locator('input[name=method][value="code"]'),
).toBeAttached()
await expect(container.locator("button[name=resend]")).toBeVisible()
await expect(container.locator("button[name=method]")).toBeVisible()
})

Expand Down
41 changes: 26 additions & 15 deletions src/react-components/ory/sections/auth-code-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,38 @@ export const AuthCodeSection = ({
nodes,
}: AuthCodeSectionProps): JSX.Element | null =>
hasCode(nodes) ? (
<div className={gridStyle({ gap: 32 })}>
<div className={gridStyle({ gap: 16 })}>
{/* default group is used here automatically for login */}
<>
{/* place this outisde of the grid so that hidden fields dont break the layout */}
<FilterFlowNodes
filter={{
nodes: nodes,
groups: "code",
withoutDefaultAttributes: true,
attributes: ["hidden"],
}}
/>
<div className={gridStyle({ gap: 32 })}>
<div className={gridStyle({ gap: 16 })}>
{/* default group is used here automatically for login */}
<FilterFlowNodes
filter={{
nodes: nodes,
groups: "code",
withoutDefaultAttributes: true,
excludeAttributes: ["hidden", "button", "submit"], // the form will take care of default (csrf) hidden fields
}}
/>
</div>
{/* include hidden here because we want to have resend support */}
{/* exclude default group because we dont want to map csrf twice */}
<FilterFlowNodes
filter={{
nodes: nodes,
groups: "code",
withoutDefaultAttributes: true,
excludeAttributes: ["hidden", "button", "submit"], // the form will take care of hidden fields
attributes: ["button", "submit"],
}}
/>
</div>
{/* include hidden here because we want to have resend support */}
{/* exclude default group because we dont want to map csrf twice */}
<FilterFlowNodes
filter={{
nodes: nodes,
groups: "code",
withoutDefaultAttributes: true,
attributes: ["button", "submit"],
}}
/>
</div>
</>
) : null