Skip to content

Commit cd8dd19

Browse files
committed
fix(react): Add descriptiont to SMS MFA verification
1 parent 13740f5 commit cd8dd19

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

packages/react/src/auth/forms/mfa/sms-multi-factor-enrollment-form.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ describe("<MultiFactorEnrollmentVerifyPhoneNumberForm />", () => {
217217
verificationCode: "verificationCode",
218218
verifyCode: "verifyCode",
219219
},
220+
prompts: {
221+
mfaSmsEnrollmentVerificationPrompt: "mfaSmsEnrollmentVerificationPrompt",
222+
},
220223
}),
221224
});
222225

@@ -238,6 +241,10 @@ describe("<MultiFactorEnrollmentVerifyPhoneNumberForm />", () => {
238241

239242
expect(screen.getByRole("textbox", { name: /verificationCode/i })).toBeInTheDocument();
240243

244+
const description = container.querySelector("[data-input-description]");
245+
expect(description).toBeInTheDocument();
246+
expect(description).toHaveTextContent("mfaSmsEnrollmentVerificationPrompt");
247+
241248
const verifyCodeButton = screen.getByRole("button", { name: "verifyCode" });
242249
expect(verifyCodeButton).toBeInTheDocument();
243250
expect(verifyCodeButton).toHaveAttribute("type", "submit");

packages/react/src/auth/forms/mfa/sms-multi-factor-enrollment-form.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,13 @@ export function MultiFactorEnrollmentVerifyPhoneNumberForm(props: MultiFactorEnr
193193
<form.AppForm>
194194
<fieldset>
195195
<form.AppField name="verificationCode">
196-
{(field) => <field.Input label={getTranslation(ui, "labels", "verificationCode")} type="text" />}
196+
{(field) => (
197+
<field.Input
198+
description={getTranslation(ui, "prompts", "mfaSmsEnrollmentVerificationPrompt")}
199+
label={getTranslation(ui, "labels", "verificationCode")}
200+
type="text"
201+
/>
202+
)}
197203
</form.AppField>
198204
</fieldset>
199205
<fieldset>

packages/react/src/components/form.test.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,47 @@ describe("form export", () => {
120120
expect(screen.getByTestId("test-action")).toHaveTextContent("Action");
121121
});
122122

123+
it("should render the Input description prop when provided", () => {
124+
const { result } = renderHook(() => {
125+
return form.useAppForm({
126+
defaultValues: { foo: "bar" },
127+
});
128+
});
129+
130+
const hook = result.current;
131+
132+
const { container } = render(
133+
<hook.AppForm>
134+
<hook.AppField name="foo">
135+
{(field) => <field.Input label="Foo" description="This is a description" />}
136+
</hook.AppField>
137+
</hook.AppForm>
138+
);
139+
140+
const description = container.querySelector("[data-input-description]");
141+
expect(description).toBeInTheDocument();
142+
expect(description).toHaveTextContent("This is a description");
143+
});
144+
145+
it("should not render the Input description when not provided", () => {
146+
const { result } = renderHook(() => {
147+
return form.useAppForm({
148+
defaultValues: { foo: "bar" },
149+
});
150+
});
151+
152+
const hook = result.current;
153+
154+
const { container } = render(
155+
<hook.AppForm>
156+
<hook.AppField name="foo">{(field) => <field.Input label="Foo" />}</hook.AppField>
157+
</hook.AppForm>
158+
);
159+
160+
const description = container.querySelector("[data-input-description]");
161+
expect(description).not.toBeInTheDocument();
162+
});
163+
123164
it("should render the Input metadata when available", async () => {
124165
const { result } = renderHook(() => {
125166
return form.useAppForm({

packages/react/src/components/form.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ function Input({
2424
before,
2525
label,
2626
action,
27+
description,
2728
...props
28-
}: PropsWithChildren<ComponentProps<"input"> & { label: string; before?: ReactNode; action?: ReactNode }>) {
29+
}: PropsWithChildren<
30+
ComponentProps<"input"> & { label: string; before?: ReactNode; action?: ReactNode; description?: ReactNode }
31+
>) {
2932
const field = useFieldContext<string>();
3033

3134
return (
@@ -34,6 +37,7 @@ function Input({
3437
<div>{label}</div>
3538
{action ? <div>{action}</div> : null}
3639
</div>
40+
{description ? <div data-input-description>{description}</div> : null}
3741
<div data-input-group>
3842
{before}
3943
<input

packages/styles/src/base.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@
120120
@apply grow;
121121
}
122122

123+
:where(.fui-form fieldset label div[data-input-description]) {
124+
@apply text-xs text-text-muted;
125+
}
126+
123127
:where(.fui-form .fui-form__action) {
124128
@apply px-1 hover:underline text-xs text-text-muted;
125129
}

0 commit comments

Comments
 (0)