Skip to content

Commit 6cd353b

Browse files
authored
fix(text): User's style not having priority (#2211)
1 parent dcb8164 commit 6cd353b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

.changeset/curly-cameras-ask.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-email/text": patch
3+
---
4+
5+
give priority to the user's style

packages/text/src/text.spec.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ describe('<Text> component', () => {
88
expect(html).toContain(testMessage);
99
});
1010

11+
it("gives priority to the user's style", async () => {
12+
const style = { marginTop: '0px' };
13+
const html = await render(<Text style={style} />);
14+
expect(html).toContain('margin-top:0px');
15+
});
16+
1117
it('passes style and other props correctly', async () => {
1218
const style = { fontSize: '16px' };
1319
const html = await render(

packages/text/src/text.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ export type TextProps = Readonly<React.ComponentPropsWithoutRef<'p'>>;
55

66
export const Text = React.forwardRef<HTMLParagraphElement, TextProps>(
77
({ style, ...props }, ref) => {
8-
const modifiedStyle = { ...style };
8+
let modifiedStyle: React.CSSProperties = {};
99
if (modifiedStyle.marginBottom === undefined) {
1010
modifiedStyle.marginBottom = '16px';
1111
}
1212
if (modifiedStyle.marginTop === undefined) {
1313
modifiedStyle.marginTop = '16px';
1414
}
15+
modifiedStyle = { ...modifiedStyle, ...style };
1516
const margins = computeMargins(modifiedStyle);
1617

1718
return (

0 commit comments

Comments
 (0)