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 }.
Import
Section titled “Import”<script> import LoginForm from "@invisible-ui/svelte/LoginForm.svelte";</script><script setup> import { LoginForm } from "@invisible-ui/vue";</script>import { LoginForm } from "@invisible-ui/react";<script type="module"> import "@invisible-ui/elements/define";</script>
<ds-login-form></ds-login-form>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>| Prop | Type | Default | Description |
|---|---|---|---|
heading | string | undefined | undefined | |
subheading | string | undefined | undefined | |
submitLabel | string | undefined | undefined | Submit button label. Defaults to the i18n catalog's "Sign in". |
forgotHref | string | "#" | |
forgotLabel | string | undefined | undefined | Forgot-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) | undefined | undefined | |
onProvider | ((id: string) => void) | undefined | undefined | |
logo | Snippet | undefined | undefined | A logo shown on top of the card. |
providerIcon | Snippet<[{ provider: string }]> | undefined | undefined | The icon of a social provider button, given the provider id. |
| Prop | Type | Default | Description |
|---|---|---|---|
heading | string | undefined | |
subheading | string | undefined | |
submitLabel | string | undefined | Submit button label. Defaults to the catalog's "Sign in". |
forgotHref | string | "#" | |
forgotLabel | string | undefined | Forgot-password link text. Defaults to the catalog's "Forgot password?". |
providers | LoginFormProvider[] | () => [] | Social providers rendered as white buttons above the fields. |
onSubmit | (value: LoginFormValue) => void | undefined | |
onProvider | (id: string) => void | undefined |
Slots: logo, providerIcon.
| Prop | Type | Default | Description |
|---|---|---|---|
heading | string | — | The card's heading. Defaults to the catalog's "Sign in". |
subheading | string | — | |
submitLabel | string | — | Submit button label. Defaults to the catalog's "Sign in". |
forgotHref | string | "#" | Where the forgot-password link goes. An empty string leaves the link out. |
forgotLabel | string | — | Forgot-password link text. Defaults to the catalog's "Forgot password?". |
providers | LoginFormProvider[] | EMPTY | Social providers rendered as buttons above the fields. |
onSubmit | (value: LoginFormValue) => void | — | Called with the typed credentials when the form is submitted. |
onProvider | (id: string) => void | — | Called with the provider id when a provider button is pressed. |
logo | ReactNode | — | A logo shown on top of the card. |
renderProviderIcon | (provider: string) => ReactNode | — | The icon of a provider button, given the provider id. |
| Attribute | Reactive | Description |
|---|---|---|
heading | yes | |
subheading | yes | |
submit-label | yes | |
forgot-href | yes | an empty value hides the link |
forgot-label | yes | |
action | yes | |
method | yes |
Reactive attributes re-render the element when they change after the first render.
Properties: providers ({ id, label }[]).
Emits: bubbling, cancelable submit CustomEvent with detail.email and detail.password; bubbling provider CustomEvent with detail.id when a provider button is pressed.
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.
Example
Section titled “Example”<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-*.