ontario-back-to-top
Use a Back to Top button to help users quickly navigate to the top of a long page.
Usage guidance
Please refer to the Ontario Design System for current documentation guidance.
Configuration
Once the component package has been installed (see Ontario Design System Component Library for installation instructions), the Back to Top component can be added directly into the project's code, and can be customized by updating the properties outlined here. Please see the examples below for how to configure the component.
Examples
By default, the Back to Top button will have its language set to English ('en'). However, a property can be passed to set the language to French by default. For example:
- HTML
- React
- Angular
<ontario-back-to-top language="fr"> </ontario-back-to-top>
<OntarioBackToTop language="fr"> </OntarioBackToTop>
<ontario-back-to-top [language]="'fr'"> </ontario-back-to-top>
Otherwise, a default Back to Top button can be used as follows:
- HTML
- React
- Angular
<ontario-back-to-top> </ontario-back-to-top>
<OntarioBackToTop> </OntarioBackToTop>
<ontario-back-to-top> </ontario-back-to-top>
Technical Note: SSR (Server-Side Rendering) Considerations
The Ontario Back to Top component supports server-side rendering, with a few considerations:
- Scroll behaviour and visibility toggling: These rely on window and scroll position, which are only available in the browser. These features activate after hydration.
- Language prop: Pass
languageexplicitly during SSR. - Hydrated-only language events: Language change events only fire after hydration.
Overview
Ontario Back to Top helps users quickly return to the top of long pages.
For component guidance, see:
- https://designsystem.ontario.ca/components/detail/back-to-top.html
- https://designsystem.ontario.ca/developer-docs/components/ontario-back-to-top/
Properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
language | language | The 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 prop is passed, it will default to English. | "en" | "fr" | undefined | undefined |
Built with StencilJS