Skip to content

Commit

Permalink
fix(core): support popover boolean attribute (#4393)
Browse files Browse the repository at this point in the history
* support popover boolean attribute

* Update render.test.js

Co-authored-by: Ryan Christian <33403762+rschristian@users.noreply.github.com>

* Update props.js

Co-authored-by: Ryan Christian <33403762+rschristian@users.noreply.github.com>

---------

Co-authored-by: Ryan Christian <33403762+rschristian@users.noreply.github.com>
  • Loading branch information
JoviDeCroock and rschristian authored May 22, 2024
1 parent 85bed33 commit b7c43d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/diff/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export function setProperty(dom, name, value, oldValue, namespace) {
name != 'rowSpan' &&
name != 'colSpan' &&
name != 'role' &&
name != 'popover' &&
name in dom
) {
try {
Expand All @@ -135,7 +136,7 @@ export function setProperty(dom, name, value, oldValue, namespace) {
if (typeof value == 'function') {
// never serialize functions as attribute values
} else if (value != null && (value !== false || name[4] === '-')) {
dom.setAttribute(name, value);
dom.setAttribute(name, name == 'popover' && value == true ? '' : value);
} else {
dom.removeAttribute(name);
}
Expand Down
15 changes: 15 additions & 0 deletions test/browser/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,21 @@ describe('render()', () => {
expect(scratch.firstChild.spellcheck).to.equal(false);
});

it('should support popover auto', () => {
render(<div popover="auto" />, scratch);
expect(scratch.innerHTML).to.equal("<div popover=\"auto\"></div>");
});

it('should support popover true boolean', () => {
render(<div popover />, scratch);
expect(scratch.innerHTML).to.equal("<div popover=\"\"></div>");
});

it('should support popover false boolean', () => {
render(<div popover={false} />, scratch);
expect(scratch.innerHTML).to.equal("<div></div>");
});

// Test for preactjs/preact#4340
it('should respect defaultValue in render', () => {
scratch.innerHTML = '<input value="foo">';
Expand Down

0 comments on commit b7c43d9

Please sign in to comment.