Skip to content

Commit

Permalink
fix(Page): improve a11y in sidebar and header (patternfly#1145)
Browse files Browse the repository at this point in the history
Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>
  • Loading branch information
boaz0 authored and dlabaj committed Jan 28, 2019
1 parent 2feb026 commit 274d7f7
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 8 deletions.
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

0 comments on commit 274d7f7

Please sign in to comment.