Skip to content

Commit 9bac7c6

Browse files
authored
Merge pull request #3002 from mjmlio/bugfix/MJML-41-mj-social_align_icon-height
fix(mjml-social): align / icon-height #3001
2 parents 4a088b6 + cd5f25a commit 9bac7c6

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

packages/mjml-social/src/SocialElement.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export default class MjSocialElement extends BodyComponent {
181181
tdText: {
182182
'vertical-align': 'middle',
183183
padding: this.getAttribute('text-padding'),
184+
'text-align': this.getAttribute('align'),
184185
},
185186
text: {
186187
color: this.getAttribute('color'),
@@ -230,7 +231,6 @@ export default class MjSocialElement extends BodyComponent {
230231
sizes,
231232
href,
232233
'icon-size': iconSize,
233-
'icon-height': iconHeight,
234234
} = this.getSocialAttributes()
235235

236236
const hasLink = !!this.getAttribute('href')
@@ -263,7 +263,6 @@ export default class MjSocialElement extends BodyComponent {
263263
${this.htmlAttributes({
264264
alt: this.getAttribute('alt'),
265265
title: this.getAttribute('title'),
266-
height: parseInt(iconHeight || iconSize, 10),
267266
src,
268267
style: 'img',
269268
width: parseInt(iconSize, 10),
@@ -315,7 +314,7 @@ export default class MjSocialElement extends BodyComponent {
315314
class: this.getAttribute('css-class'),
316315
})}
317316
>
318-
${iconPosition === 'left' ? renderLeft() : renderRight() }
317+
${iconPosition === 'left' ? renderLeft() : renderRight()}
319318
</tr>
320319
`
321320
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const chai = require('chai')
2+
const { load } = require('cheerio')
3+
const mjml = require('../lib')
4+
5+
describe('mj-social-element align', function () {
6+
it('should render correct align in CSS style values on mj-social-element', function () {
7+
const input = `
8+
<mjml>
9+
<mj-body>
10+
<mj-section>
11+
<mj-column>
12+
<mj-social mode="vertical">
13+
<mj-social-element name="facebook" href="https://mjml.io/" icon-position="right" align="right"css-class="my-social-element">
14+
Facebook
15+
</mj-social-element>
16+
</mj-social>
17+
</mj-column>
18+
</mj-section>
19+
</mj-body>
20+
</mjml>
21+
`
22+
23+
const { html } = mjml(input)
24+
25+
const $ = load(html)
26+
27+
// align values should be correct
28+
chai
29+
.expect(
30+
$('.my-social-element > td:first-child')
31+
.map(function getAttr() {
32+
const start = $(this).attr('style').indexOf('text-align:') + 11
33+
const end = $(this).attr('style').indexOf(';', start)
34+
return $(this).attr('style').substring(start, end)
35+
})
36+
.get(),
37+
'align values on social elements',
38+
)
39+
.to.eql(['right'])
40+
})
41+
})
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const chai = require('chai')
2+
const { load } = require('cheerio')
3+
const mjml = require('../lib')
4+
5+
describe('mj-social icon-height', function () {
6+
it('should render correct icon-height align in CSS style values on mj-social', function () {
7+
const input = `
8+
<mjml>
9+
<mj-body>
10+
<mj-section>
11+
<mj-column css-class="my-social-element">
12+
<mj-social icon-height="40px">
13+
<mj-social-element name="facebook" href="https://mjml.io/" css-class="my-social-element">
14+
Facebook
15+
</mj-social-element>
16+
</mj-social>
17+
</mj-column>
18+
</mj-section>
19+
</mj-body>
20+
</mjml>
21+
`
22+
23+
const { html } = mjml(input)
24+
25+
const $ = load(html)
26+
27+
// height values should be correct
28+
chai
29+
.expect(
30+
$('.my-social-element > td > table > tbody > tr > td')
31+
.map(function getAttr() {
32+
const start = $(this).attr('style').indexOf('height:') + 7
33+
const end = $(this).attr('style').indexOf(';', start)
34+
return $(this).attr('style').substring(start, end)
35+
})
36+
.get(),
37+
'icon-height values on social elements',
38+
)
39+
.to.eql(['40px'])
40+
41+
chai
42+
.expect(
43+
$('.my-social-element > td > table > tbody > tr > td img')
44+
.map(function getAttr() {
45+
return $(this).attr('height')
46+
})
47+
.get(),
48+
)
49+
.to.satisfy((arr) => arr.every((val) => !val))
50+
})
51+
})

0 commit comments

Comments
 (0)