Skip to content

Commit

Permalink
remove tabindex to disable focus
Browse files Browse the repository at this point in the history
  • Loading branch information
sissbruecker committed Nov 5, 2024
1 parent 54140c3 commit 32a9ee3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/upload/src/vaadin-upload-file-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,16 @@ export const UploadFileMixin = (superClass) =>
* @protected
*/
_shouldSetFocus(event) {
return !this.disabled && event.composedPath()[0] === this;
return event.composedPath()[0] === this;
}

/** @private */
__disabledChanged(disabled) {
this.tabIndex = disabled ? -1 : 0;
if (disabled) {
this.removeAttribute('tabindex');
} else {
this.setAttribute('tabindex', this.tabindex);
}
}

/** @private */
Expand Down
5 changes: 4 additions & 1 deletion packages/upload/test/file.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ describe('<vaadin-upload-file> element', () => {
it('should be focusable by default', () => {
fileElement.focus();
expect(fileElement.hasAttribute('focused')).to.be.true;
expect(document.activeElement).to.equal(fileElement);
});

it('should not be focusable when disabled', () => {
it('should not be focusable when disabled', async () => {
fileElement.disabled = true;
await nextUpdate(fileElement);
fileElement.focus();
expect(fileElement.hasAttribute('focused')).to.be.false;
expect(document.activeElement).to.not.equal(fileElement);
});

it('should not add focus-ring to the host on programmatic focus', () => {
Expand Down

0 comments on commit 32a9ee3

Please sign in to comment.