Skip to content

Commit 81f37ea

Browse files
authored
Merge pull request #2990 from mjmlio/bugfix/MJML-36-mj-column_border_radius
fix(mjml-column): border-radius not working #2989
2 parents 025e3fc + be643a5 commit 81f37ea

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

packages/mjml-column/src/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export default class MjColumn extends BodyComponent {
6868
}
6969

7070
getStyles() {
71+
const hasBorderRadius = this.hasBorderRadius()
72+
const hasInnerBorderRadius = this.hasInnerBorderRadius()
73+
7174
const tableStyle = {
7275
'background-color': this.getAttribute('background-color'),
7376
border: this.getAttribute('border'),
@@ -77,6 +80,7 @@ export default class MjColumn extends BodyComponent {
7780
'border-right': this.getAttribute('border-right'),
7881
'border-top': this.getAttribute('border-top'),
7982
'vertical-align': this.getAttribute('vertical-align'),
83+
...(hasBorderRadius && { 'border-collapse': 'separate' }),
8084
}
8185

8286
return {
@@ -100,6 +104,7 @@ export default class MjColumn extends BodyComponent {
100104
'border-top': this.getAttribute('inner-border-top'),
101105
}
102106
: tableStyle),
107+
...(hasInnerBorderRadius && { 'border-collapse': 'separate' }),
103108
},
104109
tdOutlook: {
105110
'vertical-align': this.getAttribute('vertical-align'),
@@ -202,6 +207,16 @@ export default class MjColumn extends BodyComponent {
202207
return className
203208
}
204209

210+
hasBorderRadius() {
211+
const borderRadius = this.getAttribute('border-radius')
212+
return borderRadius !== '' && typeof borderRadius !== 'undefined'
213+
}
214+
215+
hasInnerBorderRadius() {
216+
const innerBorderRadius = this.getAttribute('inner-border-radius')
217+
return innerBorderRadius !== '' && typeof innerBorderRadius !== 'undefined'
218+
}
219+
205220
hasGutter() {
206221
return [
207222
'padding',
@@ -213,6 +228,8 @@ export default class MjColumn extends BodyComponent {
213228
}
214229

215230
renderGutter() {
231+
const hasBorderRadius = this.hasBorderRadius()
232+
216233
return `
217234
<table
218235
${this.htmlAttributes({
@@ -221,6 +238,9 @@ export default class MjColumn extends BodyComponent {
221238
cellspacing: '0',
222239
role: 'presentation',
223240
width: '100%',
241+
...(hasBorderRadius && {
242+
style: { 'border-collapse': 'separate' },
243+
}),
224244
})}
225245
>
226246
<tbody>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const chai = require('chai')
2+
const { load } = require('cheerio')
3+
const mjml = require('../lib')
4+
5+
describe('mj-column border-radius', function () {
6+
it('should render correct border-radius / inner-border-radius (and border-collapse) in CSS style values on mj-column', function () {
7+
const input = `
8+
<mjml>
9+
<mj-body>
10+
<mj-section>
11+
<mj-column border-radius="50px" inner-border-radius="40px" padding="50px" border="5px solid #000" inner-border="5px solid #666">
12+
<mj-text>Hello World</mj-text>
13+
</mj-column>
14+
</mj-section>
15+
</mj-body>
16+
</mjml>
17+
`
18+
19+
const { html } = mjml(input)
20+
21+
const $ = load(html)
22+
23+
// border radius values should be correct
24+
chai
25+
.expect(
26+
$(
27+
'.mj-column-per-100 > table > tbody > tr > td, .mj-column-per-100 > table > tbody > tr > td > table',
28+
)
29+
.map(function getAttr() {
30+
const start = $(this).attr('style').indexOf('border-radius:') + 14
31+
const end = $(this).attr('style').indexOf(';', start)
32+
return $(this).attr('style').substring(start, end)
33+
})
34+
.get(),
35+
'Border-radius / inner-border-radius in CSS style values on mj-column',
36+
)
37+
.to.eql(['50px', '40px'])
38+
39+
// border collapse values should be correct
40+
chai
41+
.expect(
42+
$(
43+
'.mj-column-per-100 > table > tbody > tr > td, .mj-column-per-100 > table > tbody > tr > td > table',
44+
)
45+
.map(function getAttr() {
46+
const start = $(this).attr('style').indexOf('border-collapse:') + 16
47+
const end = $(this).attr('style').indexOf(';', start)
48+
return $(this).attr('style').substring(start, end)
49+
})
50+
.get(),
51+
'Border-collapse in CSS style values on mj-column',
52+
)
53+
.to.eql(['separate', 'separate'])
54+
})
55+
})

0 commit comments

Comments
 (0)