Skip to content

Commit

Permalink
code
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Jan 13, 2025
1 parent 10c9e2f commit cbddad7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-birds-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kitajs/html': patch
---

Allow undefined in style attributes
8 changes: 4 additions & 4 deletions packages/html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ function attributesToString(attributes) {
// @ts-expect-error - this indexing is safe.
value = attributes[key];

if (value === null || value === undefined) {
continue;
}

// React className compatibility.
if (key === 'className') {
// @ts-expect-error - both were provided, so use the class attribute.
Expand Down Expand Up @@ -317,10 +321,6 @@ function attributesToString(attributes) {
continue;
}

if (value === null || value === undefined) {
continue;
}

result += ' ' + key;

if (type !== 'string') {
Expand Down
9 changes: 9 additions & 0 deletions packages/html/test/style.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ describe('Style', () => {
);
});

test('accepts undefined', () => {
assert.equal(
<div style={{ backgroundColor: undefined }}></div>,
'<div style=""></div>'
);

assert.equal(<div style={undefined}></div>, '<div></div>');
});

test('CSSProperties', () => {
const style: JSX.CSSProperties = {
color: 'red',
Expand Down

0 comments on commit cbddad7

Please sign in to comment.