Skip to content

fix(fab-button): aria attributes are inherited #25635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion core/src/components/fab-button/fab-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { close } from 'ionicons/icons';
import { getIonMode } from '../../global/ionic-global';
import type { AnimationBuilder, Color, RouterDirection } from '../../interface';
import type { AnchorInterface, ButtonInterface } from '../../utils/element-interface';
import { inheritAriaAttributes } from '../../utils/helpers';
import type { Attributes } from '../../utils/helpers';
import { createColorClasses, hostContext, openURL } from '../../utils/theme';

/**
Expand All @@ -23,6 +25,7 @@ import { createColorClasses, hostContext, openURL } from '../../utils/theme';
})
export class FabButton implements ComponentInterface, AnchorInterface, ButtonInterface {
private fab: HTMLIonFabElement | null = null;
private inheritedAttributes: Attributes = {};

@Element() el!: HTMLElement;

Expand Down Expand Up @@ -142,8 +145,12 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt
fab.toggle();
};

componentWillLoad() {
this.inheritedAttributes = inheritAriaAttributes(this.el);
}

render() {
const { el, disabled, color, href, activated, show, translucent, size } = this;
const { el, disabled, color, href, activated, show, translucent, size, inheritedAttributes } = this;
const inList = hostContext('ion-fab-list', el);
const mode = getIonMode(this);
const TagType = href === undefined ? 'button' : ('a' as any);
Expand Down Expand Up @@ -182,6 +189,7 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt
onFocus={this.onFocus}
onBlur={this.onBlur}
onClick={(ev: Event) => openURL(href, ev, this.routerDirection, this.routerAnimation)}
{...inheritedAttributes}
>
<ion-icon icon={this.closeIcon} part="close-icon" class="close-icon" lazy={false}></ion-icon>
<span class="button-inner">
Expand Down
19 changes: 19 additions & 0 deletions core/src/components/fab-button/test/fab-button.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { newSpecPage } from '@stencil/core/testing';

import { FabButton } from '../fab-button';

describe('fab-button: aria attributes', () => {
it('should inherit aria attributes to inner <button>', async () => {
const page = await newSpecPage({
components: [FabButton],
html: `
<ion-fab-button aria-label="Hello World">My Button</ion-fab-button>
`,
});

const fabButton = page.body.querySelector('ion-fab-button');
const root = fabButton.shadowRoot;
const nativeButton = root.querySelector('button');
expect(nativeButton.getAttribute('aria-label')).toEqual('Hello World');
});
});