From 5e13f04e3cf98ee462c41dd7feb0c9d732dcb9b3 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Fri, 30 Oct 2020 10:22:39 -0700 Subject: [PATCH] docs(code-snippet): add examples for dynnamic, hidden code snippets --- docs/src/pages/components/CodeSnippet.svx | 14 +++++++ .../CodeSnippet/DynamicCodeSnippet.svelte | 15 ++++++++ .../CodeSnippet/HiddenCodeSnippet.svelte | 38 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 docs/src/pages/framed/CodeSnippet/DynamicCodeSnippet.svelte create mode 100644 docs/src/pages/framed/CodeSnippet/HiddenCodeSnippet.svelte 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} +
+
+