Skip to content

Commit

Permalink
support popover boolean attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed May 21, 2024
1 parent 85bed33 commit 68e5cda
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
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
4 changes: 2 additions & 2 deletions src/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2337,9 +2337,9 @@ export namespace JSXInternal {
| 'auto'
| 'hint'
| 'manual'
| boolean
| Booleanish
| undefined
| SignalLike<'auto' | 'hint' | 'manual' | boolean | undefined>;
| SignalLike<'auto' | 'hint' | 'manual' | Booleanish | undefined>;
popovertarget?: string | undefined | SignalLike<string | undefined>;
popoverTarget?: string | undefined | SignalLike<string | undefined>;
popovertargetaction?:
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 true 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 68e5cda

Please sign in to comment.