Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ChoiceList] Add JSX support to the title prop #2355

Merged
merged 1 commit into from
Nov 1, 2019
Merged
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
2 changes: 2 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Enhancements

- Updated the type of the `title` prop in `ChoiceList` from `string` to `ReactNode` ([#2355](https://github.com/Shopify/polaris-react/pull/2355))

### Bug fixes

### Documentation
Expand Down
2 changes: 1 addition & 1 deletion src/components/ChoiceList/ChoiceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type Choice = ChoiceDescriptor;

export interface ChoiceListProps {
/** Label for list of choices */
title: string;
title: React.ReactNode;
/** Collection of choices */
choices: Choice[];
/** Collection of selected choices */
Expand Down
18 changes: 18 additions & 0 deletions src/components/ChoiceList/tests/ChoiceList.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import {ReactWrapper} from 'enzyme';
import {mountWithApp} from 'test-utilities';
import {mountWithAppProvider} from 'test-utilities/legacy';
import {RadioButton, Checkbox, InlineError, errorTextID} from 'components';
import {ChoiceList, ChoiceDescriptor} from '../ChoiceList';
Expand Down Expand Up @@ -29,6 +30,23 @@ describe('<ChoiceList />', () => {
);
expect(element.find('legend').text()).toBe('My title');
});

it('renders a legend containing JSX for the fieldset', () => {
const TitleComponent = () => (
<React.Fragment>
JSX <b>title</b>
</React.Fragment>
);

const element = mountWithApp(
<ChoiceList
title={<TitleComponent />}
selected={[]}
choices={choices}
/>,
);
expect(element.find('legend')).toContainReactComponent(TitleComponent);
});
});

describe('choices', () => {
Expand Down