Skip to content

Commit e94b3b9

Browse files
committed
avoid duplicate classes during transclusion (fix #1806)
1 parent ad78e60 commit e94b3b9

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/compiler/transclude.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ function mergeAttrs (from, to) {
141141
if (!to.hasAttribute(name) && !specialCharRE.test(name)) {
142142
to.setAttribute(name, value)
143143
} else if (name === 'class') {
144-
value = to.getAttribute(name) + ' ' + value
145-
to.setAttribute(name, value)
144+
value.split(/\s+/).forEach(function (cls) {
145+
_.addClass(to, cls)
146+
})
146147
}
147148
}
148149
}

test/unit/specs/compiler/transclude_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ if (_.inBrowser) {
112112
})
113113

114114
it('replacer attr should overwrite container attr of same name, except class should be merged', function () {
115-
el.setAttribute('class', 'test')
115+
el.setAttribute('class', 'test other')
116116
el.setAttribute('title', 'parent')
117-
options.template = '<div class="other" title="child"></div>'
117+
options.template = '<div class="other ok" title="child"></div>'
118118
options.replace = true
119119
options._asComponent = true
120120
var res = transclude(el, options)
121-
expect(res.getAttribute('class')).toBe('other test')
121+
expect(res.getAttribute('class')).toBe('other ok test')
122122
expect(res.getAttribute('title')).toBe('child')
123123
})
124124

0 commit comments

Comments
 (0)