-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
feature: add props isSplit to button with dropdown #40278
Changes from all commits
65e1251
98fef23
74ae64d
559d293
a9d6b4b
d80eeb7
0997b0a
7d9777f
b47c929
3fc5ecf
7ce8eed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import type {ButtonWithDropdownMenuProps} from './types'; | |
|
||
function ButtonWithDropdownMenu<IValueType>({ | ||
success = false, | ||
isSplitButton = true, | ||
isLoading = false, | ||
isDisabled = false, | ||
pressOnEnter = false, | ||
|
@@ -40,7 +41,7 @@ function ButtonWithDropdownMenu<IValueType>({ | |
const [isMenuVisible, setIsMenuVisible] = useState(false); | ||
const [popoverAnchorPosition, setPopoverAnchorPosition] = useState<AnchorPosition | null>(null); | ||
const {windowWidth, windowHeight} = useWindowDimensions(); | ||
const caretButton = useRef<View & HTMLDivElement>(null); | ||
const caretButton = useRef<View | HTMLDivElement | null>(null); | ||
const selectedItem = options[selectedItemIndex] || options[0]; | ||
const innerStyleDropButton = StyleUtils.getDropDownButtonHeight(buttonSize); | ||
const isButtonSizeLarge = buttonSize === CONST.DROPDOWN_BUTTON_SIZE.LARGE; | ||
|
@@ -64,51 +65,57 @@ function ButtonWithDropdownMenu<IValueType>({ | |
}); | ||
} | ||
}, [windowWidth, windowHeight, isMenuVisible, anchorAlignment.vertical]); | ||
|
||
return ( | ||
<View style={wrapperStyle}> | ||
{shouldAlwaysShowDropdownMenu || options.length > 1 ? ( | ||
<View style={[styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter, style]}> | ||
<Button | ||
success={success} | ||
pressOnEnter={pressOnEnter} | ||
ref={buttonRef} | ||
onPress={(event) => onPress(event, selectedItem.value)} | ||
ref={(ref) => { | ||
caretButton.current = ref; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR caused a bug - Tapping Pay button in an invoice crashes the app Fixed here - #44919 (comment) |
||
}} | ||
Comment on lines
+75
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This caused style regression |
||
onPress={(event) => (!isSplitButton ? setIsMenuVisible(!isMenuVisible) : onPress(event, selectedItem.value))} | ||
text={customText ?? selectedItem.text} | ||
isDisabled={isDisabled || !!selectedItem.disabled} | ||
isLoading={isLoading} | ||
shouldRemoveRightBorderRadius | ||
style={[styles.flex1, styles.pr0]} | ||
large={isButtonSizeLarge} | ||
medium={!isButtonSizeLarge} | ||
innerStyles={[innerStyleDropButton, customText !== undefined && styles.cursorDefault, customText !== undefined && styles.pointerEventsNone]} | ||
innerStyles={[innerStyleDropButton, !isSplitButton && styles.dropDownButtonCartIconView]} | ||
enterKeyEventListenerPriority={enterKeyEventListenerPriority} | ||
iconRight={Expensicons.DownArrow} | ||
shouldShowRightIcon={!isSplitButton} | ||
isSplitButton={isSplitButton} | ||
/> | ||
|
||
<Button | ||
ref={caretButton} | ||
success={success} | ||
isDisabled={isDisabled} | ||
style={[styles.pl0]} | ||
onPress={() => setIsMenuVisible(!isMenuVisible)} | ||
shouldRemoveLeftBorderRadius | ||
large={isButtonSizeLarge} | ||
medium={!isButtonSizeLarge} | ||
innerStyles={[styles.dropDownButtonCartIconContainerPadding, innerStyleDropButton]} | ||
enterKeyEventListenerPriority={enterKeyEventListenerPriority} | ||
> | ||
<View style={[styles.dropDownButtonCartIconView, innerStyleDropButton]}> | ||
<View style={[success ? styles.buttonSuccessDivider : styles.buttonDivider]} /> | ||
<View style={[isButtonSizeLarge ? styles.dropDownLargeButtonArrowContain : styles.dropDownMediumButtonArrowContain]}> | ||
<Icon | ||
medium={isButtonSizeLarge} | ||
small={!isButtonSizeLarge} | ||
src={Expensicons.DownArrow} | ||
fill={success ? theme.buttonSuccessText : theme.icon} | ||
/> | ||
{isSplitButton && ( | ||
<Button | ||
ref={caretButton} | ||
success={success} | ||
isDisabled={isDisabled} | ||
style={[styles.pl0]} | ||
onPress={() => setIsMenuVisible(!isMenuVisible)} | ||
shouldRemoveLeftBorderRadius | ||
large={isButtonSizeLarge} | ||
medium={!isButtonSizeLarge} | ||
innerStyles={[styles.dropDownButtonCartIconContainerPadding, innerStyleDropButton]} | ||
enterKeyEventListenerPriority={enterKeyEventListenerPriority} | ||
> | ||
<View style={[styles.dropDownButtonCartIconView, innerStyleDropButton]}> | ||
<View style={[success ? styles.buttonSuccessDivider : styles.buttonDivider]} /> | ||
<View style={[isButtonSizeLarge ? styles.dropDownLargeButtonArrowContain : styles.dropDownMediumButtonArrowContain]}> | ||
<Icon | ||
medium={isButtonSizeLarge} | ||
small={!isButtonSizeLarge} | ||
src={Expensicons.DownArrow} | ||
fill={success ? theme.buttonSuccessText : theme.icon} | ||
/> | ||
</View> | ||
</View> | ||
</View> | ||
</Button> | ||
</Button> | ||
)} | ||
</View> | ||
) : ( | ||
<Button | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was it set like that? is there any specific reason? Right now I need to add small icon handling and I'll adjust it in this way:
may it broke something?
@nkdengineer