From 3495dce0e31f56debd7f15d1f9278f55f21a7cae Mon Sep 17 00:00:00 2001 From: zouxuoz Date: Fri, 20 Jul 2018 12:10:26 +0300 Subject: [PATCH] fix(tag): fix ability to pass data attributes to the tags --- src/common/Tag/Tag.js | 6 ++++-- src/common/Tag/__tests__/Tag-test.js | 6 ++++++ src/common/Tag/__tests__/__snapshots__/Tag-test.js.snap | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/common/Tag/Tag.js b/src/common/Tag/Tag.js index 638370d8..ef860477 100644 --- a/src/common/Tag/Tag.js +++ b/src/common/Tag/Tag.js @@ -1,5 +1,5 @@ import React from 'react'; -import pick from 'lodash/pick'; +import pickBy from 'lodash/pickBy'; type TagProps = {| activeClassName?: string, @@ -66,9 +66,11 @@ const COLLECTED_PROPS = [ 'value', ]; +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 = pick(props, COLLECTED_PROPS); + const collectedProps = collectProps(props); return ; } diff --git a/src/common/Tag/__tests__/Tag-test.js b/src/common/Tag/__tests__/Tag-test.js index 23909904..4fd0692c 100644 --- a/src/common/Tag/__tests__/Tag-test.js +++ b/src/common/Tag/__tests__/Tag-test.js @@ -7,3 +7,9 @@ it('As developer, I can use tag for collect common props.', () => { expect(tree.toJSON()).toMatchSnapshot(); }); + +it('As developer, I can pass data attributes to the tag.', () => { + const tree = renderer.create(); + + expect(tree.toJSON()).toMatchSnapshot(); +}); diff --git a/src/common/Tag/__tests__/__snapshots__/Tag-test.js.snap b/src/common/Tag/__tests__/__snapshots__/Tag-test.js.snap index 40a73284..89cd9234 100644 --- a/src/common/Tag/__tests__/__snapshots__/Tag-test.js.snap +++ b/src/common/Tag/__tests__/__snapshots__/Tag-test.js.snap @@ -1,5 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`As developer, I can pass data attributes to the tag. 1`] = ` +
+`; + exports[`As developer, I can use tag for collect common props. 1`] = `