Skip to content

Commit 025e3fc

Browse files
authored
Merge pull request #2992 from mjmlio/bugfix/MJML-37-mj-navbar_ico-padding-x
fix(mjml-navbar): ico-padding-x not working #2991
2 parents 424cac8 + 494c1b2 commit 025e3fc

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

packages/mjml-navbar/src/Navbar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ export default class MjNavbar extends BodyComponent {
8181
'text-transform': this.getAttribute('ico-text-transform'),
8282
'text-decoration': this.getAttribute('ico-text-decoration'),
8383
'line-height': this.getAttribute('ico-line-height'),
84+
padding: this.getAttribute('ico-padding'),
8485
'padding-top': this.getAttribute('ico-padding-top'),
8586
'padding-right': this.getAttribute('ico-padding-right'),
8687
'padding-bottom': this.getAttribute('ico-padding-bottom'),
8788
'padding-left': this.getAttribute('ico-padding-left'),
88-
padding: this.getAttribute('ico-padding'),
8989
},
9090
trigger: {
9191
display: 'none',
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const chai = require('chai')
2+
const { load } = require('cheerio')
3+
const mjml = require('../lib')
4+
5+
describe('mj-navbar ico-padding-X', function () {
6+
it('should render correct padding in CSS style values on navbar hamburger icon', function () {
7+
const input = `
8+
<mjml>
9+
<mj-body>
10+
<mj-section>
11+
<mj-column>
12+
<mj-navbar hamburger="hamburger" ico-padding="20px" ico-padding-bottom="20px" ico-padding-left="30px" ico-padding-right="40px" ico-padding-top="50px" >
13+
<mj-navbar-link href="/gettings-started-onboard" color="#ffffff">Getting started</mj-navbar-link>
14+
<mj-navbar-link href="/try-it-live" color="#ffffff">Try it live</mj-navbar-link>
15+
</mj-navbar>
16+
</mj-column>
17+
</mj-section>
18+
</mj-body>
19+
</mjml>
20+
`
21+
22+
const { html } = mjml(input)
23+
const $ = load(html)
24+
25+
function extractPadding(style, prop) {
26+
const start = style.indexOf(`${prop}:`) + prop.length + 1
27+
const end = style.indexOf(';', start)
28+
return style.substring(start, end).trim()
29+
}
30+
31+
const paddings = [
32+
'padding-bottom',
33+
'padding-left',
34+
'padding-right',
35+
'padding-top',
36+
]
37+
38+
const results = paddings.map((padding) =>
39+
$('.mj-menu-label')
40+
.map(function () {
41+
const style = $(this).attr('style')
42+
return extractPadding(style, padding)
43+
})
44+
.get(),
45+
)
46+
47+
// Padding should be ['20px', '30px', '40px', '50px']
48+
const expected = {
49+
'padding-bottom': ['20px'],
50+
'padding-left': ['30px'],
51+
'padding-right': ['40px'],
52+
'padding-top': ['50px'],
53+
}
54+
55+
paddings.forEach((padding, idx) => {
56+
chai
57+
.expect(results[idx], `${padding} in CSS style values on navbar icon`)
58+
.to.eql(expected[padding])
59+
})
60+
})
61+
})

0 commit comments

Comments
 (0)