Skip to content

Commit 8888e2b

Browse files
authored
fix(header): role attribute can now be customized (#23888)
resolves #21327
1 parent e512fc1 commit 8888e2b

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

core/src/components/header/header.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Component, ComponentInterface, Element, Host, Prop, h, writeTask } from '@stencil/core';
22

33
import { getIonMode } from '../../global/ionic-global';
4+
import { inheritAttributes } from '../../utils/helpers';
45

56
import { cloneElement, createHeaderIndex, handleContentScroll, handleToolbarIntersection, setHeaderActive, setToolbarBackgroundOpacity } from './header.utils';
7+
68
/**
79
* @virtualProp {"ios" | "md"} mode - The mode determines which platform styles to use.
810
*/
@@ -20,6 +22,7 @@ export class Header implements ComponentInterface {
2022
private contentScrollCallback?: any;
2123
private intersectionObserver?: any;
2224
private collapsibleMainHeader?: HTMLElement;
25+
private inheritedAttributes: { [k: string]: any } = {};
2326

2427
@Element() el!: HTMLElement;
2528

@@ -41,6 +44,10 @@ export class Header implements ComponentInterface {
4144
*/
4245
@Prop() translucent = false;
4346

47+
componentWillLoad() {
48+
this.inheritedAttributes = inheritAttributes(this.el, ['role']);
49+
}
50+
4451
async componentDidLoad() {
4552
await this.checkCollapsibleHeader();
4653
}
@@ -143,9 +150,10 @@ export class Header implements ComponentInterface {
143150
}
144151

145152
render() {
146-
const { translucent } = this;
153+
const { translucent, inheritedAttributes } = this;
147154
const mode = getIonMode(this);
148155
const collapse = this.collapse || 'none';
156+
149157
return (
150158
<Host
151159
role="banner"
@@ -159,6 +167,7 @@ export class Header implements ComponentInterface {
159167
[`header-collapse-${collapse}`]: true,
160168
[`header-translucent-${mode}`]: this.translucent,
161169
}}
170+
{...inheritedAttributes}
162171
>
163172
{ mode === 'ios' && translucent &&
164173
<div class="header-background"></div>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { newE2EPage } from '@stencil/core/testing';
2+
import { AxePuppeteer } from '@axe-core/puppeteer';
3+
4+
test('header: axe', async () => {
5+
const page = await newE2EPage({
6+
url: '/src/components/header/test/a11y?ionic:_testing=true'
7+
});
8+
9+
const results = await new AxePuppeteer(page).analyze();
10+
expect(results.violations.length).toEqual(0);
11+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html lang="en" dir="ltr">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Header - a11y</title>
6+
<meta name="viewport"
7+
content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
8+
<link href="../../../../../css/core.css" rel="stylesheet">
9+
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet">
10+
<script src="../../../../../scripts/testing/scripts.js"></script>
11+
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
12+
</head>
13+
14+
<body>
15+
<ion-header></ion-header>
16+
<main>
17+
<h1>Headers</h1>
18+
<ion-header role="none"></ion-header>
19+
</main>
20+
</body>
21+
</html>

0 commit comments

Comments
 (0)