Skip to content

Commit 6cc1712

Browse files
author
Eric Olkowski
committed
Fixed a11y error in demo
1 parent 24259ad commit 6cc1712

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

packages/react-core/src/demos/Page.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import LightbulbIcon from '@patternfly/react-icons/dist/esm/icons/lightbulb-icon
1414
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
1515
import pfLogo from '@patternfly/react-core/src/demos/assets/PF-HorizontalLogo-Color.svg';
1616

17-
1817
- All examples set the `isManagedSidebar` prop on the Page component to have the sidebar automatically close for smaller screen widths. You can also manually control this behavior by not adding the `isManagedSidebar` prop and instead:
1918

2019
1. Add an onNavToggle callback to PageHeader
@@ -44,6 +43,8 @@ This demonstrates a variety of navigation patterns in the context of a full page
4443

4544
### Context selector/perspective switcher in sidebar
4645

46+
When adding a context selector/perspective switcher in a `PageSidebar`, you must manually control the open state of the `PageSidebar` as well as ensure any interactive menu toggles or buttons cannot receive focus. This demo adds a `tabIndex` of `-1` when the sidebar is not expanded to achieve this.
47+
4748
```ts file='./examples/Page/PageContextSelector.tsx' isFullscreen
4849

49-
```
50+
```

packages/react-core/src/demos/examples/Page/PageContextSelector.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ export const PageStickySectionBreadcrumb: React.FunctionComponent = () => {
5959
const [isFullKebabDropdownOpen, setIsFullKebabDropdownOpen] = React.useState(false);
6060
const [isContextSelectorOpen, setIsContextSelectorOpen] = React.useState(false);
6161
const [activeItem, setActiveItem] = React.useState(1);
62+
const [isSidebarOpen, setIsSidebarOpen] = React.useState(true);
63+
64+
const onSidebarToggle = () => {
65+
setIsSidebarOpen(!isSidebarOpen);
66+
};
6267

6368
const onNavSelect = (_event: React.FormEvent<HTMLInputElement>, selectedItem: NavOnSelectProps) => {
6469
typeof selectedItem.itemId === 'number' && setActiveItem(selectedItem.itemId);
@@ -225,7 +230,12 @@ export const PageStickySectionBreadcrumb: React.FunctionComponent = () => {
225230
<Masthead>
226231
<MastheadMain>
227232
<MastheadToggle>
228-
<PageToggleButton variant="plain" aria-label="Global navigation">
233+
<PageToggleButton
234+
variant="plain"
235+
aria-label="Global navigation"
236+
isSidebarOpen={isSidebarOpen}
237+
onSidebarToggle={onSidebarToggle}
238+
>
229239
<BarsIcon />
230240
</PageToggleButton>
231241
</MastheadToggle>
@@ -267,7 +277,13 @@ export const PageStickySectionBreadcrumb: React.FunctionComponent = () => {
267277
onSelect={onContextSelectorSelect}
268278
onOpenChange={(isOpen: boolean) => setIsContextSelectorOpen(isOpen)}
269279
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
270-
<MenuToggle ref={toggleRef} onClick={onContextSelectorToggle} isExpanded={isContextSelectorOpen} isFullWidth>
280+
<MenuToggle
281+
tabIndex={isSidebarOpen ? undefined : -1}
282+
ref={toggleRef}
283+
onClick={onContextSelectorToggle}
284+
isExpanded={isContextSelectorOpen}
285+
isFullWidth
286+
>
271287
Developer
272288
</MenuToggle>
273289
)}
@@ -277,7 +293,7 @@ export const PageStickySectionBreadcrumb: React.FunctionComponent = () => {
277293
);
278294

279295
const sidebar = (
280-
<PageSidebar>
296+
<PageSidebar isSidebarOpen={isSidebarOpen}>
281297
<PageSidebarBody isContextSelector>{pageContextSelector}</PageSidebarBody>
282298
<PageSidebarBody>{pageNav}</PageSidebarBody>
283299
</PageSidebar>
@@ -304,7 +320,6 @@ export const PageStickySectionBreadcrumb: React.FunctionComponent = () => {
304320
<Page
305321
masthead={masthead}
306322
sidebar={sidebar}
307-
isManagedSidebar
308323
skipToContent={pageSkipToContent}
309324
breadcrumb={dashboardBreadcrumb}
310325
mainContainerId={mainContainerId}

0 commit comments

Comments
 (0)