-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(button): add
soft-disabled
attribute for focusable disabled bu…
…ttons PiperOrigin-RevId: 651854744
- Loading branch information
1 parent
7867674
commit 48124ba
Showing
9 changed files
with
146 additions
and
21 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 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 () => { | ||
// Arrange | ||
const {button} = await setupTest(); | ||
button.disabled = true; | ||
await env.waitForStability(); | ||
|
||
// Act | ||
button.focus(); | ||
|
||
// Assert | ||
expect(document.activeElement) | ||
.withContext('disabled button should not be focused') | ||
.not.toBe(button); | ||
}); | ||
|
||
it('should be focusable when soft-disabled', async () => { | ||
// Arrange | ||
const {button} = await setupTest(); | ||
button.softDisabled = true; | ||
await env.waitForStability(); | ||
|
||
// Act | ||
button.focus(); | ||
|
||
// Assert | ||
expect(document.activeElement) | ||
.withContext('soft-disabled button should be focused') | ||
.toBe(button); | ||
}); | ||
|
||
it('should not be clickable when disabled', async () => { | ||
// Arrange | ||
const clickListener = jasmine.createSpy('clickListener'); | ||
const {button} = await setupTest(); | ||
button.disabled = true; | ||
button.addEventListener('click', clickListener); | ||
await env.waitForStability(); | ||
|
||
// Act | ||
button.click(); | ||
|
||
// Assert | ||
expect(clickListener).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not be clickable when soft-disabled', async () => { | ||
// Arrange | ||
const clickListener = jasmine.createSpy('clickListener'); | ||
const {button} = await setupTest(); | ||
button.softDisabled = true; | ||
button.addEventListener('click', clickListener); | ||
await env.waitForStability(); | ||
|
||
// Act | ||
button.click(); | ||
|
||
// Assert | ||
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