Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Template): add props for the tagName #2757

Merged
merged 1 commit into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/Template.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class PureTemplate extends Component {
}

render() {
const RootTagName = this.props.rootTagName;
const useCustomCompileOptions = this.props.useCustomCompileOptions[
this.props.templateKey
];
Expand Down Expand Up @@ -42,7 +43,7 @@ export class PureTemplate extends Component {
}

return (
<div
<RootTagName
{...this.props.rootProps}
dangerouslySetInnerHTML={{ __html: content }}
/>
Expand All @@ -53,6 +54,7 @@ export class PureTemplate extends Component {
PureTemplate.propTypes = {
data: PropTypes.object,
rootProps: PropTypes.object,
rootTagName: PropTypes.string,
templateKey: PropTypes.string,
templates: PropTypes.objectOf(
PropTypes.oneOfType([PropTypes.string, PropTypes.func])
Expand Down Expand Up @@ -81,6 +83,7 @@ PureTemplate.propTypes = {

PureTemplate.defaultProps = {
data: {},
rootTagName: 'div',
useCustomCompileOptions: {},
templates: {},
templatesConfig: {},
Expand Down
9 changes: 9 additions & 0 deletions src/components/__tests__/Template-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ describe('Template', () => {
expect(tree).toMatchSnapshot();
});

it('can configure custom rootTagName', () => {
const props = getProps({ rootTagName: 'span' });
const tree = renderer.create(<PureTemplate {...props} />).toJSON();

expect(tree).toMatchSnapshot();
});

it('forward rootProps to the first node', () => {
function fn() {}

Expand Down Expand Up @@ -207,8 +214,10 @@ describe('Template', () => {
useCustomCompileOptions = {},
templatesConfig = { helper: {}, compileOptions: {} },
transformData = null,
...props
}) {
return {
...props,
templates,
data,
templateKey,
Expand Down
10 changes: 10 additions & 0 deletions src/components/__tests__/__snapshots__/Template-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ exports[`Template can configure compilation options 1`] = `
/>
`;

exports[`Template can configure custom rootTagName 1`] = `
<span
dangerouslySetInnerHTML={
Object {
"__html": "",
}
}
/>
`;

exports[`Template forward rootProps to the first node 1`] = `
<div
className="hey"
Expand Down