ba-copy-to-clipboard
Enables users to copy important short codes and reference numbers to their clipboards
Airframe
Web Components
React
React Native
Anatomy
Text value
Displays the content that users can copy to their clipboard, such as an identifier, code, or reference value
Heading
Provides context for the displayed value, helping users understand the purpose or meaning of the content
Copy button
A clear and accessible button that copies the displayed value to the user's clipboard when clicked or activated via keyboard, with appropriate focus indicators and accessible labeling
Design Documentation
The ba-copy-to-clipboard component is optimised for reference codes. Using it for other information may break the component and degrade the user experience, especially when used with other languages or modified through users' accessibility settings
Although technically ba-copy-to-clipboard can go in ba-grid, and ba-grid can go in ba-message, the component should not be used in ba-message itself.
This is because the component is designed for standalone use in the body of the page and may break when placed in a component with limited space (e.g., ba-message).
We are currently investigating how to enable BAgel helper to flag this as an error and the best way to document this restriction.
Copy functionality will only work in secure contexts
The copy functionality uses the native writeText() method that will only work in secure contexts (i.e. HTTPS). If you are using this component in a non-secure context, the component will still render but the copy functionality will not populate the clipboard.
Live Demo
<ba-copy-to-clipboard copy-text="ABCDEFGH" heading="Heading"></ba-copy-to-clipboard>
Properties and attributes
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
copyText(required) |
copy-text |
Text to display in the component | "" |
undefined |
heading(required) |
heading |
Sets the heading to show above the copy text | string |
undefined |
headingLevel |
heading-level |
This will set the |
2 | 3 | 4 | 5 | 6 | undefined |
3 |
Permitted ARIA roles
- None
Slots
| Slot | Description | Permitted elements |
|---|---|---|
| Unnamed slot | Elements will render in the body of the component | None |
Parent components
ba-copy-to-clipboard can be slotted into:
Usage
Basic usage
Most scenarios will only require the copy-text and a heading
<ba-copy-to-clipboard copy-text="BA1234" heading="Your booking reference"></ba-copy-to-clipboard>
Setting heading level
The heading level can be set by passing a number to the heading-level attribute. The heading level should be set by the preceding heading on the page
<h2> in the document outline<h3>A heading further up on the page</h3>
...
<ba-copy-to-clipboard copy-text="BA1234" heading="Your booking reference" heading-level="4"></ba-copy-to-clipboard>
Guidelines
Users of assistive technology often navigate by headings. Including a heading makes it easier for users to find and interact with the copy to clipboard component.
It's important to maintain the order of headings so that they appear in a logical order in the page. Screen readers (and other assistive technology) rely on headings to navigate and understand structure of pages.
Note: this will not change the font size of the heading, only the semantic meaning.
Further reading
The copy button text will change to show the user that the copy action has been successful. The amount of space required will depend on the language of the page, zoom level and browser font size settings
Keyboard navigation
State: Previous element in DOM has focus
<button> in shadow DOM gets focus
State: <button> in shadow has focus
Copies value in copy-text to the user's clipboard
Copies value in copy-text to the user's clipboard
Next tabbable element in the DOM gets focus
Usage and accessibility checklist
Use this checklist to confirm the component has been configured and used correctly.
UX checklist
- Component always has a visible heading
- Copy button has enough space to expand its label (e.g., “Copied”) without overlap or wrapping issues
- Component is only used for short codes or reference numbers (not paragraphs, full sentences, or large data)
- Component is not placed inside ba-message
Accessibility checklist
- Heading follows the correct document hierarchy
- Copy button state change (e.g., “Copied”) is perceivable across languages, zoom levels, and font sizes
- Focus indicator has not been obscured on all sides of the button
- Button is reachable using assistive technology
These checks are handled by the component and do not need to be repeated each time it is used.
- ba-copy-to-clipboard is operable using assistive technology
- Has a visible focus indicator on all sides of the button
- Colour contrast for all states in all BAgel themes
- Animations respect users' reduced motion settings
- High contrast mode adjustments