diff --git a/src/components/html-message.js b/src/components/html-message.js index 4cfdfcbb82..68093e8249 100644 --- a/src/components/html-message.js +++ b/src/components/html-message.js @@ -23,7 +23,11 @@ export default class FormattedHTMLMessage extends Component { static propTypes = { ...messageDescriptorPropTypes, values: PropTypes.object, - tagName: PropTypes.string, + tagName: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.func, + PropTypes.shape({render: PropTypes.func.isRequired}), + ]), children: PropTypes.func, }; diff --git a/src/components/message.js b/src/components/message.js index ff9c100e82..e73a9997f6 100644 --- a/src/components/message.js +++ b/src/components/message.js @@ -40,7 +40,11 @@ export default class FormattedMessage extends Component { static propTypes = { ...messageDescriptorPropTypes, values: PropTypes.object, - tagName: PropTypes.oneOfType([PropTypes.string, PropTypes.element]), + tagName: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.func, + PropTypes.shape({render: PropTypes.func.isRequired}), + ]), children: PropTypes.func, }; diff --git a/test/unit/components/html-message.js b/test/unit/components/html-message.js index 739d8ef9a1..fb80a719cb 100644 --- a/test/unit/components/html-message.js +++ b/test/unit/components/html-message.js @@ -190,6 +190,26 @@ describe('', () => { ); }); + it('accepts a react component as `tagName` prop', () => { + const {intl} = intlProvider.getChildContext(); + const descriptor = { + id: 'hello', + defaultMessage: 'Hello, World!', + }; + + const H1 = (children) =>

{children}

+ const el = ; + + renderer.render(el, {intl}); + expect(renderer.getRenderOutput()).toEqualJSX( +

+ ); + }); + it('supports function-as-child pattern', () => { const {intl} = intlProvider.getChildContext(); const descriptor = { diff --git a/test/unit/components/message.js b/test/unit/components/message.js index 4373d72711..8ac000cda1 100644 --- a/test/unit/components/message.js +++ b/test/unit/components/message.js @@ -205,7 +205,7 @@ describe('', () => { ); }); - it('accepts an react element as `tagName` prop', () => { + it('accepts a react component as `tagName` prop', () => { const {intl} = intlProvider.getChildContext(); const descriptor = { id: 'hello',