Skip to content

Commit

Permalink
fix(shared): make Focusable pass disabled always
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Nov 1, 2019
1 parent c278263 commit a339d6f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/button/test/button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,19 @@ describe('Button', () => {
await elementUpdated(el);

expect(el.hasAttribute('aria-disabled')).to.be.false;
expect((el.focusElement as HTMLButtonElement).disabled).to.be.false;

el.disabled = true;
await elementUpdated(el);

expect(el.hasAttribute('aria-disabled')).to.be.true;
expect((el.focusElement as HTMLButtonElement).disabled).to.be.true;

el.disabled = false;
await elementUpdated(el);

expect(el.hasAttribute('aria-disabled')).to.be.false;
expect((el.focusElement as HTMLButtonElement).disabled).to.be.false;
});
it('manages tabIndex while disabled', async () => {
const el = await fixture<Button>(
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/src/focusable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
} from 'lit-element';
import focusableStyles from './focusable.css.js';

type DisableableElement = HTMLElement & { disabled?: boolean };

/**
* Focusable base class handles tabindex setting into shadowed elements automatically.
*
Expand Down Expand Up @@ -50,7 +52,7 @@ export class Focusable extends LitElement {
private newTabindex?: number = 0;
private oldTabindex = 0;

public get focusElement(): HTMLElement {
public get focusElement(): DisableableElement {
throw new Error('Must implement focusElement getter!');
}

Expand Down Expand Up @@ -111,9 +113,7 @@ export class Focusable extends LitElement {
super.updated(changedProperties);

if (changedProperties.has('disabled')) {
if (this.focusElement instanceof HTMLInputElement) {
this.focusElement.disabled = this.disabled;
}
this.focusElement.disabled = this.disabled;
if (this.disabled) {
this.blur();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/status-light/src/spectrum-status-light.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* stylelint-disable */ /*
/* stylelint-disable */ /*
Copyright 2019 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
Expand Down

0 comments on commit a339d6f

Please sign in to comment.