Skip to content
Open
Show file tree
Hide file tree
Changes from all 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/named-destination-left-coordinate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@react-pdf/render': patch
---

fix(render): specify the left coordinate in named destinations so internal links navigate in macOS Preview
2 changes: 1 addition & 1 deletion packages/render/src/operations/setDestination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const setDestination = (ctx: Context, node: SafeNode) => {
if (!node.props) return;

if ('id' in node.props) {
ctx.addNamedDestination(node.props.id!, 'XYZ', null, node.box.top, null);
ctx.addNamedDestination(node.props.id!, 'XYZ', node.box.left ?? 0, node.box.top, null);
}
};

Expand Down
14 changes: 14 additions & 0 deletions packages/render/tests/operations/setDestination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ describe('operations setDestination', () => {

expect(ctx.addNamedDestination.mock.calls).toHaveLength(1);
expect(ctx.addNamedDestination.mock.calls[0][0]).toBe('test');
expect(ctx.addNamedDestination.mock.calls[0][2]).toBe(0);
expect(ctx.addNamedDestination.mock.calls[0][3]).toBe(20);
});

test('should pass the node left coordinate as the destination left', () => {
const ctx = createCTX();
const box = { top: 20, left: 15 };
const props = { id: 'test' };
const doc = { type: P.View, style: {}, props, box } as SafeNode;

setDestination(ctx, doc);

expect(ctx.addNamedDestination.mock.calls).toHaveLength(1);
expect(ctx.addNamedDestination.mock.calls[0][2]).toBe(15);
expect(ctx.addNamedDestination.mock.calls[0][3]).toBe(20);
});

Expand Down