Skip to content
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

[CP Staging] fix: disable double press event handler #40642

Merged
merged 4 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
1 change: 1 addition & 0 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ function BaseSelectionList<TItem extends ListItem>(
onCheckboxPress={onCheckboxPress ? () => onCheckboxPress?.(item) : undefined}
onDismissError={() => onDismissError?.(item)}
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
shouldPreventEnterKeySubmit
mountiny marked this conversation as resolved.
Show resolved Hide resolved
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
3 changes: 3 additions & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ type ListItemProps<TItem extends ListItem> = CommonListItemProps<TItem> & {
/** Whether the default focus should be prevented on row selection */
shouldPreventDefaultFocusOnSelectRow?: boolean;

shouldPreventEnterKeySubmit?: boolean;
allroundexperts marked this conversation as resolved.
Show resolved Hide resolved

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

Expand All @@ -150,6 +152,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
Loading