Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Commit 11e407e

Browse files
authored
Merge pull request #30 from peterp/pp-rename-delete-tag-prop
Make `deleteTagOnPress` match the docs.
2 parents 5097df3 + 9f99796 commit 11e407e

File tree

3 files changed

+53
-18
lines changed

3 files changed

+53
-18
lines changed

Tags/__tests__/Tags_enzyme-tests.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,37 @@ import Tags from "../../";
77
enzyme.configure({ adapter: new Adapter() });
88

99
describe("Tags", () => {
10+
describe("tags", () => {
11+
it("removes a tag when you press them", () => {
12+
const wrapper = shallow(
13+
<Tags initialTags={["this", "is", "a", "test"]} />
14+
);
15+
16+
wrapper
17+
.find("Tag")
18+
.at(1)
19+
.simulate("press");
20+
21+
expect(wrapper.find("Tag").length).toEqual(3);
22+
});
23+
24+
it("doesn't remove tags when they're readonly", () => {
25+
const wrapper = shallow(
26+
<Tags
27+
deleteTagOnPress={false}
28+
initialTags={["this", "is", "a", "test"]}
29+
/>
30+
);
31+
32+
wrapper
33+
.find("Tag")
34+
.at(0)
35+
.simulate("press");
36+
37+
expect(wrapper.find("Tag").length).toEqual(4);
38+
});
39+
});
40+
1041
describe("TextInput", () => {
1142
describe("onChangeText", () => {
1243
it("should add a new tag when a space, or comma is detected", () => {

Tags/index.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Tags extends React.Component {
7272
style,
7373
tagContainerStyle,
7474
tagTextStyle,
75-
deleteOnTagPress,
75+
deleteTagOnPress,
7676
onTagPress,
7777
readonly,
7878
maxNumberOfTags,
@@ -88,7 +88,7 @@ class Tags extends React.Component {
8888
key={i}
8989
label={tag}
9090
onPress={e => {
91-
if (deleteOnTagPress) {
91+
if (deleteTagOnPress) {
9292
this.setState(
9393
{
9494
tags: [
@@ -112,19 +112,18 @@ class Tags extends React.Component {
112112
/>
113113
))}
114114

115-
{!readonly &&
116-
maxNumberOfTags > this.state.tags.length && (
117-
<View style={[styles.textInputContainer, inputContainerStyle]}>
118-
<TextInput
119-
{...textInputProps}
120-
value={this.state.text}
121-
style={[styles.textInput, inputStyle]}
122-
onChangeText={this.onChangeText}
123-
onSubmitEditing={this.onSubmitEditing}
124-
underlineColorAndroid="transparent"
125-
/>
126-
</View>
127-
)}
115+
{!readonly && maxNumberOfTags > this.state.tags.length && (
116+
<View style={[styles.textInputContainer, inputContainerStyle]}>
117+
<TextInput
118+
{...textInputProps}
119+
value={this.state.text}
120+
style={[styles.textInput, inputStyle]}
121+
onChangeText={this.onChangeText}
122+
onSubmitEditing={this.onSubmitEditing}
123+
underlineColorAndroid="transparent"
124+
/>
125+
</View>
126+
)}
128127
</View>
129128
);
130129
}
@@ -136,7 +135,7 @@ Tags.defaultProps = {
136135
createTagOnString: [",", " "],
137136
createTagOnReturn: false,
138137
readonly: false,
139-
deleteOnTagPress: true,
138+
deleteTagOnPress: true,
140139
maxNumberOfTags: Number.POSITIVE_INFINITY
141140
};
142141

@@ -148,7 +147,7 @@ Tags.propTypes = {
148147
onChangeTags: PropTypes.func,
149148
readonly: PropTypes.bool,
150149
maxNumberOfTags: PropTypes.number,
151-
deleteOnTagPress: PropTypes.bool,
150+
deleteTagOnPress: PropTypes.bool,
152151
containerStyle: PropTypes.any,
153152
style: PropTypes.any,
154153
inputContainerStyle: PropTypes.any,

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
22
"name": "react-native-tags",
3-
"version": "1.7.0",
3+
"version": "1.8.0",
44
"description": "Tag input component for React Native",
5+
"keywords": [
6+
"react native",
7+
"tags",
8+
"tag input"
9+
],
510
"main": "index.js",
611
"scripts": {
712
"test": "jest",

0 commit comments

Comments
 (0)