Skip to content

Commit

Permalink
[Header] Add hidden live region to announce when the page title chang…
Browse files Browse the repository at this point in the history
…es. (#10958)

### WHY are these changes introduced?

Relates to Shopify/web#101295

Merchants using a screen reader have no idea when pages change, so this
PR adds a hidden live element which will announce to the merchant the
page title followed by "This page is ready".

### How to 🎩

🖥 [Local development
instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development)
🗒 [General tophatting
guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md)
📄 [Changelog
guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog)


</details>

### 🎩 checklist

- [x] Tested on
[mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing)
- [x] Tested on [multiple
browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers)
- [x] Tested for
[accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)
- [x] Updated the component's `README.md` with documentation changes
- [x] [Tophatted
documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md)
changes in the style guide

---------

Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>
Co-authored-by: Chloe Rice <[email protected]>
  • Loading branch information
3 people authored Dec 13, 2023
1 parent a749323 commit 5c183e0
Show file tree
Hide file tree
Showing 24 changed files with 90 additions and 21 deletions.
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 @@ -350,7 +350,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 @@ -348,7 +348,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 @@ -348,7 +348,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 @@ -349,7 +349,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 @@ -348,7 +348,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 @@ -349,7 +349,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 @@ -349,7 +349,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 @@ -348,7 +348,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 @@ -348,7 +348,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 @@ -348,7 +348,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 @@ -348,7 +348,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 @@ -350,7 +350,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 @@ -349,7 +349,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 @@ -349,7 +349,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 @@ -348,7 +348,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 @@ -348,7 +348,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 @@ -348,7 +348,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 @@ -348,7 +348,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 @@ -348,7 +348,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 @@ -348,7 +348,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

1 comment on commit 5c183e0

@kaitoukid-1412
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
image

  "@shopify/polaris": "^12.5.0",

Please sign in to comment.