-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
alwaysFocusable
property to button and iconbutton
Aligns with the `alwaysFocusable` property that's currently provided by chip. Fixes #5672. PiperOrigin-RevId: 650632329
- Loading branch information
1 parent
7867674
commit 1e56236
Showing
9 changed files
with
184 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// import 'jasmine'; (google3-only) | ||
|
||
import {html} from 'lit'; | ||
import {customElement} from 'lit/decorators.js'; | ||
|
||
import {Environment} from '../../testing/environment.js'; | ||
import {ButtonHarness} from '../harness.js'; | ||
|
||
import {Button} from './button.js'; | ||
|
||
@customElement('test-button') | ||
class TestButton extends Button {} | ||
|
||
describe('Button', () => { | ||
const env = new Environment(); | ||
|
||
async function setupTest() { | ||
const button = new TestButton(); | ||
env.render(html`${button}`); | ||
await env.waitForStability(); | ||
return {button, harness: new ButtonHarness(button)}; | ||
} | ||
|
||
it('should not be focusable when disabled', async () => { | ||
const {button} = await setupTest(); | ||
button.disabled = true; | ||
await env.waitForStability(); | ||
|
||
button.focus(); | ||
expect(document.activeElement).toEqual(document.body); | ||
}); | ||
|
||
it('should be focusable when disabled and alwaysFocusable', async () => { | ||
const {button} = await setupTest(); | ||
button.disabled = true; | ||
button.alwaysFocusable = true; | ||
await env.waitForStability(); | ||
|
||
button.focus(); | ||
expect(document.activeElement).toEqual(button); | ||
}); | ||
|
||
it('should not activate if clicked when disabled', async () => { | ||
const clickListener = jasmine.createSpy('clickListener'); | ||
const {button} = await setupTest(); | ||
button.disabled = true; | ||
button.addEventListener('click', clickListener); | ||
await env.waitForStability(); | ||
|
||
button.click(); | ||
expect(clickListener).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.