Skip to content
# CopyButton **Also known as:** ClipboardButton, CopyToClipboardButton ## Description BitCopyButton puts a value on the clipboard and confirms it, because a copy button that gives no feedback leaves the user guessing whether it worked: for CopiedDuration after the copy its glyph is a check mark, its text says Copied, and a polite live region announces it. It is a BitButton, with the button's variants, sizes and colors, an icon button when it is given no Text, and is disabled while it has no Value. ## Parameters | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Classes | `BitCopyButtonClassStyles?` | null | Custom CSS classes for different parts of the copy button. | | Color | `BitColor?` | null | The general color of the button. Left unset, the button is primary unless the --bit-Button-* variables say otherwise. | | CopiedDuration | `TimeSpan` | TimeSpan.FromSeconds(2) | How long the copied state - the copied glyph and text - stays on the button after a copy, before it goes back to what it was. Another copy while it shows starts it over. A zero or negative duration confirms nothing: the copy is made and OnCopy raised, but the copied state is never shown or announced. | | CopiedIcon | `BitIconInfo?` | null | The icon the button shows while it is in the copied state, using custom CSS classes for external icon libraries. Takes precedence over CopiedIconName when both are set. With neither set, the button shows a check mark (Accept). | | CopiedIconName | `string?` | null | The name of the built-in Fluent UI icon the button shows while it is in the copied state. With neither this nor CopiedIcon set, the button shows a check mark (Accept). | | CopiedText | `string?` | null | The text the button carries, and the live region announces, while it is in the copied state. When null, the Copied text of the strings in force is used (BitStrings.Copied, "Copied"). | | Icon | `BitIconInfo?` | null | The icon of the button, using custom CSS classes for external icon libraries. Takes precedence over IconName when both are set. With neither set, the button shows the Copy glyph. | | IconName | `string?` | null | The name of the built-in Fluent UI icon of the button. With neither this nor Icon set, the button shows the Copy glyph. | | OnCopy | `EventCallback<string>` | | The callback raised once the value is on the clipboard, with the value that was copied. | | OnCopyFailed | `EventCallback<Exception>` | | The callback raised when the browser could not put the value on the clipboard (a permission denied, a copy command refused), with the error it gave. The button confirms nothing, and a confirmation of an earlier copy still showing is taken off. | | Size | `BitSize?` | null | The size of the button. Left unset, the button is medium unless the --bit-Button-* variables say otherwise. | | Styles | `BitCopyButtonClassStyles?` | null | Custom CSS styles for different parts of the copy button. | | Text | `string?` | null | The text of the button; CopiedText takes its place while the button is in the copied state. When null, the button is an icon button named by the Copy text of the strings in force (BitStrings.Copy, "Copy") - or by AriaLabel - which is also its tooltip. | | Value | `string?` | null | The text to put on the clipboard, read when the button is pressed. A null value disables the button, the way Disabled does; an empty text is copied like any other. A confirmation still showing is taken off once the value changes. | | Variant | `BitVariant?` | null | The visual variant of the button. Left unset, the button is Fill. | | 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. | ## 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 ### BitColor Enum | Name | Value | Description | | :--- | :--- | :---------- | | Primary | 0 | 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. | | 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. | ## Sub Classes ### BitCopyButtonClassStyles Properties | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Root | `string?` | null | Custom CSS classes/styles for the root element of the BitCopyButton. | | Button | `BitButtonClassStyles?` | null | Custom CSS classes/styles for the BitButton of the BitCopyButton. | | LiveRegion | `string?` | null | Custom CSS classes/styles for the visually hidden live region of the BitCopyButton, which announces the copy. | ## Examples \n**Basic**: ```razor dotnet add package Bit.BlazorUI.Extras ``` \n**Text & CopiedText**: ```razor ``` \n**Icons**: ```razor ``` \n**Variant**: ```razor ``` \n**CopiedDuration & OnCopy**: ```razor Copied @copyCount time(s)@(copyError is null ? null : $", last error: {copyError}") ``` ```csharp private int copyCount; private string? copyError; private void HandleCopy(string value) { copyCount++; copyError = null; } private void HandleCopyFailed(Exception exception) { copyError = exception.Message; } ``` \n**Value**: ```razor ``` ```csharp private string? draft; ``` \n**Disabled**: ```razor ``` \n**Cascading parameters**: ```razor ``` ```csharp private readonly BitCopyButtonParams[] copyButtonParams = [ new() { Variant = BitVariant.Outline, Text = "Copy", CopiedText = "Done", CopiedDuration = TimeSpan.FromSeconds(4) } ]; ``` \n**Color**: ```razor ``` \n**External Icons**: ```razor ``` \n**Size**: ```razor ``` \n**Style & Class**: ```razor ``` ```csharp private const string cssVariablesStyle = "--bit-Button-fill-background:var(--bit-clr-ter);" + "--bit-Button-fill-border-color:var(--bit-clr-ter);" + "--bit-Button-radius:2rem;"; ``` \n**RTL**: ```razor
```