Skip to content

Commit

Permalink
Improve a11y in EuiNavDrawer (#2417)
Browse files Browse the repository at this point in the history
* updated docs and added focus state to button

* cl

* trying to make aria-label dynamic

* trying to make aria-label dynamic

* added missing underline property

* making hover and focus behave differently

* updated aria-labels

* remove unneeded line

* cl

* use nav and avoid a11y error

* remove role=presentation
  • Loading branch information
andreadelrio authored and thompsongl committed Oct 14, 2019
1 parent f475ce9 commit 1299399
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Added `component` prop to `EuiPageBody`, switching the default from `div` to `main` ([#2410](https://github.com/elastic/eui/pull/2410))
- Added focus state to `EuiListGroupItem` ([#2406](https://github.com/elastic/eui/pull/2406))
- Added `keyboardShorcut` glyph to 'EuiIcon ([#2413](https://github.com/elastic/eui/pull/2413))
- Improved a11y in `EuiNavDrawer` ([#2417](https://github.com/elastic/eui/pull/2417))

**Bug fixes**

Expand Down
32 changes: 18 additions & 14 deletions src-docs/src/views/nav_drawer/nav_drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export default class extends Component {
color: 'subdued',
iconType: 'pin',
iconSize: 's',
'aria-label': 'Pin to top',
};

const pinExtraActionFn = val => {
pinExtraAction['aria-label'] = `Pin ${val} to top`;
return pinExtraAction;
};

this.topLinks = [
Expand Down Expand Up @@ -124,43 +128,43 @@ export default class extends Component {
iconType: 'canvasApp',
isActive: true,
extraAction: {
...pinExtraAction,
...pinExtraActionFn('Canvas'),
alwaysShow: true,
},
},
{
label: 'Discover',
href: '#/layout/nav-drawer',
iconType: 'discoverApp',
extraAction: pinExtraAction,
extraAction: { ...pinExtraActionFn('Discover') },
},
{
label: 'Visualize',
href: '#/layout/nav-drawer',
iconType: 'visualizeApp',
extraAction: pinExtraAction,
extraAction: { ...pinExtraActionFn('Visualize') },
},
{
label: 'Dashboard',
href: '#/layout/nav-drawer',
iconType: 'dashboardApp',
extraAction: pinExtraAction,
extraAction: { ...pinExtraActionFn('Dashboard') },
},
{
label: 'Machine learning',
href: '#/layout/nav-drawer',
iconType: 'machineLearningApp',
extraAction: pinExtraAction,
extraAction: { ...pinExtraActionFn('Machine learning') },
},
{
label: 'Custom Plugin (no icon)',
href: '#/layout/nav-drawer',
extraAction: pinExtraAction,
extraAction: { ...pinExtraActionFn('Custom Plugin') },
},
{
label: 'Nature Plugin (image as icon)',
href: '#/layout/nav-drawer',
extraAction: pinExtraAction,
extraAction: { ...pinExtraActionFn('Nature Plugin') },
icon: (
<EuiImage
size="s"
Expand All @@ -176,37 +180,37 @@ export default class extends Component {
label: 'APM',
href: '#/layout/nav-drawer',
iconType: 'apmApp',
extraAction: pinExtraAction,
extraAction: { ...pinExtraActionFn('APM') },
},
{
label: 'Infrastructure',
href: '#/layout/nav-drawer',
iconType: 'infraApp',
extraAction: pinExtraAction,
extraAction: { ...pinExtraActionFn('Infrastructure') },
},
{
label: 'Log viewer',
href: '#/layout/nav-drawer',
iconType: 'loggingApp',
extraAction: pinExtraAction,
extraAction: { ...pinExtraActionFn('Log viewer') },
},
{
label: 'Uptime',
href: '#/layout/nav-drawer',
iconType: 'upgradeAssistantApp',
extraAction: pinExtraAction,
extraAction: { ...pinExtraActionFn('Uptime') },
},
{
label: 'Maps',
href: '#/layout/nav-drawer',
iconType: 'gisApp',
extraAction: pinExtraAction,
extraAction: { ...pinExtraActionFn('Maps') },
},
{
label: 'SIEM',
href: '#/layout/nav-drawer',
iconType: 'securityAnalyticsApp',
extraAction: pinExtraAction,
extraAction: { ...pinExtraActionFn('SIEM') },
},
];

Expand Down
6 changes: 5 additions & 1 deletion src/components/nav_drawer/_nav_drawer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@
transition: width $euiAnimSpeedExtraFast;
z-index: $euiZHeader + 1;

.euiListGroupItem__button {
.navDrawerExpandButton-isExpanded .euiListGroupItem__button {
padding: $euiSizeM $euiSize;
}

.navDrawerExpandButton-isCollapsed .euiListGroupItem__button {
max-width: $euiSizeXL;
}
}

&.euiNavDrawer-isCollapsed {
Expand Down
47 changes: 26 additions & 21 deletions src/components/nav_drawer/nav_drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EuiNavDrawerFlyout } from './nav_drawer_flyout';
import { EuiNavDrawerGroup } from './nav_drawer_group';
import { EuiOutsideClickDetector } from '../outside_click_detector';
import { EuiI18n } from '../i18n';
import { EuiFlexItem } from '../flex';
import { EuiFlexItem, EuiFlexGroup } from '../flex';
import { throttle } from '../color_picker/utils';

export class EuiNavDrawer extends Component {
Expand Down Expand Up @@ -229,7 +229,7 @@ export class EuiNavDrawer extends Component {
let footerContent;
if (showExpandButton) {
footerContent = (
<EuiListGroup className="euiNavDrawer__expandButton" flush>
<EuiListGroup className="euiNavDrawer__expandButton">
<EuiI18n
tokens={[
'euiNavDrawer.sideNavCollapse',
Expand All @@ -256,6 +256,11 @@ export class EuiNavDrawer extends Component {
label={this.state.isCollapsed ? sideNavExpand : sideNavCollapse}
iconType={this.state.isCollapsed ? 'menuRight' : 'menuLeft'}
size="s"
className={
this.state.isCollapsed
? 'navDrawerExpandButton-isCollapsed'
: 'navDrawerExpandButton-isExpanded'
}
showToolTip={this.state.isCollapsed}
extraAction={{
className: 'euiNavDrawer__expandButtonLockAction',
Expand Down Expand Up @@ -319,25 +324,25 @@ export class EuiNavDrawer extends Component {
<EuiOutsideClickDetector
onOutsideClick={() => this.closeBoth()}
isDisabled={this.state.outsideClickDisabled}>
<div
className={classes}
onBlur={this.focusOut}
onFocus={this.manageFocus}
{...rest}>
<EuiFlexItem grow={false}>
<div
id="navDrawerMenu"
className={menuClasses}
onClick={this.handleDrawerMenuClick}>
{/* Put expand button first so it's first in tab order then on toggle starts the tabbing of the items from the top */}
{/* TODO: Add a "skip navigation" keyboard only button */}
{footerContent}
{modifiedChildren}
</div>
</EuiFlexItem>

{flyoutContent}
</div>
<nav className={classes} {...rest}>
<EuiFlexGroup
gutterSize="none"
onBlur={this.focusOut}
onFocus={this.manageFocus}>
<EuiFlexItem grow={false}>
<div
id="navDrawerMenu"
className={menuClasses}
onClick={this.handleDrawerMenuClick}>
{/* Put expand button first so it's first in tab order then on toggle starts the tabbing of the items from the top */}
{/* TODO: Add a "skip navigation" keyboard only button */}
{modifiedChildren}
{footerContent}
</div>
</EuiFlexItem>
{flyoutContent}
</EuiFlexGroup>
</nav>
</EuiOutsideClickDetector>
);
}
Expand Down

0 comments on commit 1299399

Please sign in to comment.