Skip to content

Commit 7a4112c

Browse files
dchyunandgen404jorytindallKristinLBradley
authored andcommitted
Website - CodeBlock height toggle docs (#2845)
Co-authored-by: Andrew Gendel <[email protected]> Co-authored-by: Jory Tindall <[email protected]> Co-authored-by: Kristin Bradley <[email protected]>
1 parent 5c1ada7 commit 7a4112c

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

website/docs/components/code-block/partials/code/how-to-use.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ loadInitializers(App, config.modulePrefix);"
149149

150150
### Limit height
151151

152-
Code content uses `auto` height by default but you can opt to set a `maxHeight` value to save space. Vertical scrolling is enabled as part of this feature allowing users to scroll vertically to view the overflowing content.
152+
Code content uses `auto` height by default but you can opt to set a `maxHeight` value to save space. If the content height exceeds the set max height, vertical scrolling is enabled to view the overflowing content and a toggle button is displayed to expand the height and show the Code Block content in its entirety.
153153

154154
```handlebars
155155
<Hds::CodeBlock
156156
@language="javascript"
157-
@maxHeight="105px"
157+
@maxHeight="130px"
158158
@value="import Application from `@ember/application`;
159159
import Resolver from `ember-resolver`;
160160
import loadInitializers from `ember-load-initializers`;

website/docs/components/code-block/partials/guidelines/guidelines.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ Line numbers are displayed by default and can make longer blocks of code and sni
6969
In the Figma component, the code examples have the appropriate number of lines by default but must be manually hidden or shown to match the length of custom snippets.
7070
!!!
7171

72+
## Height toggle button
73+
74+
When displaying longer code snippets, it can be helpful to let users expand and collapse the content to save space in the UI. Setting a `maxHeight` on the Code Block limits how much is shown by default. If the content exceeds this height, a **Show more code** button will be displayed at the bottom of the block, allowing users to expand it. Interacting with the button again collapses the block back to its original height.
75+
76+
In Figma, this is enabled by setting `hasToggleHeightButton` to true. The button is placed inside a footer element that only appears when the content overflows, keeping the layout clean when the toggle isn’t needed.
77+
78+
![Collapsed Code Block showing limited lines and a 'Show more code' button at the bottom.](/assets/components/code-block/code-block-collapsed.png)
79+
80+
Interacting with this button removes the height limit, expanding the Code Block to display the full code snippet.
81+
82+
![Expanded Code Block with all lines visible and a 'Show less code' button displayed at the bottom](/assets/components/code-block/code-block-expanded.png)
83+
84+
Interacting with it again collapses the Code Block back to its set `maxHeight`.
85+
86+
7287
## Line highlighting
7388

7489
Use line highlighting to target and call attention to specific lines or multiple lines within a block of code.
Loading
Loading

0 commit comments

Comments
 (0)