Skip to content

Login Form

A sign-in organism composed from the primitives: an optional logo, social-login buttons, the email + password fields, a “forgot password” link, and the submit button. It is a real <form> — onSubmit receives { email, password }.

<script>
import LoginForm from "@invisible-ui/svelte/LoginForm.svelte";
</script>

In Elements, the form reports a cancelable submit event. With action, it also submits natively to that URL:

<ds-login-form action="/session" method="post">
<img slot="logo" src="/logo.svg" alt="Acme" />
</ds-login-form>
<script type="module">
const login = document.querySelector("ds-login-form");
login.providers = [{ id: "google", label: "Google" }];
login.addEventListener("provider", (event) => signInWith(event.detail.id));
</script>
PropTypeDefaultDescription
headingstring | undefinedundefined
subheadingstring | undefinedundefined
submitLabelstring | undefinedundefinedSubmit button label. Defaults to the i18n catalog's "Sign in".
forgotHrefstring"#"
forgotLabelstring | undefinedundefinedForgot-password link text. Defaults to the i18n catalog's "Forgot password?".
providers{ id: string; label: string }[][]Social providers rendered as white buttons above the fields.
onSubmit((value: { email: string; password: string }) => void) | undefinedundefined
onProvider((id: string) => void) | undefinedundefined
logoSnippet | undefinedundefinedA logo shown on top of the card.
providerIconSnippet<[{ provider: string }]> | undefinedundefinedThe icon of a social provider button, given the provider id.

The fields name their purpose for autofill and assistive technology (WCAG 2.2 1.3.5): the email field uses autocomplete="username" and the password field autocomplete="current-password". Every text the form writes, including the labels, the placeholder, the divider and the provider buttons, comes from the message catalog.

Pass a logo via the logo slot and provider glyphs via provider-icon. In Svelte these are the logo and providerIcon snippets; providerIcon receives { provider }.

The forgot-password link href is rendered as given: pass only URLs you trust or have sanitized. See Security.

<LoginForm
providers={[{ id: "google", label: "Google" }]}
onSubmit={({ email, password }) => signIn(email, password)}
/>

In React, logo takes markup and renderProviderIcon receives the provider id. onSubmit reads the credentials from the form itself, so a form reset leaves nothing behind:

<LoginForm
logo={<img src="/logo.svg" alt="Acme" />}
providers={[{ id: "google", label: "Google" }]}
renderProviderIcon={(id) => <ProviderGlyph id={id} />}
onProvider={signInWith}
onSubmit={({ email, password }) => signIn(email, password)}
/>

Themeable via --ds-login-*.