mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] blockdom: properly handle falsy attributes
This commit fixes some issues with falsy attributes not being properly set/removed in various situations. Also, the behaviour was not consistent between normal attribute (key/value) and generic attributes (pair or object)
This commit is contained in:
committed by
Aaron Bohy
parent
983b9f996d
commit
e2819323ee
@@ -1,6 +1,6 @@
|
||||
import type { Setter } from "./block_compiler";
|
||||
|
||||
const { setAttribute, removeAttribute } = Element.prototype;
|
||||
const { setAttribute: elemSetAttribute, removeAttribute } = Element.prototype;
|
||||
const tokenList = DOMTokenList.prototype;
|
||||
const tokenListAdd = tokenList.add;
|
||||
const tokenListRemove = tokenList.remove;
|
||||
@@ -14,11 +14,23 @@ const wordRegexp = /\s+/;
|
||||
* file.
|
||||
*/
|
||||
|
||||
function setAttribute(this: HTMLElement, key: string, value: any) {
|
||||
switch (value) {
|
||||
case false:
|
||||
case undefined:
|
||||
removeAttribute.call(this, key);
|
||||
break;
|
||||
case true:
|
||||
elemSetAttribute.call(this, key, "");
|
||||
break;
|
||||
default:
|
||||
elemSetAttribute.call(this, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
export function createAttrUpdater(attr: string): Setter<HTMLElement> {
|
||||
return function (this: HTMLElement, value: any) {
|
||||
if (value !== false && value !== undefined) {
|
||||
setAttribute.call(this, attr, value === true ? "" : value);
|
||||
}
|
||||
setAttribute.call(this, attr, value);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user