Skip to content

Commit 99b5793

Browse files
Feature to add anchor attribute to core/paragraph block (#2015)
* [feat] Add anchor attribute to core/paragraph block * Added test for Core/Paragraph block * chore: changeset message update, package version boost v6.0.0
1 parent bdb7d7f commit 99b5793

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@faustwp/blocks': major
3+
---
4+
5+
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)"
6+
7+
Introduces new field to `core/paragraph` block: `anchor`. This field allows users to add an anchor to the paragraph block. The anchor is used to create a link to a specific part of the page. The anchor is added to the block's wrapper element as an ID attribute.
8+
9+
**Files changed:**
10+
- packages/blocks/src/blocks/CoreParagraph.tsx (added anchor attribute)
11+
- packages/blocks/package.json (updated package version to 6.0.0)

packages/blocks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@faustwp/blocks",
3-
"version": "5.0.0",
3+
"version": "6.0.0",
44
"description": "Faust Blocks",
55
"main": "dist/cjs/index.js",
66
"module": "dist/mjs/index.js",

packages/blocks/src/blocks/CoreParagraph.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type CoreParagraphFragmentProps = ContentBlock & {
1919
dropCap?: string;
2020
gradient?: string;
2121
align?: string;
22+
anchor?: string;
2223
};
2324
};
2425

@@ -30,6 +31,7 @@ export function CoreParagraph(props: CoreParagraphFragmentProps) {
3031
<p
3132
style={style}
3233
className={attributes?.cssClassName}
34+
id={attributes?.anchor}
3335
// eslint-disable-next-line react/no-danger
3436
dangerouslySetInnerHTML={{ __html: attributes?.content ?? '' }}
3537
/>
@@ -52,6 +54,7 @@ CoreParagraph.fragments = {
5254
dropCap
5355
gradient
5456
align
57+
anchor
5558
}
5659
}
5760
`,

packages/blocks/tests/blocks/CoreParagraph.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,20 @@ describe('<CoreParagraph />', () => {
4242
</p>
4343
`);
4444
});
45+
46+
test('applies the HTML anchor attribute properly', () => {
47+
renderProvider({
48+
attributes: {
49+
anchor: 'test-anchor',
50+
content: 'Hello World',
51+
},
52+
});
53+
expect(screen.queryByText('Hello World')).toMatchInlineSnapshot(`
54+
<p
55+
id="test-anchor"
56+
>
57+
Hello World
58+
</p>
59+
`);
60+
});
4561
});

0 commit comments

Comments
 (0)