Skip to content

Commit 68a7e43

Browse files
fix(back-button): pass aria-label to native element (#24027)
1 parent e92fecb commit 68a7e43

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

core/src/components/back-button/back-button.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { config } from '../../global/config';
44
import { getIonMode } from '../../global/ionic-global';
55
import { AnimationBuilder, Color } from '../../interface';
66
import { ButtonInterface } from '../../utils/element-interface';
7+
import { inheritAttributes } from '../../utils/helpers';
78
import { createColorClasses, hostContext, openURL } from '../../utils/theme';
89

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

2628
@Element() el!: HTMLElement;
2729

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

6668
componentWillLoad() {
69+
this.inheritedAttributes = inheritAttributes(this.el, ['aria-label']);
70+
6771
if (this.defaultHref === undefined) {
6872
this.defaultHref = config.get('backButtonDefaultHref');
6973
}
@@ -115,9 +119,10 @@ export class BackButton implements ComponentInterface, ButtonInterface {
115119
}
116120

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

122127
return (
123128
<Host
@@ -139,7 +144,7 @@ export class BackButton implements ComponentInterface, ButtonInterface {
139144
disabled={disabled}
140145
class="button-native"
141146
part="native"
142-
aria-label={backButtonText || 'back'}
147+
aria-label={ariaLabel}
143148
>
144149
<span class="button-inner">
145150
{backButtonIcon && <ion-icon part="icon" icon={backButtonIcon} aria-hidden="true" lazy={false}></ion-icon>}

core/src/components/back-button/test/basic/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<ion-content>
1919
<h3>Default</h3>
2020
<p>
21-
<ion-back-button></ion-back-button>
22-
<ion-back-button text="Back"></ion-back-button>
21+
<ion-back-button aria-label="back button"></ion-back-button>
22+
<ion-back-button text="Back" aria-label="back button"></ion-back-button>
2323
<ion-back-button icon="add"></ion-back-button>
2424
<ion-back-button disabled text="Text Only" icon=""></ion-back-button>
2525
<ion-back-button icon="heart" text="Love" color="danger"></ion-back-button>

0 commit comments

Comments
 (0)