Skip to content

Commit

Permalink
fix(prop): Update attribute value when setting prop (#1579)
Browse files Browse the repository at this point in the history
Fixes #883
Fixes #927
Fixes #1364
  • Loading branch information
fb55 committed Dec 22, 2020
1 parent c58258f commit db3fce7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/api/attributes.js
Expand Up @@ -120,7 +120,11 @@ var getProp = function (el, name) {
};

var setProp = function (el, name, value) {
el[name] = rboolean.test(name) ? !!value : value;
if (name in el) {
el[name] = value;
} else {
setAttr(el, name, rboolean.test(name) ? (value ? '' : null) : value);
}
};

/**
Expand Down
11 changes: 11 additions & 0 deletions test/api/attributes.js
Expand Up @@ -172,6 +172,17 @@ describe('$(...)', function () {
expect(checkbox.prop('checked')).to.equal(true);
});

it('(key, value) : should update attribute', function () {
expect(checkbox.prop('checked')).to.equal(true);
expect(checkbox.attr('checked')).to.equal('checked');
checkbox.prop('checked', false);
expect(checkbox.prop('checked')).to.equal(false);
expect(checkbox.attr('checked')).to.equal(undefined);
checkbox.prop('checked', true);
expect(checkbox.prop('checked')).to.equal(true);
expect(checkbox.attr('checked')).to.equal('checked');
});

it('(map) : object map should set multiple props', function () {
checkbox.prop({
id: 'check',
Expand Down

0 comments on commit db3fce7

Please sign in to comment.