Skip to content

Commit 3dba094

Browse files
authored
fix(jsx-email): border not showing up in outlook using withBackground (#278)
1 parent 7c9e5e7 commit 3dba094

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

packages/jsx-email/src/components/button.tsx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,6 @@ export const Button: JsxEmailComponent<ButtonProps> = ({
6969
...(textColor ? { color: textColor } : {})
7070
};
7171

72-
const baseButton = (
73-
<a
74-
href={href}
75-
style={{
76-
...baseStyles,
77-
...propStyles,
78-
...style,
79-
...(withBackground ? {} : { msoHide: 'all' })
80-
}}
81-
{...props}
82-
>
83-
{children}
84-
</a>
85-
);
86-
8772
return (
8873
<table
8974
{...debugProps}
@@ -123,6 +108,10 @@ export const Button: JsxEmailComponent<ButtonProps> = ({
123108
cellPadding={0}
124109
cellSpacing={0}
125110
role="presentation"
111+
style={{
112+
border: `${borderSize ?? '0'}px solid ${borderColor ?? 'inherit'}`,
113+
borderRadius
114+
}}
126115
>
127116
<tr>
128117
<td
@@ -138,12 +127,35 @@ export const Button: JsxEmailComponent<ButtonProps> = ({
138127
width
139128
}}
140129
>
141-
{baseButton}
130+
<a
131+
href={href}
132+
style={{
133+
...baseStyles,
134+
...(backgroundColor ? { backgroundColor } : {}),
135+
...(textColor ? { color: textColor } : {}),
136+
...style,
137+
...(withBackground ? {} : { msoHide: 'all' })
138+
}}
139+
{...props}
140+
>
141+
{children}
142+
</a>
142143
</td>
143144
</tr>
144145
</table>
145146
) : (
146-
baseButton
147+
<a
148+
href={href}
149+
style={{
150+
...baseStyles,
151+
...propStyles,
152+
...style,
153+
...(withBackground ? {} : { msoHide: 'all' })
154+
}}
155+
{...props}
156+
>
157+
{children}
158+
</a>
147159
)}
148160
</td>
149161
</tr>

packages/jsx-email/test/.snapshots/button.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ exports[`<Button> component > renders correctly when nested in <Background> 1`]
44
"<table cellPadding=\\"0\\" cellSpacing=\\"0\\" border=\\"0\\" width=\\"100%\\" role=\\"presentation\\"><tr><td valign=\\"top\\" background=\\"link-to-image\\" style=\\"background-repeat:no-repeat\\"><jsx-email-cond>
55
<!--[if gte mso 9]>
66
<v:rect xmlns:v=\\"urn:schemas-microsoft-com:vml\\" fill=\\"true\\" stroke=\\"false\\" style=\\"mso-width-percent:1000;\\"><v:fill type=\\"frame\\" src=\\"link-to-image\\" /><v:textbox style=\\"mso-fit-shape-to-text:true\\" inset=\\"0,0,0,0\\"><![endif]-->
7-
<div><table width=\\"100%\\" border=\\"0\\" cellPadding=\\"0\\" cellSpacing=\\"0\\" style=\\"border-collapse:collapse\\" role=\\"presentation\\"><tr><td align=\\"left\\"><table align=\\"left\\" width=\\"200\\" border=\\"0\\" cellPadding=\\"0\\" cellSpacing=\\"0\\" role=\\"presentation\\"><tr><td bgcolor=\\"#cccccc\\" width=\\"200\\" height=\\"40\\" style=\\"border-radius:0;height:40px;max-width:200px;text-align:center;width:200px\\"><a href=\\"https://example.com\\" style=\\"-webkit-text-size-adjust:none;border-radius:0;display:inline-block;font-size:16px;line-height:38px;max-width:200px;text-align:center;text-decoration:none;width:100%;background-color:#cccccc;padding:12px 20px\\"></a></td></tr></table></td></tr></table></div>
7+
<div><table width=\\"100%\\" border=\\"0\\" cellPadding=\\"0\\" cellSpacing=\\"0\\" style=\\"border-collapse:collapse\\" role=\\"presentation\\"><tr><td align=\\"left\\"><table align=\\"left\\" width=\\"200\\" border=\\"0\\" cellPadding=\\"0\\" cellSpacing=\\"0\\" role=\\"presentation\\" style=\\"border:1px solid inherit;border-radius:0\\"><tr><td bgcolor=\\"#cccccc\\" width=\\"200\\" height=\\"40\\" style=\\"border-radius:0;height:40px;max-width:200px;text-align:center;width:200px\\"><a href=\\"https://example.com\\" style=\\"-webkit-text-size-adjust:none;border-radius:0;display:inline-block;font-size:16px;line-height:38px;max-width:200px;text-align:center;text-decoration:none;width:100%;background-color:#cccccc;padding:12px 20px\\"></a></td></tr></table></td></tr></table></div>
88
<!--[if gte mso 9]></v:textbox></v:rect><![endif]--></jsx-email-cond></td></tr></table>"
99
`;

0 commit comments

Comments
 (0)