Skip to content

Commit fb4d9c8

Browse files
Elliott Marquezcopybara-github
authored andcommitted
feat(fab): set aria hidden on the icon slot if element has aria-label or label
PiperOrigin-RevId: 543531953
1 parent 8648be6 commit fb4d9c8

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

fab/fab_test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,40 @@ describe('<md-branded-fab>', () => {
213213
expect(button.classList.contains('large')).toBeFalse();
214214
});
215215
});
216+
217+
describe('accessibility', () => {
218+
it('sets aria-hidden on the icon slot when aria-label is set', async () => {
219+
const {button, harness} = await setupTest();
220+
await env.waitForStability();
221+
222+
const iconSlot = button.querySelector('slot[name="icon"]')!;
223+
224+
expect(button.hasAttribute('aria-label')).toBeFalse();
225+
expect(iconSlot.hasAttribute('aria-hidden')).toBeFalse();
226+
227+
const element = harness.element;
228+
element.ariaLabel = 'foo';
229+
await env.waitForStability();
230+
231+
expect(button.hasAttribute('aria-label')).toBeTrue();
232+
expect(iconSlot.getAttribute('aria-hidden')).toEqual('true');
233+
});
234+
235+
it('sets aria-hidden on the icon slot when label is set', async () => {
236+
const {button, harness} = await setupTest();
237+
await env.waitForStability();
238+
const element = harness.element;
239+
240+
const iconSlot = button.querySelector('slot[name="icon"]')!;
241+
242+
expect(!!element.label).toBeFalse();
243+
expect(iconSlot.hasAttribute('aria-hidden')).toBeFalse();
244+
245+
element.label = 'foo';
246+
await env.waitForStability();
247+
248+
expect(!!element.label).toBeTrue();
249+
expect(iconSlot.getAttribute('aria-hidden')).toEqual('true');
250+
});
251+
});
216252
});

fab/lib/shared.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ export abstract class SharedFab extends LitElement {
104104
}
105105

106106
private renderIcon() {
107+
const {ariaLabel} = this as ARIAMixinStrict;
107108
return html`<span class="icon">
108-
<slot name="icon" @slotchange=${this.onSlotchange}></slot>
109+
<slot
110+
name="icon"
111+
aria-hidden=${
112+
ariaLabel || this.label ? 'true' : nothing as unknown as 'false'}
113+
@slotchange=${this.onSlotchange}>
114+
</slot>
109115
</span>`;
110116
}
111117

0 commit comments

Comments
 (0)