Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,8 @@
],
);

const canEditParticipant = isFromGlobalCreateAndCanEditParticipant && !isTestReceipt && (!isRestrictedToPreferredPolicy || isTypeInvoice);

const sections = useMemo(() => {
const options: Array<Section<MoneyRequestConfirmationListItem>> = [];
if (isTypeSplit) {
Expand All @@ -895,8 +897,8 @@
...participant,
isSelected: false,
keyForList: `${participant.keyForList ?? participant.accountID ?? participant.reportID}`,
isInteractive: isFromGlobalCreateAndCanEditParticipant && !isTestReceipt && (!isRestrictedToPreferredPolicy || isTypeInvoice),
shouldShowRightCaret: isFromGlobalCreateAndCanEditParticipant && !isTestReceipt && (!isRestrictedToPreferredPolicy || isTypeInvoice),
isInteractive: canEditParticipant,
shouldShowRightCaret: canEditParticipant,
}));

options.push({
Expand All @@ -907,19 +909,7 @@
}

return options;
}, [
isTypeSplit,
translate,
payeePersonalDetails,
getSplitSectionHeader,
splitParticipants,
selectedParticipants,
isFromGlobalCreateAndCanEditParticipant,
isTestReceipt,
isRestrictedToPreferredPolicy,
isTypeInvoice,
shouldHideToSection,
]);
}, [isTypeSplit, translate, payeePersonalDetails, getSplitSectionHeader, splitParticipants, selectedParticipants, canEditParticipant, shouldHideToSection]);

useEffect(() => {
if (!isDistanceRequest || (isMovingTransactionFromTrackExpense && !isPolicyExpenseChat) || !transactionID || isReadOnly) {
Expand Down Expand Up @@ -1007,7 +997,7 @@
* Navigate to the participant step
*/
const navigateToParticipantPage = () => {
if (!isFromGlobalCreateAndCanEditParticipant) {
if (!canEditParticipant) {
return;
}

Expand Down Expand Up @@ -1148,7 +1138,7 @@
onSendMoney?.(paymentMethod);
}
},
[

Check warning on line 1141 in src/components/MoneyRequestConfirmationList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useCallback has a missing dependency: 'isNewManualExpenseFlowEnabled'. Either include it or remove the dependency array

Check warning on line 1141 in src/components/MoneyRequestConfirmationList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has a missing dependency: 'isNewManualExpenseFlowEnabled'. Either include it or remove the dependency array
routeError,
transactionID,
iouType,
Expand Down
3 changes: 2 additions & 1 deletion src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function BaseSelectionList<TItem extends ListItem>({
}, [data, focusedIndex, isItemSelected]);

const selectFocusedOption = () => {
if (!focusedOption) {
if (!focusedOption || focusedOption.isInteractive === false) {
return;
}
selectRow(focusedOption);
Expand Down Expand Up @@ -363,6 +363,7 @@ function BaseSelectionList<TItem extends ListItem>({
shouldSyncFocus={!isTextInputFocusedRef.current && hasKeyBeenPressed.current}
shouldDisableHoverStyle={shouldDisableHoverStyle}
shouldShowRightCaret={shouldShowRightCaret}
shouldPreventEnterKeySubmit={!disableKeyboardShortcuts}
/>
);
};
Expand Down
25 changes: 25 additions & 0 deletions src/components/SelectionList/ListItem/BaseListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ function BaseListItem<TItem extends ListItem>({

// Sync focus on an item
useSyncFocus(pressableRef, !!isFocused, shouldSyncFocus);

// List items use role="option" which doesn't natively respond to Enter key presses.
// When the list-level keyboard shortcut is disabled (disableKeyboardShortcuts), we handle
// Enter activation here at the item level so each row can still be activated individually
// without interfering with other focusable controls (e.g. footer inputs) on the same screen.
const handleKeyDown = (event: React.KeyboardEvent) => {
if (
shouldPreventEnterKeySubmit ||
accessible === false ||
event.key !== CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey ||
event.shiftKey ||
event.metaKey ||
event.ctrlKey ||
item.isInteractive === false
) {
return;
}

event.preventDefault();
onSelectRow(item);
};

const handleMouseLeave = (e: React.MouseEvent<Element, MouseEvent>) => {
bind.onMouseLeave();
e.stopPropagation();
Expand Down Expand Up @@ -191,6 +213,9 @@ function BaseListItem<TItem extends ListItem>({
{...accessibleAndAccessibilityLabel}
accessibilityState={accessibilityState}
onMouseLeave={handleMouseLeave}
// When the list-level Enter shortcut is disabled (disableKeyboardShortcuts), items with role="option"
// won't natively fire click on Enter, so we handle it manually via onKeyDown.
onKeyDown={!shouldPreventEnterKeySubmit ? handleKeyDown : undefined}
wrapperStyle={pressableWrapperStyle}
testID={`${CONST.BASE_LIST_ITEM_TEST_ID}${item.keyForList}`}
>
Expand Down
5 changes: 3 additions & 2 deletions src/components/SelectionList/ListItem/ListItemRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ListItemRendererProps<TItem extends ListItem> = Omit<BaseListItemProps<TIte
titleStyles?: StyleProp<TextStyle>;
titleContainerStyles?: StyleProp<ViewStyle>;
shouldHighlightSelectedItem: boolean;
shouldPreventEnterKeySubmit?: boolean;
};

function ListItemRenderer<TItem extends ListItem>({
Expand Down Expand Up @@ -53,6 +54,7 @@ function ListItemRenderer<TItem extends ListItem>({
shouldDisableHoverStyle,
shouldShowRightCaret,
errorRowStyles,
shouldPreventEnterKeySubmit = true,
}: ListItemRendererProps<TItem>) {
const handleOnCheckboxPress = () => {
if (isTransactionGroupListItemType(item)) {
Expand Down Expand Up @@ -81,8 +83,7 @@ function ListItemRenderer<TItem extends ListItem>({
onCheckboxPress={handleOnCheckboxPress()}
onDismissError={() => onDismissError?.(item)}
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
// We're already handling the Enter key press in the useKeyboardShortcut hook, so we don't want the list item to submit the form
shouldPreventEnterKeySubmit
shouldPreventEnterKeySubmit={shouldPreventEnterKeySubmit}
rightHandSideComponent={rightHandSideComponent}
keyForList={item.keyForList}
shouldUseDefaultRightHandSideComponent={shouldUseDefaultRightHandSideComponent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function BaseSelectionListWithSections<TItem extends ListItem>({

const selectFocusedItem = () => {
const focusedItem = getFocusedItem();
if (!focusedItem) {
if (!focusedItem || focusedItem.isInteractive === false) {
return;
}
selectRow(focusedItem);
Expand Down Expand Up @@ -363,6 +363,7 @@ function BaseSelectionListWithSections<TItem extends ListItem>({
titleNumberOfLines={titleNumberOfLines}
shouldUseDefaultRightHandSideComponent={shouldUseDefaultRightHandSideComponent}
shouldDisableHoverStyle={shouldDisableHoverStyle}
shouldPreventEnterKeySubmit={!disableKeyboardShortcuts}
/>
);
}
Expand Down
Loading