Skip to content

Notifications

Tag

Bit.BlazorUIChip

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

Text is what the tag says. On its own the tag is a label rather than a control: it takes no focus, it reacts to nothing, and it is a plain inline element that sits inside a sentence without breaking the line it is on. Everything else on this page is something added on top of that - a glyph, a dismiss button, a click handler, a URL, a selection.


Basic tag Design Archived

Variant

The tag offers three variants: Fill (default) paints the whole chip in the role color, Outline keeps only the rule and the label, and Text drops the rule too and leaves the label alone. A disabled tag keeps its variant and swaps the role color for the disabled one.


Fill Outline Text


Fill Outline Text

Shape

Shape is the corner of the tag. Rounded (default) takes the chip corner of the current theme, which is what keeps a tag in the same visual language as the chips a TagsInput or a multi-select Dropdown draws in its field; Circular pins it to a pill and Square drops the radius altogether, whatever the theme says.


Rounded Circular Square

Icon

IconName puts a glyph at the head of the tag, which is what lets a row of tags be told apart at a glance rather than read one by one. SecondaryIconName puts one at the other end, after the label and before the dismiss button, for the glyph that closes the tag rather than opening it - the chevron of a chip that drops a menu, the arrow of one that leads somewhere. It sits inside whatever the tag became, so it is part of the same target the pointer and the keyboard activate rather than a control of its own. Both glyphs are decorative - they are hidden from assistive technologies, since the label between them already says what the tag is - and both are normalized to the size of that label, so an icon from any library sits on the same line as the words. Reversed mirrors the order of the whole tag, which swaps the two ends over.


Calendar Reversed Pinned


Read the docs Both ends reversed

Image

IconUrl puts a picture where the glyph would go - the avatar of the person the tag stands for, a flag, a logo. It is cropped to a circle the height of the label, so a portrait of any aspect ratio reads as an avatar, and it is only rendered while no Icon or IconName is set, since the two occupy the same place. The picture is decorative next to the name beside it, so it carries an empty alt unless IconAlt says otherwise - as on the third tag below, where the label says what the state is and only the picture says whose it is.


Annie Lindqvist Annie LindqvistSoftware engineer Assigned to Annie LindqvistAwaiting review

Secondary text

SecondaryText adds a second line under the label, for what qualifies the tag rather than what names it - the role under a person, the count under a category, the unit under a value. It is set one step smaller and at the regular weight, and the line above it is lifted to semibold to answer it; neither is dimmed, since an opacity over a painted chip takes the contrast with it. Keep it short: a tag is a label, not a card.


Alex ParkerProduct designer Storage12.4 GB used

Dismiss

Setting OnDismiss grows a close button at the end of the tag. It is a real button standing next to the content rather than inside it, so it takes focus of its own, it is activated with Enter and Space, and a click on it never reaches the tag's own OnClick. It can also be triggered with the Delete or the Backspace key from anywhere inside the tag, which is what a keyboard user reaches for once the pointer has shown them the button. DismissIconName and DismissIcon change the glyph, and DismissLabel its accessible name and tooltip. With no label of its own the button is named after the tag it takes away - "Remove Design" - rather than being one of a row of buttons all called "Dismiss", which names none of them. DismissLabelFormat is what changes that wording for a whole list at once and what translates it, since the default is English; DismissLabel replaces the name of a single tag outright. The tag never removes itself: what the handler does with the dismissal is up to the app, and FocusAsync is what puts the keyboard back on the list afterwards.


DesignResearchDocsCustom glyph Formatted label Disabled


Click

Setting OnClick turns the tag into a real 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.




The card counts every click that reaches it. The second tag stops its own.

 

Clicked 0 times, dismissed 0 times, card clicked 0 times.

Link

Href turns the tag into a real anchor, for a tag that opens what it stands for rather than acting on the page it is already on. It brings everything a click handler cannot: the context menu, the middle click, the address in the status bar and the announcement of a link. Target picks the browsing context it opens in and Rel the relationship to the linked document - a tag opening in a new tab with no Rel of its own is given 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

Binding Selected - or setting OnChange - turns the tag into a filter chip: a toggle button that flips its own state on every activation and reports it to assistive technologies through 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.




Static selection Current link




Selected: In progress

Template

ChildContent replaces the label of the tag with markup of your own. It replaces the text only: an icon, a picture, the checkmark of a selected tag and a trailing SecondaryIcon all keep rendering around it, so a template does not have to reproduce them.

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.


Loading
Alex (owner)


APAlex ParkerProduct designer Open issues24

Truncation

A tag wraps onto as many lines as its content needs by default, which is what keeps a long label readable. NoWrap keeps it on a single line and ends it with an ellipsis wherever it does not fit, for a layout that has a width of its own to protect - a row of filters, a cell of a grid. Pair it with a Title so the part that was cut off is still reachable: a truncated label a reader cannot recover is a label that says nothing.


A tag with a label long enough to wrap onto a second line


A tag with a label long enough to wrap onto a second line

Full width

FullWidth stretches the tag to the width of whatever holds it instead of letting it shrink to its content. Use it for a tag standing on a line of its own - in a narrow side panel, or as a row of a stacked list - where a chip hugging its label leaves the line looking unfinished. The dismiss button stays at the end of the tag as it grows, and so does a trailing SecondaryIcon: the room a stretched tag gains belongs to the label, which is what pushes a trailing glyph to the far end rather than leaving it stranded against the words.


Full width
Full width and dismissible

Focus

FocusAsync gives the keyboard focus to whatever the tag offers it: the anchor or the button it becomes while it is a control, and the dismiss button of a tag that has only that. A list of dismissible tags is what needs it - the focus left on a tag that has just been removed falls back to the top of the document, and the keyboard user loses their place in the list. Removing a tag below moves the focus onto the tag that took its place, or onto the last one when the end of the list goes. A tag that is neither a control nor dismissible has nothing inside it to focus, so a TabIndex given to that one lands on the tag itself - which is what puts a plain tag in the tab sequence and what FocusAsync then focuses. Without one a plain tag stays what it is: a label, which takes no focus at all.


DesignResearchDocs




A plain tag with a TabIndex

Accessibility

A plain tag is a label, so it takes no focus and needs no name of its own - the words in it are the name. Everything that makes it a control changes that: an OnClick, an Href or a selection turns it into a real button or anchor, and a control needs a name, so AriaLabel moves onto that control and is what an icon-only tag has to be given before it becomes one. On a tag that is not a control and has no words in it either, the same label is carried as text no one can see, since an aria-label on an element with no role of its own is not something every screen reader reads. AriaDescription adds what is said after that name - why a filter is unavailable, what dismissing will do - and lands on whichever element carries the name. The dismiss button is a control of its own, already named after the tag it removes; DismissLabelFormat translates that name and DismissLabel replaces it where it needs to say something else. Icons and pictures inside the tag are hidden from assistive technologies, since the label beside them already says what the tag is, and a selected tag reports its state through 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.


Pinned to the top Design Shows only the items you own

Color

Offering a range of specialized color variants, providing visual cues for specific actions or states within your application. Every role pairs with all three variants, and the disabled state of each is the disabled slot of the same role rather than a flat grey.

Primary  Primary  Primary

Secondary  Secondary  Secondary

Tertiary  Tertiary  Tertiary

Info  Info  Info

Success  Success  Success

Warning  Warning  Warning

SevereWarning  SevereWarning  SevereWarning

Error  Error  Error

PrimaryBackground  PrimaryBackground  PrimaryBackground

SecondaryBackground  SecondaryBackground  SecondaryBackground

TertiaryBackground  TertiaryBackground  TertiaryBackground


PrimaryForeground  PrimaryForeground  PrimaryForeground

SecondaryForeground  SecondaryForeground  SecondaryForeground

TertiaryForeground  TertiaryForeground  TertiaryForeground


PrimaryBorder  PrimaryBorder  PrimaryBorder

SecondaryBorder  SecondaryBorder  SecondaryBorder

TertiaryBorder  TertiaryBorder  TertiaryBorder


Disabled:

Primary  Secondary  Tertiary  Info  Success  Warning  SevereWarning  Error

PrimaryBackground  SecondaryBackground  TertiaryBackground

PrimaryForeground  SecondaryForeground  TertiaryForeground

PrimaryBorder  SecondaryBorder  TertiaryBorder

External Icons

Use icons from external libraries like FontAwesome and Bootstrap Icons with the Icon parameter and BitIconInfo. A glyph from any of them is normalized back to the size of the label beside it, so it sits on the same line as the words whatever type scale the library it came from brings. SecondaryIcon, DismissIcon and SelectedIcon take the same values, so the trailing glyph, the close button and the checkmark of a selected tag can all come from the same set as the one in front of the label.


FontAwesome:

House Heart GitHub Rocket Dismiss Selected Trailing



Bootstrap:

House Heart GitHub Gear Dismiss Selected Trailing

Size

Three sizes set the type, the height and the inset of the tag together, so a tag stays a chip at every one of them. The inline inset is taken from the control padding of the current theme rather than from a fixed number, which is what keeps a tag in proportion under a theme whose corner is rounder or whose density is tighter.

Small  Small  Small  Small

Medium  Medium  Medium  Medium

Large  Large  Large  Large

Style & Class

Empower customization by overriding default styles and classes, allowing tailored design modifications to suit specific UI requirements. Style and Class land on the root of the tag, while Styles and Classes reach every part of it separately - the content box the tag becomes when it is a control, the label, the text, the secondary text, the icon, the image, the selected state and the dismiss button with its glyph.


Component's Style & Class:

Styled Tag Classed Tag


Styles & Classes:

Styleswith a second line Classes

RTL

Use BitTag in right-to-left (RTL). The icon, the label and the dismiss button all follow the direction of writing and swap sides with it, and so do the insets that keep them off the rule. Reversed stays a mirror of whatever that order is rather than a second way of saying right-to-left, so the two can be combined.


برچسب طراحی حذف کنید معکوس

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.

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.