Skip to content

Commit

Permalink
fix(react): simple elements not rendering (#45)
Browse files Browse the repository at this point in the history
Co-authored-by: João Pedro Schmitz <oi@joaopedro.cc>
  • Loading branch information
nrandell and jpedroschmitz authored Oct 19, 2021
1 parent de02591 commit 5dd9acb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/late-spiders-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphcms/rich-text-react-renderer": patch
---

fix(react): simple elements are not empty
2 changes: 1 addition & 1 deletion packages/react-renderer/src/util/elementIsEmpty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export function elementIsEmpty({
return hasText.length > 0 ? false : true;
} else if (children[0].text === '') return true;

return true;
return false;
}
13 changes: 13 additions & 0 deletions packages/react-renderer/test/RichText.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
inlineContent,
emptyContent,
embedAssetContent,
simpleH1Content,
} from './content';

describe('@graphcms/rich-text-react-renderer', () => {
Expand Down Expand Up @@ -99,6 +100,18 @@ describe('@graphcms/rich-text-react-renderer', () => {
`);
});

it('should should render H1 with some text', () => {
const { container } = render(<RichText content={simpleH1Content} />);

expect(container).toMatchInlineSnapshot(`
<div>
<h1>
heading
</h1>
</div>
`);
});

it('renders content with custom elements', () => {
const { container } = render(
<RichText
Expand Down
11 changes: 11 additions & 0 deletions packages/react-renderer/test/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ export const emptyContent: RichTextContent = [
},
];

export const simpleH1Content: RichTextContent = [
{
type: 'heading-one',
children: [
{
text: 'heading',
},
],
},
];

export const inlineContent: RichTextContent = [
{
type: 'paragraph',
Expand Down

0 comments on commit 5dd9acb

Please sign in to comment.