Notifications
Tag
Tag is the compact chip that stands for an attribute, a person or an asset. It takes a label, a second line under it, an icon or a picture at its head and a second glyph at its end, and comes in three variants, three sizes and three corner shapes across the whole color palette. Give it a dismiss handler and it grows a close button that answers the pointer, the keyboard and the Delete key, and that names the tag it removes; give it a click handler or a URL and it becomes a real button or a real anchor rather than an element that merely reacts to a click; bind its Selected value and it becomes a filter chip that reports its own state to assistive technologies. It wraps onto as many lines as its content needs, truncates to a single one or stretches to the width of whatever holds it, and it can be focused from code - which is what a list of dismissible tags needs once one of them is gone.
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
Variant
Shape
Icon
Image
Annie Lindqvist
Annie LindqvistSoftware engineer
Awaiting reviewSecondary text
Dismiss
Click
button: it enters the tab order, it is activated with Enter and
Space, it answers hover and press with a shade of its own color, and it wears a focus ring - none of which a click handler on a
plain element reproduces. Disabling the tag disables that button, so it can be reached by neither the pointer nor the keyboard.
A control needs a name, so a tag that carries no words of its own needs an AriaLabel as soon as it becomes one.
StopPropagation keeps the click inside the tag, for a tag that sits in something else that reacts to one - a row, a card,
a list item - where activating the tag should not also activate what holds it.
Link
rel="noopener", which keeps the opened page from
reaching back into this one. OnClick can be set alongside it, in which case the handler runs and the navigation still
happens. Download turns the tag into one that saves what it points at instead of navigating to it, taking its value as the
suggested file name. Disabling the tag drops the href and takes it out of the tab order. A Selected link reports itself
through aria-current, and AriaCurrent is what that says: leave it at True for the picked one of a set of
filters, and set it to Page for a tag standing for the page the reader is already on.
Selection
aria-pressed, so a screen reader announces it as
pressed or not pressed rather than leaving the state to color alone. A selected tag deepens its paint and shows a checkmark in
front of its content; SelectedIconName changes that glyph and HideSelectedIcon removes it.
Set Selected without either callback and it is a static "this one is picked" state the app drives on its own, and one the
tag is not allowed to change; DefaultSelected is the other half of that - a tag that keeps its own selection, with no field
in the app behind it. OnChanging runs before every change and can call it off, which is what a filter that has to be
confirmed - or saved - before it applies needs. A selected tag that is a link reports itself
as aria-current instead, since aria-pressed belongs to a button and would say nothing on an anchor.
Template
PrefixTemplate and SuffixTemplate are the other half of that: markup added beside the label rather than in place of it, at the very head and the very end of the tag. They are what the leading and trailing slots need when a glyph is not enough - an avatar with initials, a colored dot, a count - and they leave the two lines of the label to Text and SecondaryText. All three live inside whatever the tag became, so they are part of the same target the pointer and the keyboard activate; that is also why a control of your own does not belong in them - a control inside a button is one no assistive technology can reach - and why nothing in them names the tag, which is still the job of the label or the AriaLabel.
Truncation
Full width
Full width and dismissible
Focus
Accessibility
aria-pressed - or, when it is a link, through the
aria-current that AriaCurrent spells out - rather than through color alone. A tag that is neither a control nor
dismissible has nothing inside it to focus, so the TabIndex of that one lands on the tag itself and is what puts a plain tag
in the tab sequence.
The tag also keeps its rule, its selection and its disabled state in a forced-colors mode, where every color it paints is discarded.
Color
Primary Primary Primary
Secondary Secondary Secondary
Tertiary Tertiary Tertiary
Info Info Info
Success Success Success
Warning Warning Warning
SevereWarning SevereWarning SevereWarning
Error Error Error
SecondaryBackground SecondaryBackground SecondaryBackground
TertiaryBackground TertiaryBackground TertiaryBackground
PrimaryForeground PrimaryForeground PrimaryForeground
SecondaryForeground SecondaryForeground SecondaryForeground
TertiaryForeground TertiaryForeground TertiaryForeground
PrimaryBorder PrimaryBorder PrimaryBorder
SecondaryBorder SecondaryBorder SecondaryBorder
TertiaryBorder TertiaryBorder TertiaryBorder
Primary Secondary Tertiary Info Success Warning SevereWarning Error
PrimaryForeground SecondaryForeground TertiaryForeground
PrimaryBorder SecondaryBorder TertiaryBorder
External Icons
Size
Small Small Small Small
Medium Medium Medium Medium
Large Large Large Large
Style & Class
RTL
API
Every parameter, public member, sub-class and enum this component exposes.
BitTag parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AriaCurrent | BitNavAriaCurrent | BitNavAriaCurrent.True | What a selected tag that is a link reports itself as through aria-current. It only ever reaches the anchor the tag becomes while Href is set - a tag that is a button reports its selection through aria-pressed instead. |
| AriaDescription | string? | null | The detailed description of the tag for the benefit of screen readers, rendered into a visually hidden element the tag points at with aria-describedby. |
| ChildContent | RenderFragment? | null | Child content of component, the content that the tag will apply to. It replaces the Text and the SecondaryText only; an icon, an image, the checkmark of a selected tag and a trailing SecondaryIcon all keep rendering around it. Use the PrefixTemplate and the SuffixTemplate for markup that belongs beside the label rather than in place of it. |
| Classes | BitTagClassStyles? | null | Custom CSS classes for different parts of the tag. |
| Color | BitColor? | null | The general color of the tag. |
| DefaultSelected | bool? | null | The initial value of Selected for a tag that keeps its own selection: setting it is the whole of what an uncontrolled filter chip needs. A Selected that is set one way, without binding, is one the tag itself is not allowed to change. |
| DismissIcon | BitIconInfo? | null | Gets or sets the icon to use for the dismiss button using custom CSS classes for external icon libraries. Takes precedence over DismissIconName when both are set. Defaults to the built-in Cancel icon when neither is set. |
| DismissIconName | string? | null | Gets or sets the name of the icon to use for the dismiss button from the built-in Fluent UI icons. Defaults to Cancel when not set. For external icon libraries, use DismissIcon instead. |
| DismissLabel | string? | null | The accessible name and the tooltip of the dismiss button. With no value it is named after the Text of the tag through the DismissLabelFormat, and falls back to "Dismiss" on a tag that carries no text of its own. |
| DismissLabelFormat | string? | null | The format the dismiss button is named by while it has no DismissLabel of its own, where {0} is the Text of the tag. Defaults to "Remove {0}", which is also what translating that name goes through. |
| Download | string? | null | Prompts the browser to download the Href of the tag rather than to navigate to it, using the value as the suggested file name. An empty string keeps the name the server suggests. |
| FullWidth | bool | false | Stretches the tag to fill the width of whatever holds it, instead of shrinking to its content. |
| HideSelectedIcon | bool | false | Hides the checkmark a selected tag shows in front of its content. |
| Href | string? | null | The URL the tag navigates to, which also turns the tag into a link. A disabled tag drops the href and leaves the tab order. |
| Icon | BitIconInfo? | null | Gets or sets the icon to display using custom CSS classes for external icon libraries. Takes precedence over IconName when both are set. |
| IconAlt | string? | null | The text alternative of the IconUrl picture, which is decorative and renders with an empty alt by default. |
| IconName | string? | null | Gets or sets the name of the icon to display from the built-in Fluent UI icons. For external icon libraries, use Icon instead. |
| IconUrl | string? | null | The URL of a picture to show in place of the icon, cropped to a circle the height of the label. It is only rendered while neither Icon nor IconName is set. |
| NoWrap | bool | false | Keeps the content of the tag on a single line and ends it with an ellipsis where it does not fit. |
| OnChange | EventCallback<bool> | Callback for when the Selected value of the tag has changed. Setting it - or binding Selected - is what turns the tag into a toggle. | |
| OnChanging | EventCallback<BitTagChangeArgs> | Callback invoked before the Selected value changes, letting the change be cancelled by setting Cancel on the args. Since it is awaited, it can also run asynchronous work first. | |
| OnClick | EventCallback<MouseEventArgs> | Click event handler of the tag, which also turns the tag into a real button: focusable, activated with Enter and Space, and disabled along with the tag. | |
| OnDismiss | EventCallback<MouseEventArgs> | Dismiss button click event, if set the dismiss icon will show up. It can also be triggered with the Delete and the Backspace keys from any control the tag renders, and with no DismissLabel of its own the button takes the Text of the tag for its name. | |
| PrefixTemplate | RenderFragment? | null | Custom markup rendered at the head of the tag, ahead of the icon or the picture. It is added rather than substituted, so an icon, an image and the checkmark of a selected tag all keep rendering alongside it. |
| Rel | BitLinkRels? | null | The relationship between the current document and the one the Href of the tag leads to. With no value of its own, a tag opening in a new browsing context gets rel="noopener" automatically. |
| Reversed | bool | false | Reverses the direction flow of the content of the tag: the icon, the label, the trailing SecondaryIcon, the two templates and the dismiss button all swap ends with it. |
| SecondaryIcon | BitIconInfo? | null | The trailing icon of the tag, rendered after the label and before the dismiss button, using custom CSS classes for external icon libraries. Takes precedence over SecondaryIconName when both are set. |
| SecondaryIconName | string? | null | The name of the trailing icon of the tag, from the built-in Fluent UI icons. It is rendered after the label and before the dismiss button, inside whatever the tag became, and it mirrors with the rest of the row when the tag is Reversed. |
| SecondaryText | string? | null | The secondary text of the tag, rendered under the Text in a quieter type. |
| Selected | bool | false | Marks the tag as selected, which paints it in its selected colors and shows a checkmark in front of its content. Binding it - or setting OnChange - turns the tag into a toggle button reporting aria-pressed; a tag that is a link reports aria-current instead. |
| SelectedChanged | EventCallback<bool> | Callback for when the Selected value changes, which is what binding Selected assigns. | |
| SelectedIcon | BitIconInfo? | null | The icon of the checkmark a selected tag shows, using custom CSS classes for external icon libraries. Takes precedence over SelectedIconName when both are set. |
| SelectedIconName | string? | null | The name of the icon of the checkmark a selected tag shows, from the built-in Fluent UI icons. Defaults to Accept when not set. |
| Shape | BitTagShape? | null | The corner shape of the tag. |
| Size | BitSize? | null | The size of the tag. |
| StopPropagation | bool | false | Stops the click of the tag from bubbling any further up the DOM, for a tag sitting inside something else that reacts to a click. |
| Styles | BitTagClassStyles? | null | Custom CSS styles for different parts of the tag. |
| SuffixTemplate | RenderFragment? | null | Custom markup rendered at the end of the tag, after the trailing SecondaryIcon and before the dismiss button. The mirror of the PrefixTemplate, and subject to the same rules. |
| Target | string? | null | The browsing context the Href of the tag is opened in, for example _blank. |
| Text | string? | null | The text of the tag. |
| Title | string? | null | The tooltip to show when the mouse is placed on the tag, which is what spells out whatever a NoWrap ellipsis has cut off. |
| Variant | BitVariant? | null | The visual variant of the tag. |
BitTag public members
| Name | Type | Default value | Description |
|---|---|---|---|
| FocusAsync | ValueTask | Gives the keyboard focus to the tag: the anchor or the button it becomes while it is a control, the dismiss button of a tag that has only that, and the root element otherwise. |
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. |
| 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. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| IsEnabled | bool | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. |
| 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. |
BitTagClassStyles properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Root | string? | null | Custom CSS classes/styles for the root element of the BitTag. |
| Content | string? | null | Custom CSS classes/styles for the content element of the BitTag, which is the anchor or the button the tag becomes while it is a link or a control, and a plain span otherwise. |
| Label | string? | null | Custom CSS classes/styles for the label of the BitTag, which is the element holding its text and secondary text. |
| Text | string? | null | Custom CSS classes/styles for the text of the BitTag. |
| SecondaryText | string? | null | Custom CSS classes/styles for the secondary text of the BitTag. |
| Icon | string? | null | Custom CSS classes/styles for the icon of the BitTag. |
| Image | string? | null | Custom CSS classes/styles for the image of the BitTag. |
| SecondaryIcon | string? | null | Custom CSS classes/styles for the trailing icon of the BitTag, which is rendered after the label. |
| Selected | string? | null | Custom CSS classes/styles for the root element of the BitTag while it is selected. |
| SelectedIcon | string? | null | Custom CSS classes/styles for the checkmark icon a selected BitTag shows. |
| DismissButton | string? | null | Custom CSS classes/styles for the dismiss button of the BitTag. |
| DismissIcon | string? | null | Custom CSS classes/styles for the dismiss icon of the BitTag. |
BitTagChangeArgs properties
The arguments of the OnChanging callback of the BitTag.
| Name | Type | Default value | Description |
|---|---|---|---|
| Value | bool | The selection state the tag is about to move to. | |
| Cancel | bool | false | Set to true to cancel the change and keep the current selection state. |
BitIconInfo properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Name | string? | null | Gets or sets the name of the icon. |
| BaseClass | string? | null | Gets or sets the base CSS class for the icon. For built-in Fluent UI icons, this defaults to "bit-icon". For external icon libraries like FontAwesome, you might set this to "fa" or leave empty. |
| Prefix | string? | null | Gets or sets the CSS class prefix used before the icon name. For built-in Fluent UI icons, this defaults to "bit-icon--". For external icon libraries, you might set this to "fa-" or leave empty. |
BitColor enum
| Name | Value | Description |
|---|---|---|
| Primary | 0 | Info Primary general color. |
| Secondary | 1 | Secondary general color. |
| Tertiary | 2 | Tertiary general color. |
| Info | 3 | Info general color. |
| Success | 4 | Success general color. |
| Warning | 5 | Warning general color. |
| SevereWarning | 6 | SevereWarning general color. |
| Error | 7 | Error general color. |
| PrimaryBackground | 8 | Primary background color. |
| SecondaryBackground | 9 | Secondary background color. |
| TertiaryBackground | 10 | Tertiary background color. |
| PrimaryForeground | 11 | Primary foreground color. |
| SecondaryForeground | 12 | Secondary foreground color. |
| TertiaryForeground | 13 | Tertiary foreground color. |
| PrimaryBorder | 14 | Primary border color. |
| SecondaryBorder | 15 | Secondary border color. |
| TertiaryBorder | 16 | Tertiary border color. |
BitTagShape enum
| Name | Value | Description |
|---|---|---|
| Rounded | 0 | Takes the chip corner of the current theme, which is a pill in Cupertino and a small radius in Fluent and Material. |
| Circular | 1 | Rounds the corner fully, so the tag is always a pill whatever the theme says. |
| Square | 2 | Drops the corner altogether, so the tag is a rectangle. |
BitSize enum
| Name | Value | Description |
|---|---|---|
| Small | 0 | The small size. |
| Medium | 1 | The medium size. |
| Large | 2 | The large size. |
BitVariant enum
| Name | Value | Description |
|---|---|---|
| Fill | 0 | Fill styled variant. |
| Outline | 1 | Outline styled variant. |
| Text | 2 | Text styled variant. |
BitLinkRels enum
| Name | Value | Description |
|---|---|---|
| Alternate | 1 | Provides a link to an alternate representation of the document. (i.e. print page, translated or mirror) |
| Author | 2 | Provides a link to the author of the document. |
| Bookmark | 4 | Permanent URL used for bookmarking. |
| External | 8 | Indicates that the referenced document is not part of the same site as the current document. |
| Help | 16 | Provides a link to a help document. |
| License | 32 | Provides a link to licensing information for the document. |
| Next | 64 | Provides a link to the next document in the series. |
| NoFollow | 128 | Links to an unendorsed document, like a paid link. ("NoFollow" is used by Google, to specify that the Google search spider should not follow that link) |
| NoOpener | 256 | Requires that any browsing context created by following the hyperlink must not have an opener browsing context. |
| NoReferrer | 512 | Makes the referrer unknown. No referrer header will be included when the user clicks the hyperlink. |
| Prev | 1024 | The previous document in a selection. |
| Search | 2048 | Links to a search tool for the document. |
| Tag | 4096 | A tag (keyword) for the current document. |
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.