Skip to content

Commit

Permalink
Merge pull request #3062 from preactjs/tabindex
Browse files Browse the repository at this point in the history
Fix unable to reset tabIndex
  • Loading branch information
marvinhagemeister committed Mar 14, 2021
2 parents 7556b61 + 40f35ae commit c6ca49e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/diff/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
name !== 'href' &&
name !== 'list' &&
name !== 'form' &&
// Default value in browsers is `-1` and an empty string is
// cast to `0` instead
name !== 'tabIndex' &&
name !== 'download' &&
name in dom
) {
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 @@ -1142,4 +1142,21 @@ describe('render()', () => {
expect(scratch.firstChild.contentEditable).to.equal('true');
expect(scratch.querySelector('p').contentEditable).to.equal('false');
});

// #3060
it('should reset tabindex on undefined/null', () => {
render(<div tabIndex={0} />, scratch);
expect(scratch.firstChild.tabIndex).to.equal(0);
render(<div tabIndex={undefined} />, scratch);
expect(scratch.firstChild.tabIndex).to.equal(-1);
render(<div tabIndex={null} />, scratch);
expect(scratch.firstChild.tabIndex).to.equal(-1);

render(<div tabindex={0} />, scratch);
expect(scratch.firstChild.tabIndex).to.equal(0);
render(<div tabindex={undefined} />, scratch);
expect(scratch.firstChild.tabIndex).to.equal(-1);
render(<div tabindex={null} />, scratch);
expect(scratch.firstChild.tabIndex).to.equal(-1);
});
});

0 comments on commit c6ca49e

Please sign in to comment.