Skip to content

Commit

Permalink
Merge pull request #2355 from Shopify/jt/choicelist-update-title-prop…
Browse files Browse the repository at this point in the history
…-type

[ChoiceList] Add JSX support to the title prop
  • Loading branch information
jtrollia authored Nov 1, 2019
2 parents c7e8250 + de64cd1 commit abf386f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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

0 comments on commit abf386f

Please sign in to comment.