| 194 | } |
| 195 | |
| 196 | _handleUp() { |
| 197 | const itemsLength = this._getItems().length; |
| 198 | if (this._currentIndex - this._rowSize >= 0) { // no border reached, just decrease the index by a row |
| 199 | this._currentIndex -= this._rowSize; |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | if (this._behavior === ItemNavigationBehavior.Cyclic) { // if cyclic, go to the **last** item in the **previous** column |
| 204 | const firstItemInThisColumnIndex = this._currentIndex % this._rowSize; |
| 205 | const firstItemInPreviousColumnIndex = firstItemInThisColumnIndex === 0 ? this._rowSize - 1 : firstItemInThisColumnIndex - 1; // find the first item in the previous column (if the current column is the first column -> move to the last column) |
| 206 | const rows = Math.ceil(itemsLength / this._rowSize); // how many rows there are (even if incomplete, f.e. for 14 items and _rowSize=4 -> 4 rows total, although only 2 items on the last row) |
| 207 | let lastItemInPreviousColumnIndex = firstItemInPreviousColumnIndex + (rows - 1) * this._rowSize; // multiply rows by columns, and add the column's first item's index |
| 208 | if (lastItemInPreviousColumnIndex > itemsLength - 1) { // for incomplete rows, use the previous row's last item, as for them the last item is missing |
| 209 | lastItemInPreviousColumnIndex -= this._rowSize; |
| 210 | } |
| 211 | this._currentIndex = lastItemInPreviousColumnIndex; |
| 212 | } else { // not cyclic, so just go to the first item |
| 213 | this._currentIndex = 0; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | _handleDown() { |
| 218 | const itemsLength = this._getItems().length; |