Skip to content

Commit

Permalink
fix: custom Button styles nested in Card.Actions (#3651)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak authored Feb 6, 2023
1 parent e4c2e9d commit a3eb45c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
17 changes: 17 additions & 0 deletions example/src/Examples/CardExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ const CardExample = () => {
</TextComponent>
</Card.Content>
</Card>
<Card style={styles.card} mode={selectedMode}>
<Card.Cover
source={require('../../assets/images/restaurant-1.jpg')}
/>
<Card.Title title="Custom Button styles" />
<Card.Actions>
<Button style={styles.button} onPress={() => {}}>
Share
</Button>
<Button style={styles.button} onPress={() => {}}>
Explore
</Button>
</Card.Actions>
</Card>
<Card style={styles.card} mode={selectedMode}>
<Card.Cover
source={require('../../assets/images/strawberries.jpg')}
Expand Down Expand Up @@ -201,6 +215,9 @@ const styles = StyleSheet.create({
paddingVertical: 12,
paddingHorizontal: 8,
},
button: {
borderRadius: 12,
},
});

export default CardExample;
2 changes: 1 addition & 1 deletion src/components/Card/CardActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const CardActions = (props: Props) => {
mode:
child.props.mode ||
(isV3 && (i === 0 ? 'outlined' : 'contained')),
style: isV3 && styles.button,
style: [isV3 && styles.button, child.props.style],
})
: child;
})}
Expand Down
20 changes: 20 additions & 0 deletions src/components/__tests__/Card/Card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ describe('CardActions', () => {
'contained'
);
});

it('renders button with custom styles', () => {
const { getByTestId } = render(
<Card>
<Card.Actions>
<Button
testID="card-actions-button"
mode="contained"
style={styles.customBorderRadius}
>
Agree
</Button>
</Card.Actions>
</Card>
);

expect(getByTestId('card-actions-button')).toHaveStyle({
borderRadius: 32,
});
});
});

describe('getCardColors - background color', () => {
Expand Down

0 comments on commit a3eb45c

Please sign in to comment.