Skip to content

Commit

Permalink
feat(Disclosure): allow use React.Node as summary (#1233)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raubzeug authored Dec 27, 2023
1 parent 13b921e commit 3180060
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/Disclosure/Disclosure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface DisclosureProps extends QAProps {
/** Control position */
arrowPosition?: DisclosureArrowPosition;
/** Content summary */
summary?: string;
summary?: React.ReactNode;
/** Class name */
className?: string;
/** Content */
Expand Down
2 changes: 1 addition & 1 deletion src/components/Disclosure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Disclosure component that shows and hides enclosed content.
| defaultExpanded | `Boolean` | | `false` | Default opening state |
| expanded | `Boolean` | | | Controlled opening state |
| arrowPosition | `left` `right` | | `left` | Control position |
| summary | `String` | | | Content summary |
| summary | `React.ReactNode` | | | Content summary |
| keepMounted | `Boolean` | | `true` | Keep content in DOM |
| onUpdate | `(expanded: boolean) => void` | | | Callback fired when the expand/collapse state is changed |
| children | `React.ReactNode` | | | Content |
Expand Down
2 changes: 2 additions & 0 deletions src/components/Disclosure/__stories__/Disclosure.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {Meta, StoryFn} from '@storybook/react';

import {Button} from '../../Button';
import {Icon} from '../../Icon';
import {Label} from '../../Label';
import type {DisclosureProps} from '../index';
import {Disclosure} from '../index';

Expand Down Expand Up @@ -76,6 +77,7 @@ const CustomTemplate: StoryFn<DisclosureProps> = (args) => {
{(props) => <Button {...props}>Without content</Button>}
</Disclosure.Summary>
</Disclosure>
<Disclosure {...args} summary={<Label>Default node summary</Label>} />
</div>
);
};
Expand Down
16 changes: 15 additions & 1 deletion src/components/Disclosure/__tests__/Disclosure .test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe.only('Disclosure', () => {
expect(disclosure).not.toBeDisabled();
});

test('show given summary', () => {
test('show given string summary', () => {
const content = 'Some content';

render(<Disclosure summary={content} />);
Expand All @@ -48,6 +48,20 @@ describe.only('Disclosure', () => {
expect(text).toBeVisible();
});

test('show given node summary', () => {
const className = 'content';
const content = (
<div data-qa={qaId} className={className}>
Some content
</div>
);

render(<Disclosure summary={content} />);
const component = screen.getByTestId(qaId);

expect(component).toHaveClass(className);
});

test('add className', () => {
const className = 'my-class';

Expand Down

0 comments on commit 3180060

Please sign in to comment.