Skip to content

Commit 894ef55

Browse files
committed
Updated FormattedMessage. Allow tagName to be a React component or a html tag (string) and added tagProps props. This is used to add props for the given tagName React component.
1 parent 1380e71 commit 894ef55

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/components/message.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export default class FormattedMessage extends Component {
4646
defaultMessage,
4747
values,
4848
tagName,
49-
children,
49+
tagProps,
50+
children
5051
} = this.props;
5152

5253
// Creates a token with a random UID that should not be guessable or
@@ -95,7 +96,7 @@ export default class FormattedMessage extends Component {
9596
return children(...nodes);
9697
}
9798

98-
return createElement(tagName, null, ...nodes);
99+
return createElement(tagName, tagProps, ...nodes);
99100
}
100101
}
101102

@@ -108,11 +109,16 @@ FormattedMessage.contextTypes = {
108109
FormattedMessage.propTypes = {
109110
...messageDescriptorPropTypes,
110111
values : PropTypes.object,
111-
tagName : PropTypes.string,
112+
tagName: PropTypes.oneOfType([
113+
PropTypes.string,
114+
PropTypes.func
115+
]),
116+
tagProps: PropTypes.object,
112117
children: PropTypes.func,
113118
};
114119

115120
FormattedMessage.defaultProps = {
116121
values : {},
117122
tagName: 'span',
123+
tagProps: null
118124
};

0 commit comments

Comments
 (0)