Skip to content

Commit

Permalink
[ChoiceList] add JSX suppor to the title prop
Browse files Browse the repository at this point in the history
  • Loading branch information
jtrollia committed Oct 31, 2019
1 parent 47d0240 commit 71d7158
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 @@ -10,6 +10,8 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

### 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

- Fixed an accessibility issue with `TextField` `multiline` where `aria-multiline` would be set to an invalid type `number` ([#2351](https://github.com/Shopify/polaris-react/pull/2351))
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 71d7158

Please sign in to comment.