copy paste tags handler

This commit is contained in:
feruz 2020-01-06 06:04:59 +02:00
parent 90a2e47363
commit 8d05b4dfe1

View File

@ -19,13 +19,23 @@ export default class TagAreaView extends Component {
this.state = {
currentText: '',
chips: props.draftChips || [' '],
chipsCount: props.chipsCount || 7,
chipsCount: props.chipsCount || 10,
activeChip: 0,
};
}
// Component Functions
_handleOnChange = (text, i) => {
if (text.indexOf(' ') > 0) {
let ssp = [];
ssp = text.split(' ').filter(iii => iii);
if (ssp.length > 1) {
for (let ii = i; ii < i + ssp.length; ii++) {
const element = ssp[ii - i];
this._handleTagAdded(ii, element);
}
}
}
this.setState({ currentText: text.replace(/\s/g, '').replace(/,/g, '') });
if (text.indexOf(' ') > 0 && text) {
@ -50,10 +60,17 @@ export default class TagAreaView extends Component {
const _currentText = (currentText && currentText.trim()) || text;
if (_currentText && chips && chips.length < chipsCount) {
if (i !== null && text !== null) {
chips[i] = _currentText;
this.setState({
chips: [...chips],
});
} else {
this.setState({
chips: [...chips, _currentText],
});
}
}
if (handleTagChanged && chips.length < chipsCount + 1) {
handleTagChanged([...chips, _currentText]);