Skip to content

Commit

Permalink
Merge pull request #43794 from Krishna2323/krishna2323/issue/41848
Browse files Browse the repository at this point in the history
fix: Web - Split - Enter and CMD+Enter open user profile instead of splitting expense.
  • Loading branch information
mountiny authored Jul 19, 2024
2 parents 65b4b84 + a56bc41 commit 331309f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
26 changes: 23 additions & 3 deletions src/components/ButtonWithDropdownMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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';
Expand Down Expand Up @@ -33,6 +34,7 @@ function ButtonWithDropdownMenu<IValueType>({
onOptionSelected,
enterKeyEventListenerPriority = 0,
wrapperStyle,
useKeyboardShortcuts = false,
}: ButtonWithDropdownMenuProps<IValueType>) {
const theme = useTheme();
const styles = useThemeStyles();
Expand Down Expand Up @@ -65,16 +67,34 @@ 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,
},
);

useEffect(() => {
if (!!caretButton.current || !buttonRef?.current || !(shouldAlwaysShowDropdownMenu || options.length > 1)) {
return;
}
caretButton.current = buttonRef.current;
}, [buttonRef, options.length, shouldAlwaysShowDropdownMenu]);

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={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 @@ -778,6 +778,7 @@ function MoneyRequestConfirmationList({
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
enterKeyEventListenerPriority={1}
useKeyboardShortcuts
/>
) : (
<ButtonWithDropdownMenu
Expand All @@ -789,6 +790,7 @@ function MoneyRequestConfirmationList({
options={splitOrRequestOptions}
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.LARGE}
enterKeyEventListenerPriority={1}
useKeyboardShortcuts
/>
);

Expand Down Expand Up @@ -883,6 +885,7 @@ function MoneyRequestConfirmationList({
footerContent={footerContent}
listFooterContent={listFooterContent}
containerStyle={[styles.flexBasisAuto]}
disableKeyboardShortcuts
removeClippedSubviews={false}
/>
</MouseProvider>
Expand Down
9 changes: 8 additions & 1 deletion 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 @@ -283,11 +287,14 @@ function SettlementButton({
onPress={(event, iouPaymentType) => selectPaymentType(event, iouPaymentType, triggerKYCFlow)}
pressOnEnter={pressOnEnter}
options={paymentButtonOptions}
onOptionSelected={(option) => savePreferredPaymentMethod(policyID, option.value)}
onOptionSelected={(option) => {
savePreferredPaymentMethod(policyID, option.value);
}}
style={style}
buttonSize={buttonSize}
anchorAlignment={paymentMethodDropdownAnchorAlignment}
enterKeyEventListenerPriority={enterKeyEventListenerPriority}
useKeyboardShortcuts={useKeyboardShortcuts}
/>
)}
</KYCWall>
Expand Down

0 comments on commit 331309f

Please sign in to comment.