Skip to content

Commit c6ca49e

Browse files
Merge pull request #3062 from preactjs/tabindex
Fix unable to reset tabIndex
2 parents 7556b61 + 40f35ae commit c6ca49e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/diff/props.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
111111
name !== 'href' &&
112112
name !== 'list' &&
113113
name !== 'form' &&
114+
// Default value in browsers is `-1` and an empty string is
115+
// cast to `0` instead
116+
name !== 'tabIndex' &&
114117
name !== 'download' &&
115118
name in dom
116119
) {

test/browser/render.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,4 +1142,21 @@ describe('render()', () => {
11421142
expect(scratch.firstChild.contentEditable).to.equal('true');
11431143
expect(scratch.querySelector('p').contentEditable).to.equal('false');
11441144
});
1145+
1146+
// #3060
1147+
it('should reset tabindex on undefined/null', () => {
1148+
render(<div tabIndex={0} />, scratch);
1149+
expect(scratch.firstChild.tabIndex).to.equal(0);
1150+
render(<div tabIndex={undefined} />, scratch);
1151+
expect(scratch.firstChild.tabIndex).to.equal(-1);
1152+
render(<div tabIndex={null} />, scratch);
1153+
expect(scratch.firstChild.tabIndex).to.equal(-1);
1154+
1155+
render(<div tabindex={0} />, scratch);
1156+
expect(scratch.firstChild.tabIndex).to.equal(0);
1157+
render(<div tabindex={undefined} />, scratch);
1158+
expect(scratch.firstChild.tabIndex).to.equal(-1);
1159+
render(<div tabindex={null} />, scratch);
1160+
expect(scratch.firstChild.tabIndex).to.equal(-1);
1161+
});
11451162
});

0 commit comments

Comments
 (0)