Skip to content

Commit d9cad22

Browse files
author
Hossein Pousti
committed
fix: fixing an issue on the Button
1 parent bd03d1d commit d9cad22

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

example/src/ButtonExample/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ButtonExample: React.FC = () => {
3333
type="secondary"
3434
title="Pressable & Opacity Button"
3535
/>
36-
<Button size="xl" pressable color="gray-600">
36+
<Button pressable color="gray-600">
3737
<Gap space={10} behavior="style">
3838
<Text color="gray-100" size="lg">
3939
It's a title!

src/components/Button/index.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ const Button = React.forwardRef<any, Partial<PropsWithLayout<ButtonProps>>>(
4848
loadingProps,
4949
loadingColor,
5050
opacityConfig,
51-
radius = 'xs',
5251
mode = 'solid',
5352
dir: direction,
5453
pressableConfig,
5554
disabledTitleStyle,
5655
disabledTitleColor,
5756
disabledButtonColor,
57+
radius = typeof children === 'string' || !!title ? 'xs' : 0,
5858
size = typeof children === 'string' || !!title ? 'md' : undefined,
5959
type = typeof children === 'string' || !!title ? 'primary' : undefined,
6060
onPress,
@@ -77,6 +77,10 @@ const Button = React.forwardRef<any, Partial<PropsWithLayout<ButtonProps>>>(
7777
},
7878
});
7979

80+
const hasTitle = React.useMemo(() => {
81+
return typeof children === 'string' || !!title;
82+
}, [children, title]);
83+
8084
const textColor = React.useMemo(() => {
8185
const selectedColor = disabled
8286
? disabledTitleColor ?? colors?.secondText
@@ -134,26 +138,32 @@ const Button = React.forwardRef<any, Partial<PropsWithLayout<ButtonProps>>>(
134138
paddingHorizontal: rs(DefaultSizes[size]) * 1.2,
135139
};
136140
}
141+
if (hasTitle) {
142+
appliedStyles = {
143+
...appliedStyles,
144+
alignItems: 'center',
145+
};
146+
}
137147
return {
138148
...appliedStyles,
139149
overflow: 'hidden',
140-
alignItems: 'center',
141150
borderRadius: rs(
142151
typeof radius === 'number' ? radius : DefaultSizes[radius] / 2,
143152
),
144153
};
145154
}, [
146-
rs,
147-
size,
155+
disabled,
156+
disabledButtonColor,
157+
colors?.disabled,
158+
color,
148159
type,
149160
mode,
150-
color,
151-
radius,
152161
shadow,
153-
disabled,
162+
size,
163+
hasTitle,
164+
rs,
154165
borderColor,
155-
disabledButtonColor,
156-
colors?.disabled,
166+
radius,
157167
]);
158168

159169
const memorizedTitleStyle = useStyle<TextStyle>(() => {
@@ -268,7 +278,7 @@ const Button = React.forwardRef<any, Partial<PropsWithLayout<ButtonProps>>>(
268278
{...loadingProps}
269279
style={loadingLayoutStyle}
270280
/>
271-
) : typeof children === 'string' || !!title ? (
281+
) : hasTitle ? (
272282
<Text
273283
testID="FAST_BASE_BUTTON_TITLE"
274284
style={textLayoutStyle}

src/core/types/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,10 @@ export interface ButtonProps extends PressableProps {
388388
titleColor: AllColorsType;
389389

390390
titleProps: Omit<TextProps, 'style'>;
391-
391+
/**
392+
* if the children of the button are not a string or it doesn't have a title,
393+
* the default radius value will be zero.
394+
*/
392395
radius: SizeType | number;
393396
/**
394397
* only works on solid mode

0 commit comments

Comments
 (0)