-
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(icon): add aria-hidden true by default
PiperOrigin-RevId: 551024866
- Loading branch information
1 parent
fb1c603
commit 08d50e2
Showing
2 changed files
with
82 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// import 'jasmine'; (google3-only) | ||
import './icon.js'; | ||
|
||
import {html} from 'lit'; | ||
|
||
import {Environment} from '../testing/environment.js'; | ||
import {createTokenTests} from '../testing/tokens.js'; | ||
|
||
import {MdIcon} from './icon.js'; | ||
|
||
describe('<md-icon>', () => { | ||
const env = new Environment(); | ||
|
||
describe('.styles', () => { | ||
createTokenTests(MdIcon.styles); | ||
}); | ||
|
||
describe('accessiblity', () => { | ||
it('sets aria-hidden to true by default', async () => { | ||
const root = env.render(html` | ||
<md-icon>check</md-icon>`); | ||
const icon = root.querySelector('md-icon')!; | ||
|
||
await env.waitForStability(); | ||
|
||
expect(icon.getAttribute('aria-hidden')).toBe('true'); | ||
}); | ||
|
||
it('sets aria-hidden is removed when initalized as false', async () => { | ||
const root = env.render(html` | ||
<md-icon aria-hidden="false">check</md-icon>`); | ||
const icon = root.querySelector('md-icon')!; | ||
|
||
await env.waitForStability(); | ||
|
||
expect(icon.hasAttribute('aria-hidden')).toBe(false); | ||
}); | ||
|
||
it('allows overriding aria-hidden after first render', async () => { | ||
const root = env.render(html` | ||
<md-icon>check</md-icon>`); | ||
const icon = root.querySelector('md-icon')!; | ||
|
||
await env.waitForStability(); | ||
|
||
expect(icon.getAttribute('aria-hidden')).toBe('true'); | ||
|
||
icon.removeAttribute('aria-hidden'); | ||
await env.waitForStability(); | ||
|
||
expect(icon.hasAttribute('aria-hidden')).toBe(false); | ||
}); | ||
|
||
it('overrides invalid aria-hidden values to true', async () => { | ||
const root = env.render(html` | ||
<!-- @ts-ignore:disable-next-line:no-incompatible-type-binding --> | ||
<md-icon aria-hidden="foo">check</md-icon>`); | ||
const icon = root.querySelector('md-icon')!; | ||
|
||
await env.waitForStability(); | ||
|
||
expect(icon.getAttribute('aria-hidden')).toBe('true'); | ||
}); | ||
}); | ||
}); |
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