Skip to content

Commit

Permalink
closes #2454
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Oct 1, 2017
1 parent 95e7992 commit 1422827
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
11 changes: 10 additions & 1 deletion lib/browser/common/util/check.js
Expand Up @@ -60,7 +60,16 @@ export function isString(value) {
* @returns { Boolean } -
*/
export function isBlank(value) {
return isUndefined(value) || value === null || value === ''
return isNil(value) || value === ''
}

/**
* Check against the null and undefined values
* @param { * } value -
* @returns {Boolean} -
*/
export function isNil(value) {
return isUndefined(value) || value === null
}

/**
Expand Down
5 changes: 3 additions & 2 deletions lib/browser/tag/update.js
Expand Up @@ -158,7 +158,8 @@ export function updateExpression(expr) {

// remove original attribute
if (expr.attr && (!expr.isAttrRemoved || !hasValue || value === false)) {
remAttr(dom, expr.attr)
// remove either riot-* attributes or just the attribute name
remAttr(dom, getAttr(dom, expr.attr) ? expr.attr : attrName)
expr.isAttrRemoved = true
}

Expand All @@ -175,7 +176,7 @@ export function updateExpression(expr) {
// if the value is an object we can not do much more with it
if (isObj && !isToggle) return
// avoid to render undefined/null values
if (isBlank(value)) value = ''
if (!hasValue) value = ''

// textarea and text nodes have no attribute name
if (!attrName) {
Expand Down
16 changes: 16 additions & 0 deletions test/specs/browser/riot/core.spec.js
Expand Up @@ -1513,4 +1513,20 @@ describe('Riot core', function() {
expect(tag.refs.foo).to.be.undefined
tag.unmount()
})

it('remove style attributes if they contain blank values', function() {
injectHTML('<riot-tmp></riot-tmp>')

riot.tag('riot-tmp', "<p ref='p' riot-style=\"{changed ? 'background-color: green' : ''}\"></p>", function() {
this.changed = true
})

var tag = riot.mount('riot-tmp')[0]
expect(tag.refs.p.hasAttribute('style')).to.be.ok
tag.changed = false
tag.update()
expect(tag.refs.p.hasAttribute('style')).to.be.not.ok

tag.unmount()
})
})

0 comments on commit 1422827

Please sign in to comment.