This is a preview of unreleased docs from main. View the published docs
Skip to main content

EmailForm

<allegro-email-form> is a web component that renders an email subscription form. On success it transitions to a confirmation state. Both states are fully customizable via attributes, slots, CSS variables, and shadow parts.

Usage​

<allegro-email-form></allegro-email-form>

With custom attributes:

<allegro-email-form
form-label-text="Enter your email address"
show-form-label="false"
placeholder-text="Your email address"
submit-text="Subscribe"
show-disclaimer="true"
disclaimer-text="We'll never share your email."
confirmation-heading="You're in!"
confirmation-text="Thanks for subscribing."
continue-text="Continue"
></allegro-email-form>

Attributes​

AttributeTypeDefaultDescription
show-form-labelbooleantrueWhether to show the email field's label. When false, the label is still rendered for screen readers but visually hidden. If placeholder-text is empty, the label text is used as the placeholder so the field still has visible text.
form-label-texttextEmail AddressLabel text for the email input field.
placeholder-texttextEnter your emailPlaceholder text for the email input field.
submit-texttextSubmitLabel for the submit button.
show-disclaimerbooleanfalseWhether to show the disclaimer paragraph below the form.
disclaimer-texttext(empty)HTML for the disclaimer paragraph. Links and inline formatting are kept; other markup is stripped.
confirmation-headingtextThank you!Heading shown in the confirmation state.
confirmation-texttextThanks for providing your email.Body text shown in the confirmation state.
continue-texttextContinueLabel for the continue button in the confirmation state.
user-attributestext(empty)JSON object of user attribute values stored against the reader on submit, e.g. "{'wants-newsletter': true}".
tracking-datatext(empty)JSON object of custom data merged into every tracked event, e.g. "{'campaign': 'footer'}".

Storing user attributes​

user-attributes sets user attribute values on the reader when they submit their email, keyed by attribute slug. A value is only stored when the reader doesn't already have one for that attribute, so existing values are never overwritten. Every slug must be an attribute readers can edit; if one isn't, or a value fails the attribute's rules, the form shows the error and nothing is saved.

<allegro-email-form
user-attributes="{'signup-source': 'footer', 'wants-newsletter': true}"
></allegro-email-form>

States​

StateTriggerDescription
emailInitial renderThe default state showing the email input form.
confirmationSuccessful form submissionShown after the email is successfully submitted.

Slots​

SlotAppears inDescription
headeremailRendered above the email input. Use for a title or description. Hidden once the form transitions to the confirmation state.
after-formemailRendered below the email input and above the disclaimer. Use for supplementary inputs such as newsletter opt-in checkboxes.
footeremailRendered below the disclaimer. Use for supplementary links. Hidden once the form transitions to the confirmation state.
successconfirmationReplaces the default confirmation state UI. When present, the default content is not rendered.
confirmationconfirmationSame as success, kept for existing pages. If both are present, success is used.
<allegro-email-form submit-text="Subscribe">
<div slot="header">
<h2>Get the morning newsletter</h2>
</div>
<label slot="after-form">
<input type="checkbox" name="wants-weekly" value="yes" />
Also send me the weekly roundup
</label>
<p slot="footer"><a href="/privacy">Privacy policy</a></p>
<div slot="success">
<h2>You're on the list</h2>
<p>Check your inbox.</p>
</div>
</allegro-email-form>

Submitting slotted inputs​

Named <input>, <select>, and <textarea> elements inside the header, after-form, and footer slots are sent with the email as request data, keyed by name. A checkbox sends its value when checked (or true when it has no value) and false when unchecked. Inputs without a name are ignored. Slotted values are merged over any request data the form already sends, so a slotted input wins when the names match.

Slotted inputs are part of your page, not the component, so give each one its own label. The component does not validate them before submitting.

When the confirmation slot has a heading, focus moves to it after a successful submit; otherwise its text is announced to screen readers.

Shadow Parts​

For styling beyond what the CSS variables make available, elements can be targeted directly with the CSS ::part() selector.

allegro-email-form::part(email-field-input) {
margin-bottom: 2rem;
}
PartAppears inDescription
email-formemailThe email input + submit button <form>.
email-fieldemailWrapper around the email label and input.
email-field-labelemailThe email input's <label> element.
email-field-inputemailThe email <input> element.
email-form-submitemailThe submit button.
disclaimeremailThe disclaimer paragraph.
confirmationconfirmationWrapper around the confirmation elements.
confirmation-iconconfirmationThe confirmation icon.
confirmation-headingconfirmationThe confirmation heading.
confirmation-bodyconfirmationThe confirmation body text.
confirmation-continueconfirmationThe continue button.

Events​

Dispatched​

EventBubblesDetailDescription
allegro:email-form:successyes{ email: string }Fired when the form is successfully submitted.
allegro:email-form:erroryes{ email: string, error: string }Fired when there is an error during form submission.

Tracked Events​

The component records the following events via the Allegro SDK.

EventWhenData
email_form_submittedFired after a successful form submission.(none)

CSS Variables​

All visual properties are exposed as CSS custom properties so the component can be themed from the host page without piercing the shadow DOM.

allegro-email-form {
--emailForm--button--background: #1a1a1a;
--emailForm--input--border: 1px solid #ccc;
}

General​

VariableDefaultDescription
--emailForm--font-familysystem-ui, sans-serifFont family for the component.

Form Layout​

VariableDefaultDescription
--emailForm--form--gap0.8remGap between the field and submit button.
--emailForm--label--margin0 0 0.4remMargin around the email field's label.

Input​

VariableDefaultDescription
--emailForm--input--background#fffInput background color.
--emailForm--input--border1px solid #8c8c8cInput border.
--emailForm--input--border-radius0.375remInput border radius.
--emailForm--input--font-size1remInput font size.
--emailForm--input--padding0.75rem 1remInput padding.
--emailForm--input--focus-border-color#555Border color on input focus.

Submit Button​

VariableDefaultDescription
--emailForm--button--background#000Button background color.
--emailForm--button--color#fffButton text color.
--emailForm--button--border-radius0.375remButton border radius.
--emailForm--button--font-size0.875remButton font size.
--emailForm--button--font-weight700Button font weight.
--emailForm--button--padding0.75rem 1.25remButton padding.
--emailForm--button--text-transformuppercaseButton text transform.

Error Message​

VariableDefaultDescription
--emailForm--error--background#fef2f2Error background color.
--emailForm--error--border1px solid #fecacaError border.
--emailForm--error--accent-color#dc2626Error left accent border color.
--emailForm--error--border-radius0.375remError border radius.
--emailForm--error--color#b91c1cError text color.
--emailForm--error--icon-colorcurrentColorError icon color.
--emailForm--error--padding0.625rem 0.875remError padding.

Confirmation State​

VariableDefaultDescription
--emailForm--state-icon--background#111Confirmation icon circle background.
--emailForm--state-heading--color#111Confirmation heading color.
--emailForm--state-heading--font-size1.25remConfirmation heading font size.
--emailForm--state-heading--font-weight700Confirmation heading font weight.
--emailForm--state-body--color#555Confirmation body text color.
--emailForm--state-body--font-size0.9375remConfirmation body font size.

Disclaimer​

VariableDefaultDescription
--emailForm--disclaimer--color#555Disclaimer text color.
--emailForm--disclaimer--font-size0.8125remDisclaimer text size.
--emailForm--disclaimer--link--colorinheritColor of links inside the disclaimer HTML. Links are underlined.

Example: Dark Background​

allegro-email-form {
--emailForm--input--background: #1a1a1a;
--emailForm--input--border: 1px solid #444;
--emailForm--input--focus-border-color: #888;
--emailForm--button--background: #fff;
--emailForm--button--color: #000;
--emailForm--state-icon--background: #fff;
--emailForm--state-heading--color: #fff;
--emailForm--state-body--color: #aaa;
}