Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.
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
31 changes: 31 additions & 0 deletions Tags/__tests__/Tags_enzyme-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,37 @@ import Tags from "../../";
enzyme.configure({ adapter: new Adapter() });

describe("Tags", () => {
describe("tags", () => {
it("removes a tag when you press them", () => {
const wrapper = shallow(
<Tags initialTags={["this", "is", "a", "test"]} />
);

wrapper
.find("Tag")
.at(1)
.simulate("press");

expect(wrapper.find("Tag").length).toEqual(3);
});

it("doesn't remove tags when they're readonly", () => {
const wrapper = shallow(
<Tags
deleteTagOnPress={false}
initialTags={["this", "is", "a", "test"]}
/>
);

wrapper
.find("Tag")
.at(0)
.simulate("press");

expect(wrapper.find("Tag").length).toEqual(4);
});
});

describe("TextInput", () => {
describe("onChangeText", () => {
it("should add a new tag when a space, or comma is detected", () => {
Expand Down
33 changes: 16 additions & 17 deletions Tags/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Tags extends React.Component {
style,
tagContainerStyle,
tagTextStyle,
deleteOnTagPress,
deleteTagOnPress,
onTagPress,
readonly,
maxNumberOfTags,
Expand All @@ -88,7 +88,7 @@ class Tags extends React.Component {
key={i}
label={tag}
onPress={e => {
if (deleteOnTagPress) {
if (deleteTagOnPress) {
this.setState(
{
tags: [
Expand All @@ -112,19 +112,18 @@ class Tags extends React.Component {
/>
))}

{!readonly &&
maxNumberOfTags > this.state.tags.length && (
<View style={[styles.textInputContainer, inputContainerStyle]}>
<TextInput
{...textInputProps}
value={this.state.text}
style={[styles.textInput, inputStyle]}
onChangeText={this.onChangeText}
onSubmitEditing={this.onSubmitEditing}
underlineColorAndroid="transparent"
/>
</View>
)}
{!readonly && maxNumberOfTags > this.state.tags.length && (
<View style={[styles.textInputContainer, inputContainerStyle]}>
<TextInput
{...textInputProps}
value={this.state.text}
style={[styles.textInput, inputStyle]}
onChangeText={this.onChangeText}
onSubmitEditing={this.onSubmitEditing}
underlineColorAndroid="transparent"
/>
</View>
)}
</View>
);
}
Expand All @@ -136,7 +135,7 @@ Tags.defaultProps = {
createTagOnString: [",", " "],
createTagOnReturn: false,
readonly: false,
deleteOnTagPress: true,
deleteTagOnPress: true,
maxNumberOfTags: Number.POSITIVE_INFINITY
};

Expand All @@ -148,7 +147,7 @@ Tags.propTypes = {
onChangeTags: PropTypes.func,
readonly: PropTypes.bool,
maxNumberOfTags: PropTypes.number,
deleteOnTagPress: PropTypes.bool,
deleteTagOnPress: PropTypes.bool,
containerStyle: PropTypes.any,
style: PropTypes.any,
inputContainerStyle: PropTypes.any,
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"name": "react-native-tags",
"version": "1.7.0",
"version": "1.8.0",
"description": "Tag input component for React Native",
"keywords": [
"react native",
"tags",
"tag input"
],
"main": "index.js",
"scripts": {
"test": "jest",
Expand Down