Skip to content

Commit 98fcbed

Browse files
committed
test(header): check role on md
1 parent f6dba23 commit 98fcbed

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

core/src/components/header/header.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,10 @@ export class Header implements ComponentInterface {
209209
const { translucent, inheritedAttributes } = this;
210210
const mode = getIonMode(this);
211211
const collapse = this.collapse || 'none';
212+
const isCondensed = collapse === 'condense';
212213

213214
// banner role must be at top level, so remove role if inside a menu
214-
const roleType = getRoleType(hostContext('ion-menu', this.el));
215+
const roleType = getRoleType(hostContext('ion-menu', this.el), isCondensed, mode);
215216

216217
return (
217218
<Host

core/src/components/header/header.utils.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,23 @@ export const handleHeaderFade = (scrollEl: HTMLElement, baseEl: HTMLElement, con
262262
* Get the role type for the ion-header.
263263
*
264264
* @param isInsideMenu If ion-header is inside ion-menu.
265-
* @returns 'none' if inside ion-menu, otherwise 'banner'.
265+
* @param isCondensed If ion-header has collapse="condense".
266+
* @param mode The current mode.
267+
* @returns 'none' if inside ion-menu or if condensed in md
268+
* mode, otherwise 'banner'.
266269
*/
267-
export const getRoleType = (isInsideMenu: boolean) => {
268-
return isInsideMenu ? ROLE_NONE : ROLE_BANNER;
270+
export const getRoleType = (isInsideMenu: boolean, isCondensed: boolean, mode: 'ios' | 'md') => {
271+
// If the header is inside a menu, it should not have the banner role.
272+
if (isInsideMenu) {
273+
return ROLE_NONE;
274+
}
275+
/**
276+
* Only apply role="none" to `md` mode condensed headers
277+
* since the large header is never shown.
278+
*/
279+
if (isCondensed && mode === 'md') {
280+
return ROLE_NONE;
281+
}
282+
// Default to banner role.
283+
return ROLE_BANNER;
269284
};

core/src/components/header/test/condense/header.e2e.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,25 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, screenshot, c
6060
});
6161
});
6262
});
63+
64+
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
65+
test.describe(title('header: condense'), () => {
66+
test('should only have the banner role on the small header', async ({ page }) => {
67+
await page.goto('/src/components/header/test/condense', config);
68+
const largeTitleHeader = page.locator('#largeTitleHeader');
69+
const smallTitleHeader = page.locator('#smallTitleHeader');
70+
const content = page.locator('ion-content');
71+
72+
await expect(smallTitleHeader).toHaveAttribute('role', 'banner');
73+
await expect(largeTitleHeader).toHaveAttribute('role', 'none');
74+
75+
await content.evaluate(async (el: HTMLIonContentElement) => {
76+
await el.scrollToBottom();
77+
});
78+
await page.waitForChanges();
79+
80+
await expect(smallTitleHeader).toHaveAttribute('role', 'banner');
81+
await expect(largeTitleHeader).toHaveAttribute('role', 'none');
82+
});
83+
});
84+
});

0 commit comments

Comments
 (0)