Skip to content

Commit 25ff055

Browse files
feat: Add support to use different labels for tag and node (#412)
Co-authored-by: Bulletninja <luis.linuxero@gmail.com>
1 parent db0e59c commit 25ff055

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ Data for rendering the tree select items. The object requires the following stru
273273
actions, // optional: An array of extra action on the node (such as displaying an info icon or any custom icons/elements)
274274
dataset, // optional: Allows data-* attributes to be set on the node and tag elements
275275
isDefaultValue, // optional: Indicate if a node is a default value. When true, the dropdown will automatically select the node(s) when there is no other selected node. Can be used on more than one node.
276+
tagLabel, // optional: tag label in case you need it to differ from the checkbox label
276277
... // optional: Any extra properties that you'd like to receive during `onChange` event
277278
}
278279
```

__snapshots__/src/tags/index.test.js.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,35 @@ Generated by [AVA](https://ava.li).
9292
<Input />
9393
</li>
9494
</ul>
95+
96+
## should render the tagLabel instead of label when provided
97+
98+
> Snapshot 1
99+
100+
<ul
101+
className="tag-list"
102+
>
103+
<li
104+
className="tag-item"
105+
key="tag-item-i1"
106+
>
107+
<Tag
108+
id="i1"
109+
label="custom label"
110+
/>
111+
</li>
112+
<li
113+
className="tag-item"
114+
key="tag-item-i2"
115+
>
116+
<Tag
117+
id="i2"
118+
label="l2"
119+
/>
120+
</li>
121+
<li
122+
className="tag-item"
123+
>
124+
<Input />
125+
</li>
126+
</ul>
64 Bytes
Binary file not shown.

src/tags/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import './index.css'
77

88
const getTags = (tags = [], onDelete, readOnly, disabled, labelRemove) =>
99
tags.map(tag => {
10-
const { _id, label, tagClassName, dataset } = tag
10+
const { _id, label, tagClassName, dataset, tagLabel } = tag
1111
return (
1212
<li
1313
className={['tag-item', tagClassName].filter(Boolean).join(' ')}
1414
key={`tag-item-${_id}`}
1515
{...getDataset(dataset)}
1616
>
1717
<Tag
18-
label={label}
18+
label={tagLabel || label}
1919
id={_id}
2020
onDelete={onDelete}
2121
readOnly={readOnly}

src/tags/index.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,15 @@ test('should render data attributes', t => {
5757

5858
t.snapshot(wrapper)
5959
})
60+
61+
test('should render the tagLabel instead of label when provided', t => {
62+
const tags = [{ _id: 'i1', label: 'l1', tagLabel: 'custom label' }, { _id: 'i2', label: 'l2' }]
63+
const wrapper = toJson(
64+
shallow(
65+
<Tags tags={tags}>
66+
<Input />
67+
</Tags>
68+
)
69+
)
70+
t.snapshot(wrapper)
71+
})

0 commit comments

Comments
 (0)