Skip to content

Commit ed5c901

Browse files
committed
fix: no undefined class name used at MarkdownContent if no custom class name was provided
Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
1 parent 16ef9e5 commit ed5c901

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

.changeset/lemon-months-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@backstage/core-components': patch
3+
---
4+
5+
No `undefined` class name used at `MarkdownContent` if no custom class name was provided.

packages/core-components/src/components/MarkdownContent/MarkdownContent.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,36 @@ describe('<MarkdownContent />', () => {
4545
).toBeInTheDocument();
4646
});
4747

48+
it('Render MarkdownContent component without custom class', async () => {
49+
await renderInTestApp(
50+
<MarkdownContent content="https://example.com" dialect="common-mark" />,
51+
);
52+
const content = screen.getByText('https://example.com', { selector: 'p' });
53+
54+
expect(
55+
Array.from(content.parentElement?.classList?.values() ?? []).map(cls =>
56+
cls.replace(/-\d+$/, ''),
57+
),
58+
).toEqual(['BackstageMarkdownContent-markdown']);
59+
});
60+
61+
it('Render MarkdownContent component with custom class', async () => {
62+
await renderInTestApp(
63+
<MarkdownContent
64+
content="https://example.com"
65+
dialect="common-mark"
66+
className="custom-class"
67+
/>,
68+
);
69+
const content = screen.getByText('https://example.com', { selector: 'p' });
70+
71+
expect(
72+
Array.from(content.parentElement?.classList?.values() ?? []).map(cls =>
73+
cls.replace(/-\d+$/, ''),
74+
),
75+
).toEqual(['BackstageMarkdownContent-markdown', 'custom-class']);
76+
});
77+
4878
it('render MarkdownContent component with CodeSnippet for code blocks', async () => {
4979
await renderInTestApp(
5080
<MarkdownContent content={'```typescript\njest(test: string);\n```'} />,

packages/core-components/src/components/MarkdownContent/MarkdownContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function MarkdownContent(props: Props) {
127127
return (
128128
<ReactMarkdown
129129
remarkPlugins={dialect === 'gfm' ? [gfm] : []}
130-
className={`${classes.markdown} ${className}`}
130+
className={`${classes.markdown} ${className ?? ''}`.trim()}
131131
children={content}
132132
components={components}
133133
linkTarget={linkTarget}

0 commit comments

Comments
 (0)