Skip to content

Commit ca5114d

Browse files
committed
added support for aria-label and aria-labelledby
1 parent 4696392 commit ca5114d

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

packages/components/src/components/hds/code-editor/index.hbs

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
{{#if (and this._isSetupComplete (or this.hasActions (has-block)))}}
1414
<div class="hds-code-editor__header">
1515
<div class="hds-code-editor__header-content">
16-
{{yield (hash Title=(component "hds/code-editor/title") Description=(component "hds/code-editor/description"))}}
16+
{{yield
17+
(hash
18+
Title=(component "hds/code-editor/title" onInsert=this._registerTitleElement)
19+
Description=(component "hds/code-editor/description")
20+
)
21+
}}
1722
</div>
1823

1924
{{#if this.hasActions}}
@@ -38,6 +43,8 @@
3843
</div>
3944
{{/if}}
4045
<div
46+
aria-label={{this.ariaLabel}}
47+
aria-describedby={{this.ariaLabelledBy}}
4148
class="hds-code-editor__editor"
4249
{{hds-code-editor value=@value language=@language onInput=this.onInput onSetup=this.onSetup}}
4350
/>

packages/components/src/components/hds/code-editor/index.ts

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import type { EditorView } from '@codemirror/view';
1717

1818
export interface HdsCodeEditorSignature {
1919
Args: {
20+
ariaLabel?: string;
21+
ariaLabelledby?: string;
2022
hasCopyButton?: boolean;
2123
hasFullScreenButton?: boolean;
2224
language?: HdsCodeEditorModifierSignature['Args']['Named']['language'];
@@ -40,6 +42,7 @@ export default class HdsCodeEditor extends Component<HdsCodeEditorSignature> {
4042
@tracked private _isFullScreen = false;
4143
@tracked private _isSetupComplete = false;
4244
@tracked private _value;
45+
@tracked private _titleId: string | null = null;
4346

4447
private _handleEscape = modifier(() => {
4548
const handleKeyDown = (event: KeyboardEvent) => {
@@ -65,6 +68,14 @@ export default class HdsCodeEditor extends Component<HdsCodeEditorSignature> {
6568
}
6669
}
6770

71+
get ariaLabel(): string {
72+
return this.args.ariaLabel ?? 'Code editor';
73+
}
74+
75+
get ariaLabelledby(): string | null {
76+
return this.args.ariaLabelledby ?? this._titleId ?? null;
77+
}
78+
6879
get classNames(): string {
6980
// Currently there is only one theme so the class name is hard-coded.
7081
// In the future, additional themes such as a "light" theme could be added.
@@ -81,6 +92,11 @@ export default class HdsCodeEditor extends Component<HdsCodeEditorSignature> {
8192
return (this.args.hasCopyButton || this.args.hasFullScreenButton) ?? false;
8293
}
8394

95+
@action
96+
registerTitleElement(element: HdsCodeEditorTitleSignature['Element']): void {
97+
this._titleId = element.id;
98+
}
99+
84100
@action
85101
toggleFullScreen(): void {
86102
this._isFullScreen = !this._isFullScreen;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
<Hds::Text::Body class="hds-code-editor__title" @tag={{this.tag}} @size="200" @weight="semibold" ...attributes>
1+
<Hds::Text::Body
2+
id={{this._id}}
3+
class="hds-code-editor__title"
4+
@tag={{this.tag}}
5+
@size="200"
6+
@weight="semibold"
7+
{{did-insert this.onInsert}}
8+
...attributes
9+
>
210
{{yield}}
311
</Hds::Text::Body>

packages/components/src/components/hds/code-editor/title.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@ import Component from '@glimmer/component';
77

88
import type { HdsTextBodySignature } from '../text/body';
99

10+
type HdsCodeEditorTitleElement = HdsTextBodySignature['Element'];
11+
1012
export interface HdsCodeEditorTitleSignature {
1113
Args: {
14+
editorId: string;
1215
tag?: HdsTextBodySignature['Args']['tag'];
16+
onInsert: (element: HdsCodeEditorTitleElement) => void;
1317
};
1418
Blocks: {
1519
default: [];
1620
};
17-
Element: HdsTextBodySignature['Element'];
21+
Element: HdsCodeEditorTitleElement;
1822
}
1923

2024
export default class HdsCodeEditorTitle extends Component<HdsCodeEditorTitleSignature> {
25+
private _id = `${this.args.editorId}-title`;
26+
2127
get tag() {
2228
return this.args.tag ?? 'h2';
2329
}

0 commit comments

Comments
 (0)