Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8fef98

Browse files
committed
Falsey attributes
1 parent cf041a6 commit b8fef98

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

hyperapp.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface Component<Attributes = {}> {
2424
/**
2525
* Possibles children types
2626
*/
27-
export type Children = VNode | string | number | null;
27+
export type Children = VNode | string | number | null
2828

2929
/** The soft way to create a VNode.
3030
* @param name An element name or a Component function
@@ -37,7 +37,7 @@ export type Children = VNode | string | number | null;
3737
export function h<Attributes>(
3838
nodeName: Component<Attributes> | string,
3939
attributes?: Attributes,
40-
...children: Array<Children | Children[]>,
40+
...children: Array<Children | Children[]>
4141
): VNode<Attributes>
4242

4343
/** @namespace [App] */

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ export function app(state, actions, view, container) {
166166
element.removeEventListener(name, eventListener)
167167
}
168168
} else if (name in element && name !== "list" && !isSvg) {
169-
element[name] = value == null ? "" : value
169+
element[name] =
170+
value == null ||
171+
value === "false" ||
172+
value === "off" ||
173+
value === "no"
174+
? ""
175+
: value
170176
} else if (value != null && value !== false) {
171177
element.setAttribute(name, value)
172178
}

test/dom.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,3 +652,10 @@ testVdomToHtml("events", [
652652
html: `<button id="clicked"></button>`
653653
}
654654
])
655+
656+
testVdomToHtml("falsey attributes", [
657+
{
658+
vdom: <input spellcheck="false" autocomplete="off" translate="no" />,
659+
html: `<input spellcheck="false" autocomplete="off" translate="no">`
660+
}
661+
])

0 commit comments

Comments
 (0)