Skip to content

Commit

Permalink
fix: grid navigation class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rita committed Feb 21, 2025
1 parent 0909318 commit 20aa21f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions components/header-bar/src/command-palette/utils/grid-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ class GridNavigation {
getLastIndexOfActiveRow = (highlightedIndex, gridSize) => {
const activeRow = this.getActiveRow(highlightedIndex)
const lastIndexPerRowArray = this.getLastIndexPerRow(gridSize)
const lastIndexOfActiveRow = lastIndexPerRowArray[activeRow]

return lastIndexPerRowArray[activeRow]
return lastIndexOfActiveRow || highlightedIndex
}

getFirstIndexOfLastRow = () => {
Expand Down Expand Up @@ -83,9 +84,10 @@ class GridNavigation {
const firstIndexOfActiveRow =
this.getFirstIndexOfActiveRow(highlightedIndex)

const lastIndexOfActiveRow =
this.getLastIndexOfActiveRow(highlightedIndex, gridSize) ||
highlightedIndex
const lastIndexOfActiveRow = this.getLastIndexOfActiveRow(
highlightedIndex,
gridSize
)

return highlightedIndex > firstIndexOfActiveRow
? highlightedIndex - 1
Expand All @@ -95,16 +97,17 @@ class GridNavigation {
getNextRightIndex = (highlightedIndex, gridSize) => {
const firstIndexOfActiveRow =
this.getFirstIndexOfActiveRow(highlightedIndex)
const lastIndexOfActiveRow =
this.getLastIndexOfActiveRow(highlightedIndex, gridSize) ||
highlightedIndex
const lastIndexOfActiveRow = this.getLastIndexOfActiveRow(
highlightedIndex,
gridSize
)

return highlightedIndex >= lastIndexOfActiveRow
? firstIndexOfActiveRow
: highlightedIndex + 1
}

getNextUpperIndex = ({
static getNextUpperIndex = ({
isTopIndexInCurrentSection,
lastIndexInNextSection,
verticalGap,
Expand All @@ -117,7 +120,7 @@ class GridNavigation {
}
}

getNextLowerIndex = ({
static getNextLowerIndex = ({
isLastIndexInCurrentSection,
verticalGap,
highlightedIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const handleHomeNavigation = ({
? actionsListLength - 1
: grid.getFirstIndexOfLastRow()

const nextTopIndex = grid.getNextUpperIndex({
const nextTopIndex = GridNavigation.getNextUpperIndex({
isTopIndexInCurrentSection: isTopIndex,
lastIndexInNextSection,
verticalGap,
Expand All @@ -78,7 +78,7 @@ export const handleHomeNavigation = ({
? grid.isInLastRow(highlightedIndex, gridSize)
: isLastListIndex(highlightedIndex, actionsListLength)

const nextLowerIndex = grid.getNextLowerIndex({
const nextLowerIndex = GridNavigation.getNextLowerIndex({
isLastIndexInCurrentSection: isLastIndex,
verticalGap,
highlightedIndex,
Expand Down

0 comments on commit 20aa21f

Please sign in to comment.