Skip to content

Commit

Permalink
fix: remove role attribute when it's null or undefined (#4137)
Browse files Browse the repository at this point in the history
* add failing test

* fix `role` not being removed

* add PR number in test case
  • Loading branch information
DAreRodz authored Sep 20, 2023
1 parent 7dc66bc commit 64be3cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/diff/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
name !== 'download' &&
name !== 'rowSpan' &&
name !== 'colSpan' &&
name !== 'role' &&
name in dom
) {
try {
Expand Down
17 changes: 17 additions & 0 deletions test/browser/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1281,4 +1281,21 @@ describe('render()', () => {
render(<div tabindex={null} />, scratch);
expect(scratch.firstChild.tabIndex).to.equal(defaultValue);
});

// #4137
it('should unset role if null || undefined', () => {
render(
<section>
<div role="status">role="status"</div>
<div role={undefined}>role="undefined"</div>
<div role={null}>role="null"</div>
</section>,
scratch
);

const divs = scratch.querySelectorAll('div');
expect(divs[0].hasAttribute('role')).to.equal(true);
expect(divs[1].hasAttribute('role')).to.equal(false);
expect(divs[2].hasAttribute('role')).to.equal(false);
});
});

0 comments on commit 64be3cb

Please sign in to comment.