Skip to content

Commit fbe66d5

Browse files
authored
EuiNavDrawer a11y, pt. 1 (#2643)
* lock button aria-pressed * maintain focus state * CL
1 parent a05b1e7 commit fbe66d5

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
## [`master`](https://github.com/elastic/eui/tree/master)
22

3+
- Improved a11y of `EuiNavDrawer` lock button state via `aria-pressed` ([#2643](https://github.com/elastic/eui/pull/2643))
4+
35
**Bug fixes**
46

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

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

src/components/list_group/list_group_item.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ export type EuiListGroupItemProps = CommonProps &
9595
* Allow link text to wrap
9696
*/
9797
wrapText?: boolean;
98+
99+
/**
100+
* Pass-through ref reference specifically for targeting
101+
* instances where the item content is rendered as a `button`
102+
*/
103+
buttonRef?: React.RefObject<HTMLButtonElement>;
98104
};
99105

100106
export const EuiListGroupItem: FunctionComponent<EuiListGroupItemProps> = ({
@@ -110,6 +116,7 @@ export const EuiListGroupItem: FunctionComponent<EuiListGroupItemProps> = ({
110116
size = 'm',
111117
showToolTip = false,
112118
wrapText,
119+
buttonRef,
113120
...rest
114121
}) => {
115122
const classes = classNames(
@@ -200,6 +207,7 @@ export const EuiListGroupItem: FunctionComponent<EuiListGroupItemProps> = ({
200207
className="euiListGroupItem__button"
201208
disabled={isDisabled}
202209
onClick={onClick}
210+
ref={buttonRef}
203211
{...rest as ButtonHTMLAttributes<HTMLButtonElement>}>
204212
{iconNode}
205213
{labelContent}

src/components/nav_drawer/nav_drawer.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { throttle } from '../color_picker/utils';
1212
export class EuiNavDrawer extends Component {
1313
constructor(props) {
1414
super(props);
15+
this.expandButtonRef;
1516

1617
this.state = {
1718
isLocked: props.isLocked,
@@ -65,19 +66,6 @@ export class EuiNavDrawer extends Component {
6566
});
6667
};
6768

68-
toggleOpen = () => {
69-
this.setState({
70-
isCollapsed: !this.state.isCollapsed,
71-
});
72-
73-
setTimeout(() => {
74-
this.setState({
75-
outsideClickDisabled: this.state.isCollapsed ? true : false,
76-
toolTipsEnabled: this.state.isCollapsed ? true : false,
77-
});
78-
}, 150);
79-
};
80-
8169
collapseButtonClick = () => {
8270
if (this.state.isCollapsed) {
8371
this.expandDrawer();
@@ -86,6 +74,12 @@ export class EuiNavDrawer extends Component {
8674
}
8775

8876
this.collapseFlyout();
77+
78+
requestAnimationFrame(() => {
79+
if (this.expandButtonRef) {
80+
this.expandButtonRef.focus();
81+
}
82+
});
8983
};
9084

9185
expandDrawer = () => {
@@ -253,6 +247,7 @@ export class EuiNavDrawer extends Component {
253247
sideNavLockCollapsed,
254248
]) => (
255249
<EuiListGroupItem
250+
buttonRef={node => (this.expandButtonRef = node)}
256251
label={this.state.isCollapsed ? sideNavExpand : sideNavCollapse}
257252
iconType={this.state.isCollapsed ? 'menuRight' : 'menuLeft'}
258253
size="s"
@@ -272,8 +267,7 @@ export class EuiNavDrawer extends Component {
272267
title: this.state.isLocked
273268
? sideNavLockExpanded
274269
: sideNavLockCollapsed,
275-
'aria-checked': this.state.isLocked ? true : false,
276-
role: 'switch',
270+
'aria-pressed': this.state.isLocked ? true : false,
277271
}}
278272
onClick={this.collapseButtonClick}
279273
data-test-subj={
@@ -334,7 +328,6 @@ export class EuiNavDrawer extends Component {
334328
id="navDrawerMenu"
335329
className={menuClasses}
336330
onClick={this.handleDrawerMenuClick}>
337-
{/* Put expand button first so it's first in tab order then on toggle starts the tabbing of the items from the top */}
338331
{/* TODO: Add a "skip navigation" keyboard only button */}
339332
{footerContent}
340333
{modifiedChildren}

0 commit comments

Comments
 (0)