-
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: add
soft-disabled
property to button and iconbutton
Fixes #5672. PiperOrigin-RevId: 651409230
- Loading branch information
1 parent
7867674
commit f6c66aa
Showing
15 changed files
with
298 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* @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 soft-disabled', async () => { | ||
const {button} = await setupTest(); | ||
button.softDisabled = true; | ||
await env.waitForStability(); | ||
|
||
button.focus(); | ||
expect(document.activeElement).toEqual(button); | ||
}); | ||
|
||
it('should not be clickable 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(); | ||
}); | ||
|
||
it('should not be clickable when soft-disabled', async () => { | ||
const clickListener = jasmine.createSpy('clickListener'); | ||
const {button} = await setupTest(); | ||
button.softDisabled = 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
Oops, something went wrong.