Skip to content
Open
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
2 changes: 2 additions & 0 deletions packages/react-core/src/components/Page/PageSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext } from 'react';
import styles from '@patternfly/react-styles/css/components/Page/page';
import { css } from '@patternfly/react-styles';
import { IS_INERT } from '../../helpers/inert';
import { PageContextConsumer } from './PageContext';

export interface PageSidebarProps extends React.HTMLProps<HTMLDivElement> {
Expand Down Expand Up @@ -48,6 +49,7 @@ export const PageSidebar: React.FunctionComponent<PageSidebarProps> = ({
className
)}
aria-hidden={!sidebarOpen}
{...(!sidebarOpen && { inert: IS_INERT })}
{...props}
>
<PageSidebarContext.Provider value={{ isSidebarOpen: sidebarOpen }}>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core/src/demos/Page.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ This demonstrates a variety of navigation patterns in the context of a full page

### Context selector/perspective switcher in sidebar

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.
A collapsed `PageSidebar` removes its interactive content, including the context selector, from the tab order.

```ts file='./examples/Page/PageContextSelector.tsx' isFullscreen

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,7 @@ export const PageStickySectionBreadcrumb: React.FunctionComponent = () => {
onSelect={onContextSelectorSelect}
onOpenChange={(isOpen: boolean) => setIsContextSelectorOpen(isOpen)}
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle
tabIndex={isSidebarOpen ? undefined : -1}
ref={toggleRef}
onClick={onContextSelectorToggle}
isExpanded={isContextSelectorOpen}
isFullWidth
>
<MenuToggle ref={toggleRef} onClick={onContextSelectorToggle} isExpanded={isContextSelectorOpen} isFullWidth>
Developer
</MenuToggle>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@ describe('Page Managed Sidebar Closed Demo Test', () => {
cy.get('.pf-v6-c-masthead__content').invoke('text').should('contain', 'header-tools | Avatar');
});
});

it('skips the sidebar link when collapsed and reaches it when expanded', { browser: '!firefox' }, () => {
cy.viewport(390, 792);
cy.visit('http://localhost:3000/page-managed-sidebar-closed-demo-nav-link');

cy.get('#uncontrolled-sidebar').should('have.attr', 'aria-hidden', 'true');
cy.get('#uncontrolled-nav-toggle').focus();
cy.press(Cypress.Keyboard.Keys.TAB);
cy.focused().should('have.text', 'Main content link');

cy.get('#uncontrolled-nav-toggle').click();
cy.get('#uncontrolled-sidebar').should('have.attr', 'aria-hidden', 'false');
cy.get('#uncontrolled-nav-toggle').focus();
cy.press(Cypress.Keyboard.Keys.TAB);
cy.get('#uncontrolled-sidebar a').should('have.focus');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ export const PageManagedSidebarClosedDemo: React.FunctionComponent = () => {

const sidebar = (
<PageSidebar id="uncontrolled-sidebar">
<PageSidebarBody>Navigation</PageSidebarBody>
<PageSidebarBody>
<a href="#managed-sidebar-main-link">Navigation link</a>
</PageSidebarBody>
</PageSidebar>
);

return (
<Page id="page-managed-sidebar-closed-demo" isManagedSidebar masthead={masthead} sidebar={sidebar}>
<PageSection>Section </PageSection>
<PageSection>
<a href="#page-managed-sidebar-closed-demo" id="managed-sidebar-main-link">
Main content link
</a>
</PageSection>
</Page>
);
};
Expand Down