change counter variable name
This commit is contained in:
parent
3ffc7f34f8
commit
26b40e9fb0
@ -25,7 +25,7 @@ export default class DropdownList extends Component {
|
|||||||
this.childrenRefs = [];
|
this.childrenRefs = [];
|
||||||
this.handleItemKeyDown = this.handleItemKeyDown.bind(this);
|
this.handleItemKeyDown = this.handleItemKeyDown.bind(this);
|
||||||
this.handleItemClick = this.handleItemClick.bind(this);
|
this.handleItemClick = this.handleItemClick.bind(this);
|
||||||
this.counter = 0;
|
this.focusedItemIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
@ -51,7 +51,7 @@ export default class DropdownList extends Component {
|
|||||||
handleItemKeyDown(event, callback) {
|
handleItemKeyDown(event, callback) {
|
||||||
const { dropdownHide } = this.props;
|
const { dropdownHide } = this.props;
|
||||||
const { activeItemIndex } = this.state;
|
const { activeItemIndex } = this.state;
|
||||||
|
|
||||||
let selectableItems = [];
|
let selectableItems = [];
|
||||||
for (let i = 0; i < (this._menu.children.length); i++) {
|
for (let i = 0; i < (this._menu.children.length); i++) {
|
||||||
if (this._menu.children[i].getAttribute("role") === 'menuitem'){
|
if (this._menu.children[i].getAttribute("role") === 'menuitem'){
|
||||||
@ -63,7 +63,7 @@ export default class DropdownList extends Component {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
selectableItems[this.counter].focus();
|
selectableItems[this.focusedItemIndex].focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([KEY_CODES.ENTER, KEY_CODES.SPACE].includes(event.keyCode)) {
|
if ([KEY_CODES.ENTER, KEY_CODES.SPACE].includes(event.keyCode)) {
|
||||||
@ -74,20 +74,20 @@ export default class DropdownList extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (KEY_CODES.ARROW_DOWN === event.which) {
|
if (KEY_CODES.ARROW_DOWN === event.which) {
|
||||||
this.counter += 1;
|
this.focusedItemIndex += 1;
|
||||||
|
|
||||||
if (!selectableItems[this.counter]) {
|
if (!selectableItems[this.focusedItemIndex]) {
|
||||||
this.counter = 0;
|
this.focusedItemIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
focusMenuItem();
|
focusMenuItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (KEY_CODES.ARROW_UP === event.which) {
|
if (KEY_CODES.ARROW_UP === event.which) {
|
||||||
this.counter -= 1;
|
this.focusedItemIndex -= 1;
|
||||||
|
|
||||||
if (this.counter < 0) {
|
if (this.focusedItemIndex < 0) {
|
||||||
this.counter = selectableItems.length - 1;
|
this.focusedItemIndex = selectableItems.length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
focusMenuItem();
|
focusMenuItem();
|
||||||
|
@ -93,7 +93,7 @@ class UserList extends Component {
|
|||||||
if (event.keyCode === KEY_CODES.ARROW_UP) {
|
if (event.keyCode === KEY_CODES.ARROW_UP) {
|
||||||
this.focusedItemIndex -= 1;
|
this.focusedItemIndex -= 1;
|
||||||
|
|
||||||
if (this.focusedItemIndex <= -1) {
|
if (this.focusedItemIndex < 0) {
|
||||||
this.focusedItemIndex = numberOfItems - 1;
|
this.focusedItemIndex = numberOfItems - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user