Code snippet
No accessibility annotations are needed for code snippets, but keep these considerations in mind if you are modifying Carbon or creating a custom component.
What Carbon provides
Carbon bakes keyboard operation into its components, as well as many other accessibility considerations.
Keyboard interaction
For all three variants, the code snippet can be copied with
Space
Enter
![inline code snippet keyboard interaction](/static/6c2987d50a493ce1101c2f9bb50636fd/3cbba/code-snippet-accessibility-1.png)
By default, each inline code snippet is reachable by
Tab
Space
Enter
![single line code snippet interaction, with 2 tab stops](/static/7e86c6ba0d5cb4ab338f5b98bc55a773/3cbba/code-snippet-accessibility-2.png)
The single line code snippet tabstop supports left and right arrow key scrolling.
![multi-line code snippet keyboard interaction](/static/dfc86d03f38c1d0911314b2c886cae3d/3cbba/code-snippet-accessibility-3.png)
The multi-line’s buttons are reachable by
Tab
Space
Enter
Labeling and updates
Carbon provides the copy button’s default label and tooltip behavior. Carbon handles notices about the success of the copy function, as well as updates to the Show more mechanism.
![hovering on the button exposes ‘copy to clipboard’ tooltip](/static/bad91b117b0ac5b9d39cf117385cfae3/3cbba/code-snippet-accessibility-4.png)
The code snippet’s buttons expose their labels on hover or focus.
![the activated button shows a ‘copied!’ message](/static/f11bf886d2282ca7f48c960815d7362a/3cbba/code-snippet-accessibility-5.png)
The results of activating buttons are provided in text.
Development considerations
Keep this in mind if you are modifying Carbon or creating a custom component:
- the inline code text is implemented as a button so its text can be copied
- single line snippets take an additional tabstop to support arrow key scrolling
Accessibility testing statusFor every latest release, Carbon runs tests on all components to meet the accessibility requirements. These different statuses report the work that Carbon has done in the back end. These tests appear only when the components are stable.
For every latest release, Carbon runs tests on all components to meet the accessibility requirements. These different statuses report the work that Carbon has done in the back end. These tests appear only when the components are stable.
Latest version: | Framework: React (@carbon/react)
Component | Accessibility test | Status | Link to source code |
---|---|---|---|
Code snippet | Test(s) that ensure the initial render state of a component is accessible. | Some tests are incomplete, in progress, invalid, or temporarily skipped. | GitHub link |
Tests that ensure additional states of the component are accessible. This could be interactive states of a component or its multiple variants. | Passes all automated tests with no reported accessibility violations. | ||
Tests that ensure focus is properly managed, and all interactive functions of a component have a proper keyboard-accessible equivalent. | Passes all automated tests with no reported accessibility violations. | ||
This manual testing ensures that the visual information on the screen is properly conveyed and read correctly by screen readers such as JAWS, VoiceOver, and NVDA. | A human has manually tested this component, e.g. screen reader testing. |