Skip to content

Commit 2d94846

Browse files
authored
fix(CodeSnippet): a11y tabstop + attributes (#13310)
* fix(CodeSnippet): a11y tabstop + attributes * fix(CSS): add Carbon CSS to focus outline * refactor(CodeSnippet): relocate parens
1 parent 0229bf0 commit 2d94846

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/react/src/components/CodeSnippet/CodeSnippet.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,14 @@ function CodeSnippet({
226226
<div {...rest} className={codeSnippetClasses}>
227227
<div
228228
ref={codeContainerRef}
229-
role={type === 'single' ? 'textbox' : null}
230-
tabIndex={type === 'single' && !disabled ? 0 : null}
229+
role={type === 'single' || type === 'multi' ? 'textbox' : null}
230+
tabIndex={
231+
(type === 'single' || type === 'multi') && !disabled ? 0 : null
232+
}
231233
className={`${prefix}--snippet-container`}
232234
aria-label={ariaLabel || 'code-snippet'}
235+
aria-readonly={type === 'single' || type === 'multi' ? true : null}
236+
aria-multiline={type === 'multi' ? true : null}
233237
onScroll={(type === 'single' && handleScroll) || null}
234238
{...containerStyle}>
235239
<pre

packages/styles/scss/components/code-snippet/_code-snippet.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ $copy-btn-feedback: $background-inverse !default;
201201
order: 1;
202202
overflow-y: auto;
203203
transition: max-height $duration-moderate-01 motion(standard, productive);
204+
205+
&:focus {
206+
@include focus-outline('outline');
207+
208+
outline-offset: 0;
209+
}
204210
}
205211

206212
// expanded snippet container

0 commit comments

Comments
 (0)