-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix - Message action menu - Last option is not selected when pressing up key #38007
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,6 +12,7 @@ type Config = { | |||||
itemsPerRow?: number; | ||||||
disableCyclicTraversal?: boolean; | ||||||
disableHorizontalKeys?: boolean; | ||||||
allowNegativeIndexes?: boolean; | ||||||
}; | ||||||
|
||||||
type UseArrowKeyFocusManager = [number, (index: number) => void]; | ||||||
|
@@ -44,6 +45,7 @@ export default function useArrowKeyFocusManager({ | |||||
itemsPerRow, | ||||||
disableCyclicTraversal = false, | ||||||
disableHorizontalKeys = false, | ||||||
allowNegativeIndexes = false, | ||||||
}: Config): UseArrowKeyFocusManager { | ||||||
const allowHorizontalArrowKeys = !!itemsPerRow; | ||||||
const [focusedIndex, setFocusedIndex] = useState(initialFocusedIndex); | ||||||
|
@@ -84,7 +86,13 @@ export default function useArrowKeyFocusManager({ | |||||
while (disabledIndexes.includes(newFocusedIndex)) { | ||||||
newFocusedIndex -= allowHorizontalArrowKeys ? itemsPerRow : 1; | ||||||
if (newFocusedIndex < 0) { | ||||||
break; | ||||||
if (disableCyclicTraversal) { | ||||||
if (!allowNegativeIndexes) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this fixing something? Everything seems to work fine for me without this if statement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is the exceptional case for emoji picker menu so if you remove it, it will break the emoji picker search input auto focusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm strange, it seems to work just fine for me with this block removed. Am I missing something here? Screen.Recording.2024-03-13.at.08.29.15.movThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't talking about the removal of that logic, I thought you were asking why we need that check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could you quickly demonstrate this just so I can understand what exactly we are fixing here? Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we use the App/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.tsx Lines 157 to 158 in 6e42e55
Now, while you are on the first active index if you press up the focus will be lost and unless u press down it will not appear that is what it will cause if we use the break logic but now as it is the emoji picker the only exceptional case we allow negative indexes to auto focus search input we are treating it as an exception. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok so while it essentially has no effect currently, I suppose it's better for future-proofing. Thanks for the explanation! |
||||||
return actualIndex; | ||||||
} | ||||||
break; | ||||||
} | ||||||
newFocusedIndex = maxIndex; | ||||||
} | ||||||
if (newFocusedIndex === currentFocusedIndex) { | ||||||
// all indexes are disabled | ||||||
|
@@ -93,7 +101,7 @@ export default function useArrowKeyFocusManager({ | |||||
} | ||||||
return newFocusedIndex; | ||||||
}); | ||||||
}, [allowHorizontalArrowKeys, disableCyclicTraversal, disabledIndexes, itemsPerRow, maxIndex]); | ||||||
}, [allowHorizontalArrowKeys, disableCyclicTraversal, disabledIndexes, itemsPerRow, maxIndex, allowNegativeIndexes]); | ||||||
|
||||||
useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ARROW_UP, arrowUpCallback, arrowConfig); | ||||||
|
||||||
|
@@ -127,8 +135,11 @@ export default function useArrowKeyFocusManager({ | |||||
newFocusedIndex += allowHorizontalArrowKeys ? itemsPerRow : 1; | ||||||
} | ||||||
|
||||||
if (newFocusedIndex < 0) { | ||||||
break; | ||||||
if (newFocusedIndex > maxIndex) { | ||||||
if (disableCyclicTraversal) { | ||||||
return actualIndex; | ||||||
} | ||||||
newFocusedIndex = 0; | ||||||
} | ||||||
if (newFocusedIndex === currentFocusedIndex) { | ||||||
// all indexes are disabled | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this being used anywhere or did you just add it for possible use in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using it here for
EmojiPickerMenu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see yeah we're passing false for useArrowKeyFocusManager outside of that.