Accent color
# Button ## Description BitButton triggers an action or navigates when the user activates it. It renders a native button, or an anchor when an Href is provided, and offers Fill, Outline, and Text variants across a full palette of semantic colors and sizes. It supports start/end icons, an optional secondary line of text, built-in loading and auto-loading states that keep the button's size and accessible name, EditForm submission, and accessibility-first defaults such as focusable disabled buttons and automatic rel='noopener' on external links. ## Parameters | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | AllowDisabledFocus | `bool` | true | Keeps the disabled button focusable and discoverable by screen readers, rendering aria-disabled instead of the native disabled attribute when IsEnabled is false, preserving a consistent tab order. Set it to false to render the native disabled attribute and remove the button from the tab order. | | AriaDescription | `string?` | null | Detailed description of the button for the benefit of screen readers (rendered into aria-describedby). | | AriaHidden | `bool` | false | If true, adds an aria-hidden attribute instructing screen readers to ignore the button. | | AutoFocus | `bool` | false | If true, the button automatically receives focus when the page renders (rendered as the autofocus attribute). | | AutoLoading | `bool` | false | If true, enters the loading state automatically while awaiting the OnClick event and prevents subsequent clicks by default. | | ButtonType | `BitButtonType?` | null | The type of the button element; defaults to submit inside an EditForm otherwise button. | | ChildContent | `RenderFragment?` | null | The content of primary section of the button. | | Classes | `BitButtonClassStyles?` | null | Custom CSS classes for different parts of the button. | | Color | `BitColor?` | null | The general color of the button. | | Download | `string?` | null | The value of the download attribute of the link rendered by the button when Href is provided. Instructs the browser to download the linked resource instead of navigating to it, using the provided value as the file name. | | Draggable | `bool` | false | Makes the Float/FloatAbsolute button draggable on the page. | | FixedColor | `bool` | false | Preserves the foreground color of the button through hover and focus. | | Float | `bool` | false | Enables floating behavior for the button, allowing it to be positioned relative to the viewport. | | FloatAbsolute | `bool` | false | Enables floating behavior for the button, allowing it to be positioned relative to its container. | | FloatOffset | `string?` | null | Specifies the offset of the floating button. | | FloatPosition | `BitPosition?` | null | Specifies the position of the floating button. | | FormId | `string?` | null | The id of the form element that the button is associated with (rendered as the form attribute). Allows a submit/reset button to be placed outside of its form element. | | FullWidth | `bool` | false | Expand the button width to 100% of the available width. | | Href | `string?` | null | The value of the href attribute of the link rendered by the button. If provided, the component will be rendered as an anchor tag instead of button. | | 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. | | IconName | `string?` | null | Gets or sets the name of the icon to display from the built-in Fluent UI icons. | | IconOnly | `bool` | false | Determines that only the icon should be rendered. | | IconPosition | `BitIconPosition?` | null | Gets or sets the position of the icon relative to the component's content. | | IconUrl | `string?` | null | The url of the custom icon to render inside the button. | | IsLoading | `bool` | false | Determines whether the button is in loading mode or not. | | LoadingLabel | `string?` | null | The loading label text to show next to the spinner icon. | | LoadingLabelPosition | `BitLabelPosition` | BitLabelPosition.End | The position of the loading Label in regards to the spinner icon. | | LoadingTemplate | `RenderFragment?` | null | The custom template used to replace the default loading text inside the button in the loading state. | | OnClick | `EventCallback<bool>` | | Raised when the button is clicked; receives a bool indicating the current loading state. | | PrimaryTemplate | `RenderFragment?` | | The content of the primary section of the button (alias of the ChildContent). | | Reclickable | `bool` | false | Enables re-clicking while the button is in the loading state. | | Rel | `BitLinkRels?` | null | Sets the rel attribute for link-rendered buttons when Href is a non-anchor URL; ignored for empty or hash-only hrefs. | | SecondaryText | `string?` | null | The text of the secondary section of the button. | | SecondaryTemplate | `RenderFragment?` | | The custom template for the secondary section of the button. | | Size | `BitSize?` | null | Sets the preset size for typography and padding of the button. | | StopPropagation | `bool` | false | If true, stops the click event from bubbling up to the parent elements. | | Styles | `BitButtonClassStyles?` | null | Custom inline styles for different parts of the button. | | Target | `string?` | null | Specifies target attribute of the link when the button renders as an anchor (by providing the Href parameter). When set to _blank and no Rel is provided, rel="noopener" gets added automatically for security. | | Title | `string?` | null | The tooltip to show when the mouse is placed on the button. | | Variant | `BitVariant?` | null | The visual variant of the button. | | 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. | ## 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. | ## Enums ### BitVariant Enum | Name | Value | Description | | :--- | :--- | :---------- | | Fill | 0 | Fill styled variant. | | Outline | 1 | Outline styled variant. | | Text | 2 | Text styled variant. | ### 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. | ### BitSize Enum | Name | Value | Description | | :--- | :--- | :---------- | | Small | 0 | The small size button. | | Medium | 1 | The medium size button. | | Large | 2 | The large size button. | ### BitButtonType Enum | Name | Value | Description | | :--- | :--- | :---------- | | Button | 0 | The button is a clickable button. | | Submit | 1 | The button is a submit button (submits form-data). | | Reset | 2 | The button is a reset button (resets the form-data to its initial values). | ### BitIconPosition Enum | Name | Value | Description | | :--- | :--- | :---------- | | Start | 0 | Icon renders before the content (default). | | End | 1 | Icon renders after the content. | ### BitLabelPosition Enum | Name | Value | Description | | :--- | :--- | :---------- | | Top | 0 | The label shows on the top of the button. | | End | 1 | The label shows on the end of the button. | | Bottom | 2 | The label shows on the bottom of the button. | | Start | 3 | The label shows on the start of the button. | ### 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. | ### BitPosition Enum | Name | Value | Description | | :--- | :--- | :---------- | | TopLeft | 0 | | | TopCenter | 1 | | | TopRight | 2 | | | TopStart | 3 | | | TopEnd | 4 | | | CenterLeft | 5 | | | Center | 6 | | | CenterRight | 7 | | | CenterStart | 8 | | | CenterEnd | 9 | | | BottomLeft | 10 | | | BottomCenter | 11 | | | BottomRight | 12 | | | BottomStart | 13 | | | BottomEnd | 14 | | ### 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. | ## Sub Classes ### BitButtonClassStyles Properties Defines per-part CSS class/style values for BitButton. | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Root | `string?` | null | Custom class or style applied to the root element. | | Icon | `string?` | null | Custom class or style applied to the icon element. | | Container | `string?` | null | Custom class or style applied to the internal container. | | Primary | `string?` | null | Custom class or style applied to the primary section. | | Secondary | `string?` | null | Custom class or style applied to the secondary section. | | HiddenContent | `string?` | null | Custom class or style applied to the wrapper of the content that keeps the button size while it is hidden in the loading state. | | LoadingContainer | `string?` | null | Custom class or style applied to the loading container. | | Spinner | `string?` | null | Custom class or style applied to the spinner element. | | LoadingLabel | `string?` | null | Custom class or style applied to the loading label. | ### 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. | ## Examples \n**Basic**: ```razor Button ``` \n**Primary & Secondary**: ```razor Primary text Primary text ``` \n**Variant**: ```razor Fill Outline Text Fill Outline Text Fill Outline Text Fill Outline Text ``` \n**Disabled**: ```razor Focusable disabled Unfocusable disabled ``` \n**Title**: ```razor Hover me Hover me Hover me ``` \n**Icon**: ```razor Start Start Start Start Start Start End End End End End End Start Start Start End End End ``` \n**Icon only**: ```razor ``` \n**Loading**: ```razor Click me Click me Click me Click me Click me Click me Click me
AutoLoading click count: @autoLoadCount
Reclickable
Re-clickable AutoLoading click count: @reclickableAutoLoadCount
``` ```csharp private bool fillIsLoading; private bool outlineIsLoading; private bool textIsLoading; private async Task LoadingFillClick() { fillIsLoading = true; await Task.Delay(3000); fillIsLoading = false; } private async Task LoadingOutlineClick() { outlineIsLoading = true; await Task.Delay(3000); outlineIsLoading = false; } private async Task LoadingTextClick() { textIsLoading = true; await Task.Delay(3000); textIsLoading = false; } private int autoLoadCount; private async Task AutoLoadingClick() { autoLoadCount++; await Task.Delay(3000); } private int reclickableAutoLoadCount; private TaskCompletionSource clickTsc = new(); private CancellationTokenSource delayCts = new(); private Task AutoLoadingReclick(bool isLoading) { if (isLoading) { clickTsc.TrySetException(new TaskCanceledException()); delayCts.Cancel(); } delayCts = new(); clickTsc = new(); reclickableAutoLoadCount++; _ = Task.Delay(3000, delayCts.Token).ContinueWith(async delayTask => { await delayTask; clickTsc.TrySetResult(); }); return clickTsc.Task; } ``` \n**Loading Label**: ```razor End Start Bottom Top ``` \n**Href**: ```razor Open bitplatform.dev Go to bitplatform GitHub Download the bit logo ``` \n**Rel**: ```razor Open bitplatform.dev with a rel attribute (nofollow) Open bitplatform.dev with a rel attribute (nofollow & noreferrer) ``` \n**Float & Draggable**: ```razor
Once upon a time, stories wove connections between people, a symphony of voices crafting shared dreams. Each word carried meaning, each pause brought understanding. Placeholder text reminds us of that moment when possibilities are limitless, waiting for content to emerge. The spaces here are open for growth, for ideas that change minds and spark emotions. This is where the journey begins your words will lead the way.
Every story starts with a blank canvas, a quiet space waiting to be filled with ideas, emotions, and dreams. These placeholder words symbolize the beginning - a moment of possibility where creativity has yet to take shape. Imagine this text as the scaffolding of something remarkable, a foundation upon which connections and inspirations will be built. Soon, these lines will transform into narratives that provoke thought, spark emotion, and resonate with those who encounter them. Until then, they remind us of the beauty in potential the quiet magic of beginnings, where everything is still to come, and the possibilities are boundless. This space is yours to craft, yours to shape, yours to bring to life.
In the beginning, there is silence a blank canvas yearning to be filled, a quiet space where creativity waits to awaken. These words are temporary, standing in place of ideas yet to come, a glimpse into the infinite possibilities that lie ahead. Think of this text as a bridge, connecting the empty spaces of now with the vibrant narratives of tomorrow. It whispers of the stories waiting to be told, of the thoughts yet to be shaped into meaning, and the emotions ready to resonate with every reader.
In this space, potential reigns supreme. It is a moment suspended in time, where imagination dances freely and each word has the power to transform into something extraordinary. Here lies the start of something new - an opportunity to craft, inspire, and create. Whether it's a tale of adventure, a reflection of truth, or an idea that sparks change, these lines are yours to fill, to shape, and to make uniquely yours. The journey begins here, in this quiet moment where everything is possible.
``` ```csharp private string? floatOffset = "63px"; private BitPosition floatPosition = BitPosition.BottomRight; [Inject] private IJSRuntime _js { get; set; } = default!; private async Task ScrollToFloat() => await _js.ScrollToElement("example12"); private readonly List> floatPositionList = Enum.GetValues() .Cast() .Select(enumValue => new BitDropdownItem { Value = enumValue, Text = enumValue.ToString() }) .ToList(); ``` \n**Button Type**: ```razor @if (formIsValidSubmit is false) {
Submit Reset Button
} else { The form submitted successfully. } @if (externalFormSubmitted is false) { External submit } else { The external form submitted successfully. } ``` ```csharp public class ButtonValidationModel { [Required] public string RequiredText { get; set; } = string.Empty; public string? NonRequiredText { get; set; } } private bool formIsValidSubmit; private ButtonValidationModel buttonValidationModel = new(); private async Task HandleValidSubmit() { formIsValidSubmit = true; await Task.Delay(2000); buttonValidationModel = new(); formIsValidSubmit = false; StateHasChanged(); } private void HandleInvalidSubmit() { formIsValidSubmit = false; } private bool externalFormSubmitted; private ButtonValidationModel externalFormModel = new(); private async Task HandleExternalFormValidSubmit() { externalFormSubmitted = true; await Task.Delay(2000); externalFormModel = new(); externalFormSubmitted = false; StateHasChanged(); } ``` \n**Templates**: ```razor A primary template Primary text A secondary template A primary template A secondary template Click me
Wait...
``` ```csharp private bool templateIsLoading; private async Task LoadingTemplateClick() { templateIsLoading = true; await Task.Delay(3000); templateIsLoading = false; } ``` \n**Events**: ```razor Click me (@clickCounter)
With StopPropagation Without StopPropagation
Button clicks: @buttonClickCounter, Parent clicks: @parentClickCounter
Focus target Focus the other button ``` ```csharp private int clickCounter; private int parentClickCounter; private int buttonClickCounter; private BitButton focusButtonRef = default!; ``` \n**Size**: ```razor Fill Fill Outline Outline Text Text Fill Outline Text Fill Fill Outline Outline Text Text Fill Outline Text Fill Fill Outline Outline Text Text Fill Outline Text ``` \n**FullWidth**: ```razor Full Width Button ``` \n**FixedColor**: ```razor ``` \n**Color**: ```razor 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 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 ``` \n**External Icons**: ```razor House (Icon="@@("fa-solid fa-house")") Heart (Icon="@@BitIconInfo.Css("fa-solid fa-heart")") GitHub (Icon="@@BitIconInfo.Fa("brands github")") Rocket (Icon="@@BitIconInfo.Fa("solid rocket")") House (Icon="@@("bi bi-house-fill")") Heart (Icon="@@BitIconInfo.Css("bi bi-heart-fill")") GitHub (Icon="@@BitIconInfo.Bi("github")") Gear (Icon="@@BitIconInfo.Bi("gear-fill")") ``` \n**Style & Class**: ```razor Styled Button Classed Button Click me Click me ``` ```csharp private bool stylesIsLoading; private bool classesIsLoading; private async Task LoadingStylesClick() { stylesIsLoading = true; await Task.Delay(3000); stylesIsLoading = false; } private async Task LoadingClassesClick() { classesIsLoading = true; await Task.Delay(3000); classesIsLoading = false; } ``` \n**RTL**: ```razor دکمه با آیکن دکمه با آیکن دکمه با آیکن دکمه با آیکن دکمه با آیکن دکمه با آیکن ```