Skip to content

Commit

Permalink
[EuiCard] Allow selectable with layout="horizontal" (#4692)
Browse files Browse the repository at this point in the history
* allow selectable with layout=horizontal

* test

* CL
  • Loading branch information
thompsongl authored Apr 7, 2021
1 parent 35305cb commit f62d379
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `32.0.3`.
**Bug fixes**

- Removed the restriction on `selectable` `EuiCard` with `layout="horizontal"` ([#4692](https://github.com/elastic/eui/pull/4692))

## [`32.0.3`](https://github.com/elastic/eui/tree/v32.0.3)

Expand Down
42 changes: 42 additions & 0 deletions src/components/card/__snapshots__/card.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiCard horizontal selectable 1`] = `
<div
class="euiPanel euiPanel--paddingMedium euiPanel--borderRadiusMedium euiPanel--plain euiPanel--hasShadow euiPanel--isClickable euiCard euiCard--centerAligned euiCard--horizontal euiCard--isClickable euiCard--isSelectable euiCard--isSelectable--text"
>
<div
class="euiCard__content"
>
<span
class="euiTitle euiTitle--small euiCard__title"
id="generated-idTitle"
>
Card title
</span>
<div
class="euiText euiText--small euiCard__description"
id="generated-idDescription"
>
<p>
Card description
</p>
</div>
</div>
<button
aria-checked="false"
aria-describedby="generated-idTitle generated-idDescription"
class="euiButtonEmpty euiButtonEmpty--text euiButtonEmpty--xSmall euiCardSelect euiCardSelect--text"
role="switch"
type="button"
>
<span
class="euiButtonContent euiButtonEmpty__content"
>
<span
class="euiButtonEmpty__text"
>
Select
</span>
</span>
</button>
</div>
`;

exports[`EuiCard is rendered 1`] = `
<div
aria-label="aria-label"
Expand Down
15 changes: 15 additions & 0 deletions src/components/card/card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,19 @@ describe('EuiCard', () => {
expect(component).toMatchSnapshot();
});
});

test('horizontal selectable', () => {
const component = render(
<EuiCard
title="Card title"
description="Card description"
layout="horizontal"
selectable={{
onClick: () => {},
}}
/>
);

expect(component).toMatchSnapshot();
});
});
14 changes: 7 additions & 7 deletions src/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,11 @@ type EuiCardPropsLayout = ExclusiveUnion<
* Accepts a url in string form or ReactElement for a custom image component
*/
image?: string | ReactElement;
/**
* Adds a button to the bottom of the card to allow for in-place selection
*/
selectable?: EuiCardSelectProps;
},
{
/**
* Change to "horizontal" if you need the icon to be left of the content.
* Horizontal layouts cannot be used in conjunction with `image`, `footer`, `textAlign`, or `selectable`.
* Horizontal layouts cannot be used in conjunction with `image`, `footer`, or `textAlign`.
*/
layout: 'horizontal';
}
Expand Down Expand Up @@ -161,6 +157,10 @@ export type EuiCardProps = Omit<CommonProps, 'aria-label'> &
* Padding applied around the content of the card
*/
paddingSize?: EuiPanelProps['paddingSize'];
/**
* Adds a button to the bottom of the card to allow for in-place selection
*/
selectable?: EuiCardSelectProps;
} & (
| {
// description becomes optional when children is present
Expand Down Expand Up @@ -216,9 +216,9 @@ export const EuiCard: FunctionComponent<EuiCardProps> = ({
};

if (layout === 'horizontal') {
if (image || footer || textAlign !== 'center' || selectable) {
if (image || footer || textAlign !== 'center') {
throw new Error(
"EuiCard: layout = horizontal' cannot be used in conjunction with 'image', 'footer', 'textAlign', or 'selectable'."
'EuiCard: `layout="horizontal"` cannot be used in conjunction with `image`, `footer`, or `textAlign`.'
);
}
}
Expand Down

0 comments on commit f62d379

Please sign in to comment.