Skip to content
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
9 changes: 7 additions & 2 deletions core/src/components/back-button/back-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { config } from '../../global/config';
import { getIonMode } from '../../global/ionic-global';
import { AnimationBuilder, Color } from '../../interface';
import { ButtonInterface } from '../../utils/element-interface';
import { inheritAttributes } from '../../utils/helpers';
import { createColorClasses, hostContext, openURL } from '../../utils/theme';

/**
Expand All @@ -22,6 +23,7 @@ import { createColorClasses, hostContext, openURL } from '../../utils/theme';
shadow: true
})
export class BackButton implements ComponentInterface, ButtonInterface {
private inheritedAttributes: { [k: string]: any } = {};

@Element() el!: HTMLElement;

Expand Down Expand Up @@ -64,6 +66,8 @@ export class BackButton implements ComponentInterface, ButtonInterface {
@Prop() routerAnimation: AnimationBuilder | undefined;

componentWillLoad() {
this.inheritedAttributes = inheritAttributes(this.el, ['aria-label']);

if (this.defaultHref === undefined) {
this.defaultHref = config.get('backButtonDefaultHref');
}
Expand Down Expand Up @@ -115,9 +119,10 @@ export class BackButton implements ComponentInterface, ButtonInterface {
}

render() {
const { color, defaultHref, disabled, type, hasIconOnly, backButtonIcon, backButtonText } = this;
const { color, defaultHref, disabled, type, hasIconOnly, backButtonIcon, backButtonText, inheritedAttributes } = this;
const showBackButton = defaultHref !== undefined;
const mode = getIonMode(this);
const ariaLabel = inheritedAttributes['aria-label'] || backButtonText || 'back';

return (
<Host
Expand All @@ -139,7 +144,7 @@ export class BackButton implements ComponentInterface, ButtonInterface {
disabled={disabled}
class="button-native"
part="native"
aria-label={backButtonText || 'back'}
aria-label={ariaLabel}
>
<span class="button-inner">
{backButtonIcon && <ion-icon part="icon" icon={backButtonIcon} aria-hidden="true" lazy={false}></ion-icon>}
Expand Down
4 changes: 2 additions & 2 deletions core/src/components/back-button/test/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<ion-content>
<h3>Default</h3>
<p>
<ion-back-button></ion-back-button>
<ion-back-button text="Back"></ion-back-button>
<ion-back-button aria-label="back button"></ion-back-button>
<ion-back-button text="Back" aria-label="back button"></ion-back-button>
<ion-back-button icon="add"></ion-back-button>
<ion-back-button disabled text="Text Only" icon=""></ion-back-button>
<ion-back-button icon="heart" text="Love" color="danger"></ion-back-button>
Expand Down