Skip to content

Extras

TextRotator

Bit.BlazorUI.ExtrasRotatingTextWordRotatorTextLoop

BitTextRotator cycles through a list of words or phrases in one place, moving each one out as the next one comes in. It always takes the width of its widest item, so the text around it never jumps; screen readers get every item as one stable text instead of a stream of changes; and under reduced motion it shows its first item, still.

Notes

To use this component, you need to install the Bit.BlazorUI.Extras(opens in a new tab) nuget package, as described in the Optional steps of the Getting started page.

BitTextRotator honors the reduced motion preference (prefers-reduced-motion) and shows its first item only. If the items do not rotate, turn off reduced motion or use the ForceAnimation toggle at the top of this page. The rotation starts once the page is interactive; prerendered or statically rendered, the first item is shown.

Usage

Every example is live. Open its code to see exactly what produced the component running underneath.

Basic

Give it the Items to rotate through: one comes in every three seconds as the one before it goes out. It is as wide as its widest item, so the sentence around it stays where it is. ForceAnimation keeps it rotating under reduced motion - reserve it for motion that carries a meaning.

Build apps for the web, mobile, desktop with one codebase.

Ship them as a PWA, Android, iOS, Windows, macOS apps, even with reduced motion.

Interval

Interval is the time each item is shown for, in ms (3000 by default). Keep it long enough for the item to be read.

A quick, brisk, rapid rotation of a second and a half.

A calm, steady, relaxed rotation of five seconds.

Element

Renders a span by default, which fits inside a sentence, a heading or a button. Element picks another tag. The font is inherited, so inside a BitText the rotator takes the typography of the theme.

Fast., Accessible., Themeable.

Made for developers, designers, teams

Transition

The move is drawn by the stylesheet: --bit-TextRotator-duration, --bit-TextRotator-easing and --bit-TextRotator-distance restyle it. A negative distance brings the items in from above, a distance of 0 cross-fades them in place.

Items that come in from above, the top, overhead

Items that cross-fade, dissolve, blend in place

Items that snap, spring, jump into place

Paused

Paused holds the item that is shown, and the rotation carries on from it once it is turned off again. Offering a way to pause is what lets a reader stop text that keeps changing (WCAG 2.2.2). A disabled rotator holds still too, dimmed.

Pause me on this word, that word, any word

A disabled rotator: held, still

Command line

Several rotators side by side, each at a pace of its own. Each one keeps the width of its widest item, so the line never shifts as they turn.

bit new MyApp --database sqlite, sqlserver, postgresql --api integrated, standalone --module admin, sales

Cascading parameters

BitParams with a BitTextRotatorParams sets the defaults of every rotator inside it, and a parameter of the rotator itself still wins. A cascaded Paused is one "pause animations" switch for a whole region.

Fast at one, two, three

Fast at red, green, blue

Slow at its own, Interval

Style & Class

Style and Class style the root, Styles and Classes each item and the item that is shown. The public --bit-TextRotator-* variables inherit, so setting them on :root, a container or a class restyles every rotator below it.

Styled, Bold, Big
Classy, Italic, Large
Primary, colored, items

Restyled by, the variables of, its container

RTL

The items sit at the start of the reading direction, whether it comes from Dir or from a dir attribute around the rotator.

ساخت برنامه برای وب, موبایل, دسکتاپ با یک کد

CSS variables

The public custom properties this component reads off its root, for what no parameter covers.

Every variable is read with a fallback and never declared by the component, so it inherits like any other custom property: set one on :root (or in a [bit-theme] block) to restyle every instance, on any ancestor to restyle the ones inside it, or on the Style of one instance to restyle it - and any instance nested inside it, which inherits the value too; a parameter changes one alone, as does the real CSS property on the instance's Style / Styles when that property does not inherit (opacity: 1 keeps one disabled instance undimmed without undimming a disabled one inside it), while an inherited one such as color or font-family also reaches the nested instances that do not set it themselves. Leave a variable unset and the component falls back to the theme token beside it.

BitTextRotator CSS variables

Name Default value Description
--bit-TextRotator-duration var(--bit-mot-duration-long) Length of the entrance of an item, and of the exit played beside it. It collapses under reduced motion along with the motion tokens.
--bit-TextRotator-easing var(--bit-mot-easing) Curve of the entrance and the exit.
--bit-TextRotator-distance 0.5em How far an item travels: it comes in from below and goes out above, the other way round with a negative distance, and cross-fades in place with 0.
--bit-TextRotator-disabled-opacity var(--bit-opa-dis) Opacity of a rotator whose Disabled is true.

API

Every parameter, public member, sub-class and enum this component exposes.

BitTextRotator parameters

Name Type Default value Description
Classes BitTextRotatorClassStyles? null Custom CSS classes for the different parts of the text rotator.
Element string? null The custom html element used for the root node. The default is "span", which fits inside a sentence, a heading or a button; a value that is not a name a tag can have falls back to it. A void element (such as "br" or "img") holds no content, so no item is rendered into one.
Interval double 3000 The time each item is shown for before the next one comes in, in ms, counted from the moment it starts to come in. A value that is not a positive number falls back to the default.
Items IEnumerable<string>? null The words or phrases to rotate through, in order. The first one is shown before the rotation starts, while prerendering and under reduced motion; the rotation starts over from it whenever the items change.
Paused bool false Holds the rotation on the item that is shown. It carries on from that item, after a whole Interval, once this is turned off again. A disabled rotator does not rotate either.
Styles BitTextRotatorClassStyles? null Custom CSS styles for the different parts of the text rotator.

BitComponentBase parameters

Name Type Default value Description
AriaLabel string? null Gets or sets the accessible label for the component, used by assistive technologies.
Class string? null Gets or sets the CSS class name(s) to apply to the rendered element.
Dir BitDir? null Gets or sets the text directionality for the component's content.
Disabled bool false Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction.
ForceAnimation bool false Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested.
HtmlAttributes Dictionary<string, object> new Dictionary<string, object>() Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name.
Id string? null Gets or sets the unique identifier for the component's root element.
Style string? null Gets or sets the CSS style string to apply to the rendered element.
TabIndex string? null Gets or sets the tab order index for the component when navigating with the keyboard.
Visibility BitVisibility BitVisibility.Visible Gets or sets the visibility state (visible, hidden, or collapsed) of the component.

BitComponentBase public members

Name Type Default value Description
UniqueId Guid Guid.NewGuid() Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed.
RootElement ElementReference Gets the reference to the root HTML element associated with this component.

BitTextRotatorClassStyles properties

Name Type Default value Description
Root string? null Custom CSS classes/styles for the root element of the BitTextRotator.
Item string? null Custom CSS classes/styles for each item of the BitTextRotator.
CurrentItem string? null Custom CSS classes/styles for the item of the BitTextRotator that is shown.

BitVisibility enum

Name Value Description
Visible 0 The content of the component is visible.
Hidden 1 The content of the component is hidden, but the space it takes on the page remains (visibility:hidden).
Collapsed 2 The component is hidden (display:none).

BitDir enum

Name Value Description
Ltr 0 Ltr (left to right) is to be used for languages that are written from the left to the right (like English).
Rtl 1 Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic).
Auto 2 Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element.

Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.