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 all 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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Improved a11y of `EuiNavDrawer` lock button state via `aria-pressed` ([#2643](https://github.com/elastic/eui/pull/2643))

**Bug fixes**

- Improved `EuiDataGrid` update performance ([#2638](https://github.com/elastic/eui/pull/2638))
- Fixed `EuiDroppable` not accepting multiple children when using TypeScript ([#2634](https://github.com/elastic/eui/pull/2634))
- Fixed `EuiComboBox` from submitting parent `form` element when selecting options via `Enter` key ([#2642](https://github.com/elastic/eui/pull/2642))
- Fixed `EuiComboBox` from submitting parent `form` element when selecting options via `Enter` key ([#2642](https://github.com/elastic/eui/pull/2642))
- Fixed `EuiNavDrawer` expand button from losing focus after click ([#2643](https://github.com/elastic/eui/pull/2643))

## [`17.1.2`](https://github.com/elastic/eui/tree/v17.1.2)

Expand Down
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