improvement(netlify-cms-core): wrap navigations in lists for better a11y (#1903)

This commit is contained in:
Alexander Nanberg 2018-11-26 17:53:49 +01:00 committed by Shawn Erquhart
parent 37721718a5
commit 422d0cbe2f
2 changed files with 52 additions and 37 deletions

View File

@ -96,6 +96,12 @@ const AppHeaderQuickNewButton = styled(StyledDropdownButton)`
} }
`; `;
const AppHeaderNavList = styled.ul`
display: flex;
margin: 0;
list-style: none;
`;
class Header extends React.Component { class Header extends React.Component {
static propTypes = { static propTypes = {
user: ImmutablePropTypes.map.isRequired, user: ImmutablePropTypes.map.isRequired,
@ -135,26 +141,34 @@ class Header extends React.Component {
<AppHeader> <AppHeader>
<AppHeaderContent> <AppHeaderContent>
<nav> <nav>
<AppHeaderNavLink <AppHeaderNavList>
to="/" <li>
activeClassName="header-link-active" <AppHeaderNavLink
isActive={(match, location) => location.pathname.startsWith('/collections/')} to="/"
> activeClassName="header-link-active"
<Icon type="page" /> isActive={(match, location) => location.pathname.startsWith('/collections/')}
{t('app.header.content')} >
</AppHeaderNavLink> <Icon type="page" />
{hasWorkflow ? ( {t('app.header.content')}
<AppHeaderNavLink to="/workflow" activeClassName="header-link-active"> </AppHeaderNavLink>
<Icon type="workflow" /> </li>
{t('app.header.workflow')} {hasWorkflow && (
</AppHeaderNavLink> <li>
) : null} <AppHeaderNavLink to="/workflow" activeClassName="header-link-active">
{showMediaButton ? ( <Icon type="workflow" />
<AppHeaderButton onClick={openMediaLibrary}> {t('app.header.workflow')}
<Icon type="media-alt" /> </AppHeaderNavLink>
{t('app.header.media')} </li>
</AppHeaderButton> )}
) : null} {showMediaButton && (
<li>
<AppHeaderButton onClick={openMediaLibrary}>
<Icon type="media-alt" />
{t('app.header.media')}
</AppHeaderButton>
</li>
)}
</AppHeaderNavList>
</nav> </nav>
<AppHeaderActions> <AppHeaderActions>
{createableCollections.size > 0 && ( {createableCollections.size > 0 && (

View File

@ -35,7 +35,7 @@ const SidebarHeading = styled.h2`
const SearchContainer = styled.div` const SearchContainer = styled.div`
display: flex; display: flex;
align-items: center; align-items: center;
margin: 0 8px; margin: 0 12px;
position: relative; position: relative;
${Icon} { ${Icon} {
@ -65,6 +65,11 @@ const SearchInput = styled.input`
} }
`; `;
const SidebarNavList = styled.ul`
margin: 16px 0 0;
list-style: none;
`;
const SidebarNavLink = styled(NavLink)` const SidebarNavLink = styled(NavLink)`
display: flex; display: flex;
font-size: 14px; font-size: 14px;
@ -73,19 +78,17 @@ const SidebarNavLink = styled(NavLink)`
padding: 8px 12px; padding: 8px 12px;
border-left: 2px solid #fff; border-left: 2px solid #fff;
${Icon} {
margin-right: 8px;
}
${props => css` ${props => css`
&:hover, &:hover,
&:active, &:active,
&.${props.activeClassName} { &.${props.activeClassName} {
${styles.sidebarNavLinkActive}; ${styles.sidebarNavLinkActive};
} }
`} &:first-of-type { `};
margin-top: 16px;
}
${Icon} {
margin-right: 8px;
}
`; `;
class Sidebar extends React.Component { class Sidebar extends React.Component {
@ -104,14 +107,12 @@ class Sidebar extends React.Component {
renderLink = collection => { renderLink = collection => {
const collectionName = collection.get('name'); const collectionName = collection.get('name');
return ( return (
<SidebarNavLink <li key={collectionName}>
key={collectionName} <SidebarNavLink to={`/collections/${collectionName}`} activeClassName="sidebar-active">
to={`/collections/${collectionName}`} <Icon type="write" />
activeClassName="sidebar-active" {collection.get('label')}
> </SidebarNavLink>
<Icon type="write" /> </li>
{collection.get('label')}
</SidebarNavLink>
); );
}; };
@ -131,7 +132,7 @@ class Sidebar extends React.Component {
value={query} value={query}
/> />
</SearchContainer> </SearchContainer>
{collections.toList().map(this.renderLink)} <SidebarNavList>{collections.toList().map(this.renderLink)}</SidebarNavList>
</SidebarContainer> </SidebarContainer>
); );
} }