From 1035020f0bb70fc9ee96116e38266969c3ec9afa Mon Sep 17 00:00:00 2001 From: Stephen Date: Sat, 19 Oct 2024 23:51:47 +0200 Subject: [PATCH 1/2] Initial value --- modules/element/create-attribute.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/element/create-attribute.js b/modules/element/create-attribute.js index b261611..f8747f1 100644 --- a/modules/element/create-attribute.js +++ b/modules/element/create-attribute.js @@ -15,11 +15,11 @@ function getSignal(element, name, initial) { ); } -export function createAttribute(name, parse = id) { +export function createAttribute(name, initial, parse = id) { return { attribute: function(value) { const signal = getSignal(this, name); - signal.value = parse(value); + signal.value = value === null ? initial : parse(value) ; } }; } From 690e082bc1e9bbdee67a058b1607f16f33181b8e Mon Sep 17 00:00:00 2001 From: Stephen Date: Sun, 20 Oct 2024 02:57:53 +0200 Subject: [PATCH 2/2] createNumberAttribute(name, initial, min, max, parse) --- modules/element/create-attribute.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/element/create-attribute.js b/modules/element/create-attribute.js index f8747f1..f905777 100644 --- a/modules/element/create-attribute.js +++ b/modules/element/create-attribute.js @@ -43,7 +43,7 @@ export function createProperty(name, initial, parse = id) { export function createAttributeProperty(name, initial, parse = id) { return assign(createProperty(name, initial, parse), { attribute: function(value) { - this[name] = value === null ? undefined : value ; + this[name] = value === null ? undefined : value.trim() ; } }); } @@ -68,8 +68,8 @@ export function createStringAttribute(name, parse = id) { }); } -export function createNumberAttribute(name, min, max, parse = id) { - return createAttrProp(name, 0, (value) => { +export function createNumberAttribute(name, initial, min, max, parse = id) { + return createAttrProp(name, initial, (value) => { const number = parse(value); if (Number.isNaN(number)) {