@@ -17,6 +17,8 @@ import type { EditorView } from '@codemirror/view';
17
17
18
18
export interface HdsCodeEditorSignature {
19
19
Args : {
20
+ ariaLabel ?: string ;
21
+ ariaLabelledby ?: string ;
20
22
hasCopyButton ?: boolean ;
21
23
hasFullScreenButton ?: boolean ;
22
24
language ?: HdsCodeEditorModifierSignature [ 'Args' ] [ 'Named' ] [ 'language' ] ;
@@ -40,6 +42,7 @@ export default class HdsCodeEditor extends Component<HdsCodeEditorSignature> {
40
42
@tracked private _isFullScreen = false ;
41
43
@tracked private _isSetupComplete = false ;
42
44
@tracked private _value ;
45
+ @tracked private _titleId : string | null = null ;
43
46
44
47
private _handleEscape = modifier ( ( ) => {
45
48
const handleKeyDown = ( event : KeyboardEvent ) => {
@@ -65,6 +68,14 @@ export default class HdsCodeEditor extends Component<HdsCodeEditorSignature> {
65
68
}
66
69
}
67
70
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
+
68
79
get classNames ( ) : string {
69
80
// Currently there is only one theme so the class name is hard-coded.
70
81
// In the future, additional themes such as a "light" theme could be added.
@@ -81,6 +92,11 @@ export default class HdsCodeEditor extends Component<HdsCodeEditorSignature> {
81
92
return ( this . args . hasCopyButton || this . args . hasFullScreenButton ) ?? false ;
82
93
}
83
94
95
+ @action
96
+ registerTitleElement ( element : HdsCodeEditorTitleSignature [ 'Element' ] ) : void {
97
+ this . _titleId = element . id ;
98
+ }
99
+
84
100
@action
85
101
toggleFullScreen ( ) : void {
86
102
this . _isFullScreen = ! this . _isFullScreen ;
0 commit comments