Skip to content

Commit

Permalink
fix: add default tagName to HTML message (#1361)
Browse files Browse the repository at this point in the history
fix: add default tagName to HTML message
fix: add revert back to createElement for message
fix: make textComponent optional
  • Loading branch information
longlho authored Jul 10, 2019
1 parent 3b9627e commit e86befe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/components/html-message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import withIntl from './injectIntl';
import {BaseFormattedMessage} from './message';

class FormattedHTMLMessage extends BaseFormattedMessage {
static defaultProps = {
...BaseFormattedMessage.defaultProps,
tagName: 'span' as 'span',
};
render() {
const {formatHTMLMessage, textComponent: Text} = this.props.intl;

Expand All @@ -17,7 +21,8 @@ class FormattedHTMLMessage extends BaseFormattedMessage {
description,
defaultMessage,
values: rawValues,
tagName: Component = Text,
// This is bc of TS3.3 doesn't recognize `defaultProps`
tagName: Component = Text || 'span',
children,
} = this.props;

Expand Down
2 changes: 1 addition & 1 deletion src/components/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class BaseFormattedMessage extends React.Component<Props> {
if (Component) {
// Needs to use `createElement()` instead of JSX, otherwise React will
// warn about a missing `key` prop with rich-text message formatting.
return <Component>{nodes}</Component>;
return React.createElement(Component, null, ...nodes);
}
return nodes;
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface IntlConfig {
locale: string;
timeZone?: string;
formats: CustomFormats;
textComponent: React.ComponentType | keyof React.ReactHTML;
textComponent?: React.ComponentType | keyof React.ReactHTML;
messages: Record<string, string> | Record<string, MessageFormatElement[]>;
defaultLocale: string;
defaultFormats: CustomFormats;
Expand Down

0 comments on commit e86befe

Please sign in to comment.