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

fix: Split - Enter and CMD+Enter open user profile instead of splitting expense. #46278

Merged
merged 5 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 17 additions & 3 deletions src/components/ButtonWithDropdownMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import Button from '@components/Button';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import PopoverMenu from '@components/PopoverMenu';
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import mergeRefs from '@libs/mergeRefs';
import CONST from '@src/CONST';
import type {AnchorPosition} from '@src/styles';
import type {ButtonWithDropdownMenuProps} from './types';
Expand All @@ -33,6 +35,7 @@ function ButtonWithDropdownMenu<IValueType>({
onOptionSelected,
enterKeyEventListenerPriority = 0,
wrapperStyle,
useKeyboardShortcuts = false,
}: ButtonWithDropdownMenuProps<IValueType>) {
const theme = useTheme();
const styles = useThemeStyles();
Expand Down Expand Up @@ -65,16 +68,27 @@ function ButtonWithDropdownMenu<IValueType>({
});
}
}, [windowWidth, windowHeight, isMenuVisible, anchorAlignment.vertical]);

useKeyboardShortcut(
CONST.KEYBOARD_SHORTCUTS.CTRL_ENTER,
(e) => {
onPress(e, selectedItem.value);
},
{
captureOnInputs: true,
shouldBubble: false,
isActive: useKeyboardShortcuts,
},
);

return (
<View style={wrapperStyle}>
{shouldAlwaysShowDropdownMenu || options.length > 1 ? (
<View style={[styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter, style]}>
<Button
success={success}
pressOnEnter={pressOnEnter}
ref={(ref) => {
caretButton.current = ref;
}}
ref={mergeRefs(caretButton, buttonRef)}
onPress={(event) => (!isSplitButton ? setIsMenuVisible(!isMenuVisible) : onPress(event, selectedItem.value))}
text={customText ?? selectedItem.text}
isDisabled={isDisabled || !!selectedItem.disabled}
Expand Down
3 changes: 3 additions & 0 deletions src/components/ButtonWithDropdownMenu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ type ButtonWithDropdownMenuProps<TValueType> = {

/** Whether the button should use split style or not */
isSplitButton?: boolean;

/** Whether to use keyboard shortcuts for confirmation or not */
useKeyboardShortcuts?: boolean;
};

export type {
Expand Down
3 changes: 3 additions & 0 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ function MoneyRequestConfirmationList({
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
enterKeyEventListenerPriority={1}
useKeyboardShortcuts
/>
) : (
<ButtonWithDropdownMenu
Expand All @@ -804,6 +805,7 @@ function MoneyRequestConfirmationList({
options={splitOrRequestOptions}
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.LARGE}
enterKeyEventListenerPriority={1}
useKeyboardShortcuts
/>
);

Expand Down Expand Up @@ -899,6 +901,7 @@ function MoneyRequestConfirmationList({
listFooterContent={listFooterContent}
containerStyle={[styles.flexBasisAuto]}
removeClippedSubviews={false}
disableKeyboardShortcuts
/>
</MouseProvider>
);
Expand Down
5 changes: 5 additions & 0 deletions src/components/SettlementButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ type SettlementButtonProps = SettlementButtonOnyxProps & {

/** Callback to open confirmation modal if any of the transactions is on HOLD */
confirmApproval?: () => void;

/** Whether to use keyboard shortcuts for confirmation or not */
useKeyboardShortcuts?: boolean;
};

function SettlementButton({
Expand Down Expand Up @@ -140,6 +143,7 @@ function SettlementButton({
enterKeyEventListenerPriority = 0,
confirmApproval,
policy,
useKeyboardShortcuts = false,
}: SettlementButtonProps) {
const {translate} = useLocalize();
const {isOffline} = useNetwork();
Expand Down Expand Up @@ -288,6 +292,7 @@ function SettlementButton({
buttonSize={buttonSize}
anchorAlignment={paymentMethodDropdownAnchorAlignment}
enterKeyEventListenerPriority={enterKeyEventListenerPriority}
useKeyboardShortcuts={useKeyboardShortcuts}
/>
)}
</KYCWall>
Expand Down
Loading