Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature to add anchor attribute to core/paragraph block #2015

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/popular-glasses-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@faustwp/blocks': major
theodesp marked this conversation as resolved.
Show resolved Hide resolved
---

Update of the CoreParagraph block to support the native WP anchor attribute. GitHub issue: "[[feat] Add anchor attribute to core/paragraph block](https://github.com/wpengine/faustjs/issues/1954)"
2 changes: 1 addition & 1 deletion packages/blocks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@faustwp/blocks",
"version": "5.0.0",
"version": "5.1.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a patch version instead. We are not breaking anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @theodesp, I was just trying to follow semver that, if I understand correctly, patch bumps are meant for backwards-compatible bug fixes, and minor bumps are for backwards-compatible new feature releases. I naturally considered this a new feature as it was adding functionality, but it could have been considered a fix as well. Do you want me to change it to version 5.0.1 instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jan-clockworkwp .I thin with a major change it should be 6.0.0 since we change the schema. We should update the changeset document to mention the nature of the change though.

"description": "Faust Blocks",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
Expand Down
3 changes: 3 additions & 0 deletions packages/blocks/src/blocks/CoreParagraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type CoreParagraphFragmentProps = ContentBlock & {
dropCap?: string;
gradient?: string;
align?: string;
anchor?: string;
};
};

Expand All @@ -30,6 +31,7 @@ export function CoreParagraph(props: CoreParagraphFragmentProps) {
<p
style={style}
className={attributes?.cssClassName}
id={attributes?.anchor}
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: attributes?.content ?? '' }}
/>
Expand All @@ -52,6 +54,7 @@ CoreParagraph.fragments = {
dropCap
gradient
align
anchor
}
}
`,
Expand Down
16 changes: 16 additions & 0 deletions packages/blocks/tests/blocks/CoreParagraph.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,20 @@ describe('<CoreParagraph />', () => {
</p>
`);
});

test('applies the HTML anchor attribute properly', () => {
renderProvider({
attributes: {
anchor: 'test-anchor',
content: 'Hello World',
},
});
expect(screen.queryByText('Hello World')).toMatchInlineSnapshot(`
<p
id="test-anchor"
>
Hello World
</p>
`);
});
});
Loading