diff --git a/docs/src/pages/components/CodeSnippet.svx b/docs/src/pages/components/CodeSnippet.svx index 0eaffda1..fb0a6bbc 100644 --- a/docs/src/pages/components/CodeSnippet.svx +++ b/docs/src/pages/components/CodeSnippet.svx @@ -51,6 +51,20 @@ let comment = ` +### Dynamic multi-line code + +For dynamically updated code, you must use the `code` prop instead of the default slot. + + + +### Hidden multi-line code + +There may be cases where your code snippet is visually hidden. The logic to render the "Show more" button relies on the element's computed height. For visually hidden content, the button will not appear because the height is `0`. + +The recommended workaround is to re-render the component. See the example below. + + + ### Skeleton The default skeleton type is `"single"`. diff --git a/docs/src/pages/framed/CodeSnippet/DynamicCodeSnippet.svelte b/docs/src/pages/framed/CodeSnippet/DynamicCodeSnippet.svelte new file mode 100644 index 00000000..30332096 --- /dev/null +++ b/docs/src/pages/framed/CodeSnippet/DynamicCodeSnippet.svelte @@ -0,0 +1,15 @@ + + + + diff --git a/docs/src/pages/framed/CodeSnippet/HiddenCodeSnippet.svelte b/docs/src/pages/framed/CodeSnippet/HiddenCodeSnippet.svelte new file mode 100644 index 00000000..29987a3c --- /dev/null +++ b/docs/src/pages/framed/CodeSnippet/HiddenCodeSnippet.svelte @@ -0,0 +1,38 @@ + + + + + + + +
+ +

Tab 2 contains a multi-line code snippet.

+

+ Inactive tab content is visually hidden but still rendered in the DOM. + As a result, the "Show more" button will not appear because the computed + height of the code element is 0. +

+

+ To work around this, you can force the code snippet to be re-rendered + when the tab content is active. +

+
+ +

The "Show more" button should appear.

+ {#if selected === 1} + + {/if} +
+
+