Skip to content

Commit

Permalink
Merge pull request #40642 from allroundexperts/EMBUS-40551
Browse files Browse the repository at this point in the history
[CP Staging] fix: disable double press event handler
  • Loading branch information
mountiny authored Apr 20, 2024
2 parents c249ad4 + 77d5f82 commit 8616678
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/SelectionList/BaseListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function BaseListItem<TItem extends ListItem>({
containerStyle,
isDisabled = false,
shouldPreventDefaultFocusOnSelectRow = false,
shouldPreventEnterKeySubmit = false,
canSelectMultiple = false,
onSelectRow,
onDismissError = () => {},
Expand Down Expand Up @@ -65,7 +66,12 @@ function BaseListItem<TItem extends ListItem>({
// eslint-disable-next-line react/jsx-props-no-spreading
{...bind}
ref={pressableRef}
onPress={() => onSelectRow(item)}
onPress={(e) => {
if (shouldPreventEnterKeySubmit && e && 'key' in e && e.key === CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey) {
return;
}
onSelectRow(item);
}}
disabled={isDisabled}
accessibilityLabel={item.text ?? ''}
role={CONST.ROLE.BUTTON}
Expand Down
2 changes: 2 additions & 0 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ function BaseSelectionList<TItem extends ListItem>(
onCheckboxPress={onCheckboxPress ? () => onCheckboxPress?.(item) : undefined}
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
rightHandSideComponent={rightHandSideComponent}
keyForList={item.keyForList ?? ''}
isMultilineSupported={isRowMultilineSupported}
Expand Down
2 changes: 2 additions & 0 deletions src/components/SelectionList/RadioListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function RadioListItem<TItem extends ListItem>({
onSelectRow,
onDismissError,
shouldPreventDefaultFocusOnSelectRow,
shouldPreventEnterKeySubmit,
rightHandSideComponent,
isMultilineSupported = false,
onFocus,
Expand All @@ -34,6 +35,7 @@ function RadioListItem<TItem extends ListItem>({
onSelectRow={onSelectRow}
onDismissError={onDismissError}
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
shouldPreventEnterKeySubmit={shouldPreventEnterKeySubmit}
rightHandSideComponent={rightHandSideComponent}
keyForList={item.keyForList}
onFocus={onFocus}
Expand Down
4 changes: 4 additions & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ type ListItemProps<TItem extends ListItem> = CommonListItemProps<TItem> & {
/** Whether the default focus should be prevented on row selection */
shouldPreventDefaultFocusOnSelectRow?: boolean;

/** Prevent the submission of the list item when enter key is pressed */
shouldPreventEnterKeySubmit?: boolean;

/** Key used internally by React */
keyForList?: string;

Expand All @@ -150,6 +153,7 @@ type ListItemProps<TItem extends ListItem> = CommonListItemProps<TItem> & {
type BaseListItemProps<TItem extends ListItem> = CommonListItemProps<TItem> & {
item: TItem;
shouldPreventDefaultFocusOnSelectRow?: boolean;
shouldPreventEnterKeySubmit?: boolean;
keyForList?: string | null;
errors?: Errors | ReceiptErrors | null;
pendingAction?: PendingAction | null;
Expand Down

0 comments on commit 8616678

Please sign in to comment.