Skip to content

Commit

Permalink
fix(tag): pass all props to not html tags
Browse files Browse the repository at this point in the history
  • Loading branch information
zouxuoz committed Aug 24, 2018
1 parent 3b3cc4b commit 34725e5
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/common/Tag/Tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,35 @@ const COLLECTED_PROPS = [
'rows',
'src',
'style',
'tagName',
'to',
'type',
'value',
];

const HTML_TAGS = [
'div',
'span',
'button',
'a',
'p',
'input',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'label',
'nav',
'img',
];

const collectProps = (props) => pickBy(props, (value, name) => COLLECTED_PROPS.indexOf(name) !== -1 || /^data-/.test(name));

function Tag({ tagName, ...props }: TagProps) {
const TagComponent = tagName;
const collectedProps = collectProps(props);

const collectedProps = HTML_TAGS.indexOf(tagName) === -1 ? props : collectProps(props);

return <TagComponent { ...collectedProps } ref={ props.insideRef } />;
}
Expand Down

0 comments on commit 34725e5

Please sign in to comment.