src/aria/widgets/form/list/ListController.js
function (flowOrientation, focusIndex, numberOfRows, numberOfColumns, keyCode, numberItems) {

            var moveFocus = focusIndex;

            if (numberOfColumns == 1) {
                if (keyCode == ariaDomEvent.KC_ARROW_UP) {
                    moveFocus--;
                }
                if (keyCode == ariaDomEvent.KC_ARROW_DOWN) {
                    moveFocus++;
                }
            } else {

                if (keyCode == ariaDomEvent.KC_ARROW_UP) {

                    if (flowOrientation == 'vertical') {
                        moveFocus = focusIndex - 1;
                    } else {
                        if (focusIndex - numberOfColumns < 0) {
                            moveFocus = focusIndex--;
                        } else {
                            moveFocus = focusIndex - numberOfColumns;
                        }
                    }

                } else if (keyCode == ariaDomEvent.KC_ARROW_DOWN) {

                    if (flowOrientation == 'vertical') {
                        moveFocus = focusIndex + 1;
                    } else {
                        if (numberOfColumns < numberItems - focusIndex) {
                            moveFocus = focusIndex + numberOfColumns;
                        } else {
                            return focusIndex;
                        }
                    }
                } else if (keyCode == ariaDomEvent.KC_ARROW_LEFT) {
                    if (flowOrientation == 'horizontal') {
                        moveFocus = focusIndex - 1;
                    } else {
                        if (focusIndex >= numberOfRows) {
                            moveFocus = focusIndex - numberOfRows;
                        } else {
                            return focusIndex;
                        }
                    }
                } else if (keyCode == ariaDomEvent.KC_ARROW_RIGHT) {
                    if (flowOrientation == 'horizontal') {
                        moveFocus = focusIndex + 1;
                    } else {
                        if (numberOfColumns < numberItems - focusIndex) {
                            moveFocus = focusIndex + numberOfRows;
                        } else {
                            return focusIndex;
                        }
                    }
                }
            }
            if (moveFocus >= numberItems) {
                return numberItems - 1;
            } else if (moveFocus < 0) {
                return 0;
            } else {
                return moveFocus;
            }

        }
function (flowOrientation, focusIndex, numberOfRows, numberOfColumns, keyCode, numberItems) {

            var moveFocus = focusIndex;

            if (numberOfColumns == 1) {
                if (keyCode == ariaDomEvent.KC_ARROW_UP) {
                    moveFocus--;
                }
                if (keyCode == ariaDomEvent.KC_ARROW_DOWN) {
                    moveFocus++;
                }
            } else {

                if (keyCode == ariaDomEvent.KC_ARROW_UP) {

                    if (flowOrientation == 'vertical') {
                        moveFocus = focusIndex - 1;
                    } else {
                        if (focusIndex - numberOfColumns < 0) {
                            moveFocus = focusIndex--;
                        } else {
                            moveFocus = focusIndex - numberOfColumns;
                        }
                    }

                } else if (keyCode == ariaDomEvent.KC_ARROW_DOWN) {

                    if (flowOrientation == 'vertical') {
                        moveFocus = focusIndex + 1;
                    } else {
                        if (numberOfColumns < numberItems - focusIndex) {
                            moveFocus = focusIndex + numberOfColumns;
                        } else {
                            return focusIndex;
                        }
                    }
                } else if (keyCode == ariaDomEvent.KC_ARROW_LEFT) {
                    if (flowOrientation == 'horizontal') {
                        moveFocus = focusIndex - 1;
                    } else {
                        if (focusIndex >= numberOfRows) {
                            moveFocus = focusIndex - numberOfRows;
                        } else {
                            return focusIndex;
                        }
                    }
                } else if (keyCode == ariaDomEvent.KC_ARROW_RIGHT) {
                    if (flowOrientation == 'horizontal') {
                        moveFocus = focusIndex + 1;
                    } else {
                        if (numberOfColumns < numberItems - focusIndex) {
                            moveFocus = focusIndex + numberOfRows;
                        } else {
                            return focusIndex;
                        }
                    }
                }
            }
            if (moveFocus >= numberItems) {
                return numberItems - 1;
            } else if (moveFocus < 0) {
                return 0;
            } else {
                return moveFocus;
            }

        }
function ( flowOrientation , focusIndex , numberOfRows , numberOfColumns , keyCode , numberItems ) { var moveFocus = focusIndex ; if ( numberOfColumns == 1 ) { if ( keyCode == ariaDomEvent . KC_ARROW_UP ) { moveFocus -- ; } if ( keyCode == ariaDomEvent . KC_ARROW_DOWN ) { moveFocus ++ ; } } else { if ( keyCode == ariaDomEvent . KC_ARROW_UP ) { if ( flowOrientation == 'vertical' ) { moveFocus = focusIndex - 1 ; } else { if ( focusIndex - numberOfColumns < 0 ) { moveFocus = focusIndex -- ; } else { moveFocus = focusIndex - numberOfColumns ; } } } else if ( keyCode == ariaDomEvent . KC_ARROW_DOWN ) { if ( flowOrientation == 'vertical' ) { moveFocus = focusIndex + 1 ; } else { if ( numberOfColumns < numberItems - focusIndex ) { moveFocus = focusIndex + numberOfColumns ; } else { return focusIndex ; } } } else if ( keyCode == ariaDomEvent . KC_ARROW_LEFT ) { if ( flowOrientation == 'horizontal' ) { moveFocus = focusIndex - 1 ; } else { if ( focusIndex >= numberOfRows ) { moveFocus = focusIndex - numberOfRows ; } else { return focusIndex ; } } } else if ( keyCode == ariaDomEvent . KC_ARROW_RIGHT ) { if ( flowOrientation == 'horizontal' ) { moveFocus = focusIndex + 1 ; } else { if ( numberOfColumns < numberItems - focusIndex ) { moveFocus = focusIndex + numberOfRows ; } else { return focusIndex ; } } } } if ( moveFocus >= numberItems ) { return numberItems - 1 ; } else if ( moveFocus < 0 ) { return 0 ; } else { return moveFocus ; } }
This method calculates which element of the list should have focus after a keypress
@param {String} flowOrientation Whether the items are listed horizonally or vertically
@param {String} focusIndex Which list item is currently focused
@param {String} numberOfRows How many rows are there in the list
@param {String} numberOfColumns How many columns are there in the list
@param {String} keyCode Which key was pressed
@param {String} numberItems How many items are in the list
@returns {Number}
This method calculates which element of the list should have focus after a keypress