Skip to content
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

[Header] Add hidden live region to announce when the page title changes. #10958

Merged
merged 7 commits into from
Dec 13, 2023
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
5 changes: 5 additions & 0 deletions .changeset/strong-moose-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': minor
---

Added a live region to the `Page` `Header` to announce the `title` after navigation changes
3 changes: 2 additions & 1 deletion polaris-react/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Zobrazte akce pro: {title}"
"rollupActionsLabel": "Zobrazte akce pro: {title}",
"pageReadyAccessibilityLabel": "{title}. Tato stránka je připravena."
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Se handlinger for {title}"
"rollupActionsLabel": "Se handlinger for {title}",
"pageReadyAccessibilityLabel": "{title}. Denne side er klar"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Aktionen für {title} anzeigen"
"rollupActionsLabel": "Aktionen für {title} anzeigen",
"pageReadyAccessibilityLabel": "{title}. Diese Seite ist bereit"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "View actions for {title}"
"rollupActionsLabel": "View actions for {title}",
"pageReadyAccessibilityLabel": "{title}. This page is ready"
}
},
"Pagination": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Ver acciones para {title}"
"rollupActionsLabel": "Ver acciones para {title}",
"pageReadyAccessibilityLabel": "{title}. Esta página está lista"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Tarkastele nimikettä {title} koskevia toimintoja"
"rollupActionsLabel": "Tarkastele nimikettä {title} koskevia toimintoja",
"pageReadyAccessibilityLabel": "{title}. Tämä sivu on valmis"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Afficher les actions pour {title}"
"rollupActionsLabel": "Afficher les actions pour {title}",
"pageReadyAccessibilityLabel": "{title}. Cette page est prête"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Visualizza azioni per {title}"
"rollupActionsLabel": "Visualizza azioni per {title}",
"pageReadyAccessibilityLabel": "{title}. Questa pagina è pronta"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "{title}のアクションを表示"
"rollupActionsLabel": "{title}のアクションを表示",
"pageReadyAccessibilityLabel": "{title}。このページの準備が整いました"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "{title} 작업 보기"
"rollupActionsLabel": "{title} 작업 보기",
"pageReadyAccessibilityLabel": "{title}. 이 페이지가 준비되었습니다"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Vis handlinger for {title}"
"rollupActionsLabel": "Vis handlinger for {title}",
"pageReadyAccessibilityLabel": "{title}. Denne siden er klar"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Acties voor {title} bekijken"
"rollupActionsLabel": "Acties voor {title} bekijken",
"pageReadyAccessibilityLabel": "{title}. Deze pagina is klaar"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Wyświetl czynności dla {title}"
"rollupActionsLabel": "Wyświetl czynności dla {title}",
"pageReadyAccessibilityLabel": "{title}. Ta strona jest gotowa"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Ver ações para {title}"
"rollupActionsLabel": "Ver ações para {title}",
"pageReadyAccessibilityLabel": "{title}. A página está pronta"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Ver ações para {title}"
"rollupActionsLabel": "Ver ações para {title}",
"pageReadyAccessibilityLabel": "{title}. Esta página está pronta"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Visa åtgärder för {title}"
"rollupActionsLabel": "Visa åtgärder för {title}",
"pageReadyAccessibilityLabel": "{title}. Den här sidan är redo"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "ดูการดำเนินการสำหรับ {title}"
"rollupActionsLabel": "ดูการดำเนินการสำหรับ {title}",
"pageReadyAccessibilityLabel": "{title} หน้านี้พร้อมแล้ว"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "{title} ile ilgili işlemleri görüntüle"
"rollupActionsLabel": "{title} ile ilgili işlemleri görüntüle",
"pageReadyAccessibilityLabel": "{title}. Bu sayfa hazır"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "Xem thao tác đối với {title}"
"rollupActionsLabel": "Xem thao tác đối với {title}",
"pageReadyAccessibilityLabel": "{title}. Trang này đã sẵn sàng"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "查看用于 {title} 的操作"
"rollupActionsLabel": "查看用于 {title} 的操作",
"pageReadyAccessibilityLabel": "{title}。此页面已就绪"
}
},
"FullscreenBar": {
Expand Down
3 changes: 2 additions & 1 deletion polaris-react/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@
},
"Page": {
"Header": {
"rollupActionsLabel": "檢視 {title} 的動作"
"rollupActionsLabel": "檢視 {title} 的動作",
"pageReadyAccessibilityLabel": "{title}。此頁面已準備就緒"
}
},
"FullscreenBar": {
Expand Down
18 changes: 18 additions & 0 deletions polaris-react/src/components/Page/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ interface PrimaryAction
export interface HeaderProps extends TitleProps {
/** Visually hide the title */
titleHidden?: boolean;
/** A label to use for the page when the page is ready, used by screen readers. Will override the title prop if present */
pageReadyAccessibilityLabel?: string;
/** Enables filtering action list items */
filterActions?: boolean;
/** Primary page-level action */
Expand All @@ -74,6 +76,7 @@ const LONG_TITLE = 34;
export function Header({
title,
subtitle,
pageReadyAccessibilityLabel,
titleMetadata,
additionalMetadata,
titleHidden = false,
Expand Down Expand Up @@ -128,6 +131,20 @@ export function Header({
</div>
);

const labelForPageReadyAccessibilityLabel =
pageReadyAccessibilityLabel || title;

const pageReadyAccessibilityLabelMarkup =
labelForPageReadyAccessibilityLabel ? (
<div role="status">
<Text visuallyHidden as="p">
{i18n.translate('Polaris.Page.Header.pageReadyAccessibilityLabel', {
title: labelForPageReadyAccessibilityLabel,
})}
</Text>
</div>
) : undefined;

const primaryActionMarkup = primaryAction ? (
<PrimaryActionMarkup primaryAction={primaryAction} />
) : null;
Expand Down Expand Up @@ -208,6 +225,7 @@ export function Header({
paddingInlineEnd={{xs: '400', sm: '0'}}
visuallyHidden={titleHidden}
>
{pageReadyAccessibilityLabelMarkup}
<div className={headerClassNames}>
<FilterActionsProvider filterActions={Boolean(filterActions)}>
<ConditionalRender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {Button} from '../../../../Button';
import {ButtonGroup} from '../../../../ButtonGroup';
import {Pagination} from '../../../../Pagination';
import {Tooltip} from '../../../../Tooltip';
import {Text} from '../../../../Text';
import type {LinkAction, MenuActionDescriptor} from '../../../../../types';
import {Header} from '../Header';
import type {HeaderProps} from '../Header';
Expand Down Expand Up @@ -45,6 +46,30 @@ describe('<Header />', () => {
titleMetadata: mockProps.titleMetadata,
});
});

it('renders an aria-live region with the title', () => {
const header = mountWithApp(<Header {...mockProps} />);
const liveRegion = header.find('div', {role: 'status'});
expect(liveRegion).toContainReactComponent(Text, {
visuallyHidden: true,
children: `${mockProps.title}. This page is ready`,
});
});

it('renders an aria-live region with the pageReadyAccessibilityLabel which overrides the title', () => {
const pageReadyAccessibilityLabel = 'page ready';
const header = mountWithApp(
<Header
{...mockProps}
pageReadyAccessibilityLabel={pageReadyAccessibilityLabel}
/>,
);
const liveRegion = header.find('div', {role: 'status'});
expect(liveRegion).toContainReactComponent(Text, {
visuallyHidden: true,
children: `${pageReadyAccessibilityLabel}. This page is ready`,
});
});
});

describe('breadcrumbs', () => {
Expand Down
Loading