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

EuiNavDrawer a11y, pt. 1 #2643

Merged
merged 4 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions src/components/list_group/list_group_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ export type EuiListGroupItemProps = CommonProps &
* Allow link text to wrap
*/
wrapText?: boolean;

/**
* Pass-through ref reference specifically for targeting
* instances where the item content is rendered as a `button`
*/
buttonRef?: React.RefObject<HTMLButtonElement>;
};

export const EuiListGroupItem: FunctionComponent<EuiListGroupItemProps> = ({
Expand All @@ -110,6 +116,7 @@ export const EuiListGroupItem: FunctionComponent<EuiListGroupItemProps> = ({
size = 'm',
showToolTip = false,
wrapText,
buttonRef,
...rest
}) => {
const classes = classNames(
Expand Down Expand Up @@ -200,6 +207,7 @@ export const EuiListGroupItem: FunctionComponent<EuiListGroupItemProps> = ({
className="euiListGroupItem__button"
disabled={isDisabled}
onClick={onClick}
ref={buttonRef}
{...rest as ButtonHTMLAttributes<HTMLButtonElement>}>
{iconNode}
{labelContent}
Expand Down
25 changes: 9 additions & 16 deletions src/components/nav_drawer/nav_drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { throttle } from '../color_picker/utils';
export class EuiNavDrawer extends Component {
constructor(props) {
super(props);
this.expandButtonRef;

this.state = {
isLocked: props.isLocked,
Expand Down Expand Up @@ -65,19 +66,6 @@ export class EuiNavDrawer extends Component {
});
};

toggleOpen = () => {
this.setState({
isCollapsed: !this.state.isCollapsed,
});

setTimeout(() => {
this.setState({
outsideClickDisabled: this.state.isCollapsed ? true : false,
toolTipsEnabled: this.state.isCollapsed ? true : false,
});
}, 150);
};

collapseButtonClick = () => {
if (this.state.isCollapsed) {
this.expandDrawer();
Expand All @@ -86,6 +74,12 @@ export class EuiNavDrawer extends Component {
}

this.collapseFlyout();

requestAnimationFrame(() => {
if (this.expandButtonRef) {
this.expandButtonRef.focus();
}
});
};

expandDrawer = () => {
Expand Down Expand Up @@ -253,6 +247,7 @@ export class EuiNavDrawer extends Component {
sideNavLockCollapsed,
]) => (
<EuiListGroupItem
buttonRef={node => (this.expandButtonRef = node)}
label={this.state.isCollapsed ? sideNavExpand : sideNavCollapse}
iconType={this.state.isCollapsed ? 'menuRight' : 'menuLeft'}
size="s"
Expand All @@ -272,8 +267,7 @@ export class EuiNavDrawer extends Component {
title: this.state.isLocked
? sideNavLockExpanded
: sideNavLockCollapsed,
'aria-checked': this.state.isLocked ? true : false,
role: 'switch',
'aria-pressed': this.state.isLocked ? true : false,
}}
onClick={this.collapseButtonClick}
data-test-subj={
Expand Down Expand Up @@ -334,7 +328,6 @@ export class EuiNavDrawer extends Component {
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}
Expand Down