Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
[Card] Add overflowX and overflowY properties
  • Loading branch information
tadjik1 committed Jul 30, 2025
commit b709f2081a1c1e9e8712bdb3bc99818e6b602b6e
5 changes: 5 additions & 0 deletions .changeset/sharp-queens-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': minor
---

Add `overflowX` and `overflowY` properties to the `Card`
15 changes: 13 additions & 2 deletions polaris-react/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React from 'react';

import {useBreakpoints} from '../../utilities/breakpoints';
import type {ResponsiveProp} from '../../utilities/css';
import type {BoxProps} from '../Box';
import {Box} from '../Box';
import {ShadowBevel} from '../ShadowBevel';
import {WithinContentContext} from '../../utilities/within-content-context';
Expand All @@ -31,13 +32,23 @@ export interface CardProps {
* @default 'sm'
*/
roundedAbove?: BreakpointsAlias;
/** Clip or scroll horizontal overflow of children content
* @default 'clip'
*/
overflowX?: BoxProps['overflowX'];
/** Clip or scroll vertical overflow of children content
* @default 'clip'
*/
overflowY?: BoxProps['overflowY'];
}

export const Card = ({
children,
background = 'bg-surface',
padding = {xs: '400'},
roundedAbove = 'sm',
overflowX = 'clip',
overflowY = 'clip',
}: CardProps) => {
const breakpoints = useBreakpoints();
const defaultBorderRadius: BorderRadiusAliasOrScale = '300';
Expand All @@ -53,8 +64,8 @@ export const Card = ({
<Box
background={background}
padding={padding}
overflowX="clip"
overflowY="clip"
overflowX={overflowX}
overflowY={overflowY}
minHeight="100%"
>
{children}
Expand Down
23 changes: 23 additions & 0 deletions polaris-react/src/components/Card/tests/Card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {setMediaWidth} from 'tests/utilities/breakpoints';
import {WithinContentContext} from '../../../utilities/within-content-context';
import {Card} from '..';
import {ShadowBevel} from '../../ShadowBevel';
import {Box} from '../../Box';

const heading = <p>Online store dashboard</p>;
const subheading = <p>View a summary of your online store performance</p>;
Expand Down Expand Up @@ -55,4 +56,26 @@ describe('Card', () => {
borderRadius: '300',
});
});

it('uses default overflow values if none provided', () => {
const card = mountWithApp(<Card>{heading}</Card>);
expect(card).toContainReactComponent(Box, {
overflowX: 'clip',
overflowY: 'clip',
});
});

it('forwards overflowX and overflowY props to Box', () => {
const card = mountWithApp(
<Card overflowX="hidden" overflowY="clip">
{heading}
{subheading}
</Card>,
);

expect(card).toContainReactComponent(Box, {
overflowX: 'hidden',
overflowY: 'clip',
});
});
});