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

fix(Page): improve a11y in sidebar and header #1145

Merged
merged 1 commit into from
Jan 28, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface PageHeaderProps extends HTMLProps<HTMLDivElement> {
avatar?: ReactNode;
topNav?: ReactNode;
showNavToggle?: boolean;
isNavOpen?: boolean;
onNavToggle?: Function;
}

Expand Down
14 changes: 11 additions & 3 deletions packages/patternfly-4/react-core/src/components/Page/PageHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ const propTypes = {
topNav: PropTypes.node,
/** True to show the nav toggle button (toggles side nav) */
showNavToggle: PropTypes.bool,
/** True if the side nav is shown */
isNavOpen: PropTypes.bool,
/** Callback function to handle the side nav toggle button */
onNavToggle: PropTypes.func,
/** Callback function to handle the side nav toggle button */
'aria-label': PropTypes.string,
/** Additional props are spread to the container <header> */
'': PropTypes.any
};
Expand All @@ -34,18 +38,22 @@ const defaultProps = {
avatar: null,
topNav: null,
showNavToggle: false,
onNavToggle: () => undefined
isNavOpen: true,
onNavToggle: () => undefined,
'aria-label': "Toggle global navigation",
};

const PageHeader = ({ className, logo, logoProps, toolbar, avatar, topNav, showNavToggle, onNavToggle, ...props }) => (
const PageHeader = ({ className, logo, logoProps, toolbar, avatar, topNav, isNavOpen, showNavToggle, onNavToggle, 'aria-label': ariaLabel, ...props }) => (
<header role="banner" className={css(styles.pageHeader, className)} {...props}>
<div className={css(styles.pageHeaderBrand)}>
{showNavToggle && (
<div className={css(styles.pageHeaderBrandToggle)}>
<Button
id="nav-toggle"
onClick={onNavToggle}
aria-label="Toggle primary navigation"
aria-label={ariaLabel}
aria-controls="page-sidebar"
aria-expanded={isNavOpen ? "true" : "false"}
variant={ButtonVariant.plain}
>
<BarsIcon />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const defaultProps = {
};

const PageSidebar = ({ className, nav, isNavOpen, ...props }) => (
<aside
<div
id="page-sidebar"
className={css(
styles.pageSidebar,
isNavOpen && styles.modifiers.expanded,
Expand All @@ -31,7 +32,7 @@ const PageSidebar = ({ className, nav, isNavOpen, ...props }) => (
{...props}
>
{nav}
</aside>
</div>
);

PageSidebar.propTypes = propTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ exports[`Check page horizontal layout example against snapshot 1`] = `
className="my-page-class"
header={
<PageHeader
aria-label="Toggle global navigation"
avatar=" | Avatar"
className=""
isNavOpen={true}
logo="Logo"
logoProps={null}
nav="Navigation"
Expand All @@ -105,8 +107,10 @@ exports[`Check page horizontal layout example against snapshot 1`] = `
layout="horizontal"
>
<PageHeader
aria-label="Toggle global navigation"
avatar=" | Avatar"
className=""
isNavOpen={true}
logo="Logo"
logoProps={null}
nav="Navigation"
Expand Down Expand Up @@ -142,8 +146,9 @@ exports[`Check page horizontal layout example against snapshot 1`] = `
isNavOpen={true}
nav={null}
>
<aside
<div
className="pf-c-page__sidebar pf-m-expanded"
id="page-sidebar"
/>
</PageSidebar>
<main
Expand Down Expand Up @@ -272,8 +277,10 @@ exports[`Check page vertical layout example against snapshot 1`] = `
className="my-page-class"
header={
<PageHeader
aria-label="Toggle global navigation"
avatar=" | Avatar"
className=""
isNavOpen={true}
logo="Logo"
logoProps={null}
onNavToggle={[Function]}
Expand All @@ -297,8 +304,10 @@ exports[`Check page vertical layout example against snapshot 1`] = `
id="PageId"
>
<PageHeader
aria-label="Toggle global navigation"
avatar=" | Avatar"
className=""
isNavOpen={true}
logo="Logo"
logoProps={null}
onNavToggle={[Function]}
Expand Down Expand Up @@ -332,11 +341,12 @@ exports[`Check page vertical layout example against snapshot 1`] = `
isNavOpen={true}
nav="Navigation"
>
<aside
<div
className="pf-c-page__sidebar pf-m-expanded"
id="page-sidebar"
>
Navigation
</aside>
</div>
</PageSidebar>
<main
className="pf-c-page__main"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ exports[`Check page vertical layout example against snapshot 1`] = `
}

<PageHeader
aria-label="Toggle global navigation"
avatar=" | Avatar"
className=""
isNavOpen={true}
logo="Logo"
logoProps={null}
onNavToggle={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class VerticalPage extends React.Component {
toolbar="Toolbar"
avatar=" | Avatar"
showNavToggle
isNavOpen={isNavOpen}
onNavToggle={this.onNavToggle}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class PageLayoutDefaultNav extends React.Component {
avatar={<Avatar src={avatarImg} alt="Avatar image" />}
showNavToggle
onNavToggle={this.onNavToggle}
isNavOpen={isNavOpen}
/>
);
const Sidebar = <PageSidebar nav={PageNav} isNavOpen={isNavOpen} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class PageLayoutExpandableNav extends React.Component {
avatar={<Avatar src={avatarImg} alt="Avatar image" />}
showNavToggle
onNavToggle={this.onNavToggle}
isNavOpen={isNavOpen}
/>
);
const Sidebar = <PageSidebar nav={PageNav} isNavOpen={isNavOpen} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class PageLayoutGroupsNav extends React.Component {
avatar={<Avatar src={avatarImg} alt="Avatar image" />}
showNavToggle
onNavToggle={this.onNavToggle}
isNavOpen={isNavOpen}
/>
);
const Sidebar = <PageSidebar nav={PageNav} isNavOpen={isNavOpen} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class PageLayoutSimpleNav extends React.Component {
avatar={<Avatar src={avatarImg} alt="Avatar image" />}
showNavToggle
onNavToggle={this.onNavToggle}
isNavOpen={isNavOpen}
/>
);
const Sidebar = <PageSidebar nav={PageNav} isNavOpen={isNavOpen} />;
Expand Down