DOCS-189: Fix Code Snippet bugs when used inside Table component #2373
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Jira
https://pegadigitalit.atlassian.net/browse/DOCS-189
Summary
Fixes Code Snippet bugs when used inside Table component.
Details
Table component strips whitespace around tags and text and in the process rewrites the DOM for every element inside. This breaks indentation on Code Snippets and loses any event handlers added prior to Table initializing.
Long term, Table will be rewritten to not do any of this. Short term, this PR tells Code Snippet to not automatically initialize when inside a Table. Then, tells Table to call the Code Snippet initialization after the Table is rendered.
I had to add Code Snippet as a dependency of Table, which means Code Snippet is loaded whenever a Table is present (not just when a Code Snippet is present). I did a few lighthouse checks and didn't notice any difference before and after.
How to test
http://localhost:3000/pattern-lab/patterns/999-tests-code-snippet-15-code-snippet-table/999-tests-code-snippet-15-code-snippet-table.html
) which shows the use case we're solving for. Verify the Code Snippets are properly indented and the Copy button works.