Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

How can I make only one tag selected? #15

Open
kimho opened this issue May 15, 2019 · 2 comments
Open

How can I make only one tag selected? #15

kimho opened this issue May 15, 2019 · 2 comments

Comments

@kimho
Copy link

kimho commented May 15, 2019

How can I make only one tag selected like radio button?

@liukefu2050
Copy link

liukefu2050 commented May 24, 2019

Copy classes and add this code to TagSelect.js

componentDidUpdate (prevProps, prevState, prevContext) {

if (prevProps !== this.props) {

  const value = {}

  this.props.value.forEach((val) => {

    value[val[[this.props.keyAttr]] || val] = val

  })

  this.setState({ value })

}

}

example:
<TagSelect
value={[this.state.currItem]}
theme="default"
max={1}
ref={(tag) => {
this.tag = tag;
}}
onItemPress={(item) => {
this.setState({currItem:item})
}}
data={data}
/>

@raheelshan
Copy link

raheelshan commented Oct 27, 2019

You can extend class like this.

`
import { TagSelect } from 'react-native-tag-select';

class TagSelectExtension extends TagSelect {

	handleSelectItem = (item) => {
		const key = item[this.props.keyAttr] || item

		const value = []
		const found = this.state.value[key]

		value[key] = item
		return this.setState({ value }, () => {
			if (this.props.onItemPress) {
				this.props.onItemPress(item)
			}
		})
	}

}

export default TagSelectExtension

`

Now instead of using TagSelect.js import TagSelectExtension.js and use it. this is safe way. Also notice when extending React.Component extend TagSelect.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants