Skip to main content
Version: v10.0.0-beta.1

ontario-checkbox

Technical Note: SSR (Server-Side Rendering) Considerations​

The Ontario Checkbox component supports server-side rendering, with a few considerations:

  • Language prop: Language change events only fire in the browser after hydration. To ensure the correct language is rendered during SSR, pass the desired language explicitly as a prop.
  • Form participation: This component uses the Form-Associated Custom Elements API (@AttachInternals) to participate in native form submission. During SSR, it renders a single checkbox input that can support straightforward form submission when name and elementId are stable. Custom events become available after hydration. After hydration, a required, unchecked checkbox is marked invalid in its parent form, so native form submission is blocked until it is checked. Resetting the form (for example, with form.reset()) restores the checkbox to its initial checked state.
  • Automatic required-field validation is a hydrated-only behaviour: When required is set, an unchecked checkbox shows an error state (errorMessage and red styling) as soon as it hydrates on the client. During SSR, a required, unchecked checkbox will not yet show this error. If you need the error present in the initial server-rendered markup, pass the error-message prop explicitly instead. Use required-validation-message to customize the error text; if omitted, a translated default is used. The automatic error does not replace or clear an error-message you pass (for example, a server-side error).
  • Framework guidance: For App Router setup details, follow the Next.js integration guide.

Overview​

Ontario Checkbox collects a single boolean selection, e.g. a terms and conditions acknowledgment.

This component intentionally does not expose a disabled prop.

For a set of related checkbox options, use ontario-checkboxes instead.

To support accessible and understandable form completion:

  • keep the checkbox and submission actions available
  • use validation and error messaging to guide corrections

For component guidance, see:

Disabled/read-only policy source:

Properties​

PropertyAttributeDescriptionTypeDefault
checkedcheckedWhether the checkbox is checked. This is mutable and is kept in sync with user interaction.boolean | undefinedfalse
customOnBlurcustom-on-blurUsed to add a custom function to the checkbox onBlur event.((event: Event) => void) | undefinedundefined
customOnChangecustom-on-changeUsed to add a custom function to the checkbox onChange event.((event: Event) => void) | undefinedundefined
customOnFocuscustom-on-focusUsed to add a custom function to the checkbox onFocus event.((event: Event) => void) | undefinedundefined
elementIdelement-idThe unique identifier of the checkbox. This is optional - if no ID is passed, one will be generated.string | undefinedundefined
errorMessageerror-messageSet this to display an error messagestring | undefinedundefined
hintExpanderhint-expanderUsed to include the ontario-hint-expander component for the checkbox. This is passed in as an object with key-value pairs. This is optional.HintExpander | string | undefinedundefined
hintTexthint-textUsed to include the ontario-hint-text component for the checkbox. This is optional.Hint | string | undefinedundefined
labellabelThe text to display as the checkbox label.Caption | stringundefined
languagelanguageThe language of the component. This is used for translations, and is by default set through event listeners checking for a language property from the header. If no language is passed, it will default to English."en" | "fr" | undefinedundefined
namenameThe name for the checkbox. The name value is used to reference form data after a form is submitted.stringundefined
requiredrequiredThis is used to determine whether the checkbox is required or not. This prop also gets passed to the InputCaption utility to display either an optional or required flag in the label. If no prop is set, it will default to false (optional). When required and the checkbox is unchecked, an error state is displayed automatically. It clears once the checkbox is checked. The component is also marked as invalid in its parent form (valueMissing), so native form validation blocks submission until it is checked.boolean | undefinedfalse
requiredValidationMessagerequired-validation-messageThe message to display when the checkbox is required and left unchecked. If not provided, a translated default message is used instead.string | undefinedundefined
valuevalueThe value submitted with the form data when the checkbox is checked.string | undefinedundefined

Events​

EventDescriptionType
checkboxOnBlurEmitted when a keyboard input event occurs when the checkbox has lost focus.CustomEvent<InputInteractionEvent & { focused: boolean; }>
checkboxOnChangeEmitted when a keyboard input or mouse event occurs when the checkbox has been changed.CustomEvent<InputInteractionEvent & { checked: boolean; }>
checkboxOnFocusEmitted when a keyboard input event occurs when the checkbox has gained focus.CustomEvent<InputInteractionEvent & { focused: boolean; }>
inputErrorOccurredEmitted when an error message is reported to the component.CustomEvent<{ errorMessage: string; }>

Dependencies​

Depends on​

Graph​


Built with StencilJS