Skip to content

Commit 4ad22e6

Browse files
committed
Fix: Line wrapping with long string
1 parent 5dfc2ae commit 4ad22e6

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

packages/components/src/styles/components/code-block/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ $hds-code-block-code-footer-height: 48px;
5555
.hds-code-block--has-line-wrapping {
5656
.hds-code-block__code,
5757
.hds-code-block__code code {
58+
display: block;
5859
white-space: pre-wrap;
5960
overflow-wrap: break-word;
6061
}

showcase/app/templates/components/code-block.hbs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ function assertObjectsEqual (actual, expected, testName) {
260260
{{! template-lint-enable no-whitespace-for-layout }}
261261
</SG.Item>
262262

263-
<SG.Item @label="maxHeight='130px', title, description, and copy button" @forceMinWidth={{true}}>
263+
<SG.Item
264+
@label="maxHeight='130px', title, description, and copy button, highlight lines 4 & 10"
265+
@forceMinWidth={{true}}
266+
>
264267
{{! template-lint-disable no-whitespace-for-layout }}
265268
<Hds::CodeBlock
266269
@language="javascript"
@@ -294,6 +297,38 @@ function assertObjectsEqual (actual, expected, testName) {
294297
{{! template-lint-enable no-whitespace-for-layout }}
295298
</SG.Item>
296299

300+
<SG.Item @label="maxHeight='130px', hasLineWrapping=true, highlight line 2" @forceMinWidth={{true}}>
301+
{{! template-lint-disable no-whitespace-for-layout }}
302+
<Hds::CodeBlock
303+
@language="javascript"
304+
@maxHeight="130px"
305+
@hashasLineNumbers={{true}}
306+
@hasLineWrapping={{true}}
307+
@highlightLines="2"
308+
@value="function convertObjectToArray (obj) {
309+
let codeLang='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam';
310+
let arr = Object
311+
.keys(obj) // return object's keys as an array
312+
.map(key => {return [key, obj[key] ]}) // map a function on each array item
313+
.flat()
314+
.sort()
315+
;
316+
return arr;
317+
}
318+
function assertObjectsEqual (actual, expected, testName) {
319+
let actualStr = JSON.stringify( convertObjectToArray(actual) );
320+
let expectedStr = JSON.stringify( convertObjectToArray(expected) );
321+
console.log(`ACTUAL: ${actualStr} EXPECTED: ${expectedStr}`);
322+
if (actualStr === expectedStr) {
323+
console.log('passed');
324+
} else {
325+
console.log(`FAILED [${testName}] Expected ${JSON.stringify(expected)}, but got ${JSON.stringify(actual)}`);
326+
}
327+
}"
328+
/>
329+
{{! template-lint-enable no-whitespace-for-layout }}
330+
</SG.Item>
331+
297332
<SG.Item @label="maxHeight='130px, hasLineNumbers=false" @forceMinWidth={{true}}>
298333
{{! template-lint-disable no-whitespace-for-layout }}
299334
<Hds::CodeBlock

0 commit comments

Comments
 (0)