mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[ML] Ensure applying/removing groups menu is keyboard accessible (#24212)
* add group list arrow nav * up/down moved into own functions * always prevent default on arrow key press
This commit is contained in:
parent
db905c0da5
commit
da26fcbcce
2 changed files with 50 additions and 1 deletions
|
@ -12,6 +12,7 @@ import React, {
|
|||
|
||||
import {
|
||||
EuiIcon,
|
||||
keyCodes,
|
||||
} from '@elastic/eui';
|
||||
|
||||
import './styles/main.less';
|
||||
|
@ -47,22 +48,65 @@ export class GroupList extends Component {
|
|||
this.state = {
|
||||
groups: [],
|
||||
};
|
||||
// keep track of each of the group item refs
|
||||
this.selectItems = [];
|
||||
}
|
||||
|
||||
selectGroup = (group) => {
|
||||
this.props.selectGroup(group);
|
||||
}
|
||||
|
||||
moveUp = (event, index) => {
|
||||
event.preventDefault();
|
||||
if (index < 0) {
|
||||
return;
|
||||
} else if (index > 0) {
|
||||
this.selectItems[index - 1].focus();
|
||||
}
|
||||
}
|
||||
|
||||
moveDown = (event, index) => {
|
||||
event.preventDefault();
|
||||
if (index < this.selectItems.length - 1) {
|
||||
this.selectItems[index + 1].focus();
|
||||
}
|
||||
}
|
||||
|
||||
handleKeyDown = (event, group, index) => {
|
||||
switch (event.keyCode) {
|
||||
case keyCodes.ENTER:
|
||||
this.selectGroup(group);
|
||||
break;
|
||||
case keyCodes.SPACE:
|
||||
this.selectGroup(group);
|
||||
break;
|
||||
case keyCodes.DOWN:
|
||||
this.moveDown(event, index);
|
||||
break;
|
||||
case keyCodes.UP:
|
||||
this.moveUp(event, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setRef = (ref, index) => {
|
||||
this.selectItems[index] = ref;
|
||||
}
|
||||
|
||||
render() {
|
||||
const { selectedGroups, groups } = this.props;
|
||||
|
||||
return (
|
||||
<div className="group-list">
|
||||
{
|
||||
groups.map(g => (
|
||||
groups.map((g, index) => (
|
||||
<div
|
||||
tabIndex={'0'}
|
||||
onKeyDown={(event) => this.handleKeyDown(event, g, index)}
|
||||
key={g.id}
|
||||
className="group-item"
|
||||
onClick={() => this.selectGroup(g)}
|
||||
ref={(ref) => this.setRef(ref, index)}
|
||||
>
|
||||
<Check group={g} selectedGroups={selectedGroups} />
|
||||
<JobGroup name={g.id} />
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
border-bottom: 1px solid #eee;
|
||||
cursor: pointer;
|
||||
|
||||
&:focus {
|
||||
background-color: #eef6f9;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.check {
|
||||
width: 20px;
|
||||
display: inline-block;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue