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,6 +141,8 @@ class Header extends React.Component {
<AppHeader> <AppHeader>
<AppHeaderContent> <AppHeaderContent>
<nav> <nav>
<AppHeaderNavList>
<li>
<AppHeaderNavLink <AppHeaderNavLink
to="/" to="/"
activeClassName="header-link-active" activeClassName="header-link-active"
@ -143,18 +151,24 @@ class Header extends React.Component {
<Icon type="page" /> <Icon type="page" />
{t('app.header.content')} {t('app.header.content')}
</AppHeaderNavLink> </AppHeaderNavLink>
{hasWorkflow ? ( </li>
{hasWorkflow && (
<li>
<AppHeaderNavLink to="/workflow" activeClassName="header-link-active"> <AppHeaderNavLink to="/workflow" activeClassName="header-link-active">
<Icon type="workflow" /> <Icon type="workflow" />
{t('app.header.workflow')} {t('app.header.workflow')}
</AppHeaderNavLink> </AppHeaderNavLink>
) : null} </li>
{showMediaButton ? ( )}
{showMediaButton && (
<li>
<AppHeaderButton onClick={openMediaLibrary}> <AppHeaderButton onClick={openMediaLibrary}>
<Icon type="media-alt" /> <Icon type="media-alt" />
{t('app.header.media')} {t('app.header.media')}
</AppHeaderButton> </AppHeaderButton>
) : null} </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}`}
activeClassName="sidebar-active"
>
<Icon type="write" /> <Icon type="write" />
{collection.get('label')} {collection.get('label')}
</SidebarNavLink> </SidebarNavLink>
</li>
); );
}; };
@ -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>
); );
} }