@@ -9,6 +9,7 @@ import { on } from '@ember/modifier';
99import { notEq , eq } from ' ember-truth-helpers' ;
1010import { guidFor } from ' @ember/object/internals' ;
1111import type Owner from ' @ember/owner' ;
12+ import { modifier } from ' ember-modifier' ;
1213
1314import { HdsIcon } from ' @hashicorp/design-system-components/components' ;
1415import type { HdsIconSignature } from ' @hashicorp/design-system-components/components/hds/icon/index' ;
@@ -42,8 +43,10 @@ export default class DocCodeGroup extends Component<DocCodeGroupSignature> {
4243 @tracked copyTimer: ReturnType <typeof setTimeout > | undefined ;
4344 @tracked copyIconName: HdsIconSignature [' Args' ][' name' ] = ' clipboard-copy' ;
4445 @tracked expandIconName: HdsIconSignature [' Args' ][' name' ] = ' unfold-open' ;
46+ @tracked hasScrollbar = false ;
4547
4648 componentId = guidFor (this );
49+ codeSnippetWrapperElement! : HTMLDivElement ;
4750
4851 constructor (owner : Owner , args : DocCodeGroupSignature [' Args' ]) {
4952 super (owner , args );
@@ -52,6 +55,10 @@ export default class DocCodeGroup extends Component<DocCodeGroupSignature> {
5255 }
5356 }
5457
58+ registerCodeSnippetWrapper = modifier ((element : HTMLDivElement ) => {
59+ this .codeSnippetWrapperElement = element ;
60+ });
61+
5562 get unescapedHbsSnippet() {
5663 return unescapeCode (this .args .hbsSnippet ?? ' ' );
5764 }
@@ -89,7 +96,7 @@ export default class DocCodeGroup extends Component<DocCodeGroupSignature> {
8996 }
9097
9198 get toggleButtonLabel() {
92- return this .isExpanded ? ' Collapse code ' : ' Expand code ' ;
99+ return this .isExpanded ? ' Collapse .gts snippet ' : ' Expand .gts snippet ' ;
93100 }
94101
95102 get language() {
@@ -142,13 +149,15 @@ export default class DocCodeGroup extends Component<DocCodeGroupSignature> {
142149 handleGtsExpandClick = () => {
143150 this .isExpanded = ! this .isExpanded ;
144151 this .expandIconName = this .isExpanded ? ' unfold-close' : ' unfold-open' ;
152+ this .checkHorizontalScrollbar ();
145153 };
146154
147155 handleLanguageChange = (event : Event ) => {
148156 const input = event .target as HTMLInputElement ;
149157 if (input .checked ) {
150158 this .currentView = input .value ;
151159 }
160+ this .checkHorizontalScrollbar ();
152161 };
153162
154163 onSuccess = () => {
@@ -172,6 +181,20 @@ export default class DocCodeGroup extends Component<DocCodeGroupSignature> {
172181 }, 2000 );
173182 }
174183
184+ checkHorizontalScrollbar() {
185+ const codeElement = this .codeSnippetWrapperElement .querySelector (
186+ ' code' ,
187+ ) as HTMLElement ;
188+
189+ console .log (codeElement );
190+
191+ if (codeElement .scrollHeight != codeElement .clientHeight ) {
192+ this .hasScrollbar = true ;
193+ } else {
194+ this .hasScrollbar = false ;
195+ }
196+ }
197+
175198 <template >
176199 <div class =" doc-code-group" >
177200 <div class =" doc-code-group__action-bar" >
@@ -218,17 +241,24 @@ export default class DocCodeGroup extends Component<DocCodeGroupSignature> {
218241 />
219242 </div >
220243 {{/if }}
221- <div class =" doc-code-block__code-snippet-wrapper" >
244+ <div
245+ class =" doc-code-block__code-snippet-wrapper"
246+ {{this .registerCodeSnippetWrapper }}
247+ >
222248 {{#if ( eq this . currentView " gts" ) }}
223- <button
224- type =" button"
225- class =" doc-code-group__expand-button"
226- {{on " click" this . handleGtsExpandClick}}
227- aria-label ={{this .toggleButtonLabel }}
228- aria-expanded ={{this .isExpanded }}
229- >
230- <HdsIcon @ name ={{this .expandIconName }} />
231- </button >
249+ <div class =" doc-code-group__expand-button-container" >
250+ <button
251+ type =" button"
252+ class =" doc-code-group__expand-button"
253+ {{on " click" this . handleGtsExpandClick}}
254+ aria-expanded ={{this .isExpanded }}
255+ >
256+ <HdsIcon @ name ={{this .expandIconName }} />
257+ <span >
258+ {{this .toggleButtonLabel }}
259+ </span >
260+ </button >
261+ </div >
232262 {{/if }}
233263 <CodeBlock
234264 @ code ={{this .currentViewSnippet }}
0 commit comments