import React from "react"; import styles from "./index.less"; import { Tag, Input } from "antd"; import { TweenOneGroup } from "rc-tween-one"; import { PlusOutlined } from "@ant-design/icons"; class EditableTagGroup extends React.Component { state = { tags: ["Tag 1", "Tag 2", "Tag 3"], inputVisible: false, inputValue: "" }; handleClose = removedTag => { const tags = this.state.tags.filter(tag => tag !== removedTag); console.log(tags); this.setState({ tags }); }; showInput = () => { this.setState({ inputVisible: true }, () => this.input.focus()); }; handleInputChange = e => { this.setState({ inputValue: e.target.value }); }; handleInputConfirm = () => { const { inputValue } = this.state; let { tags } = this.state; if (inputValue && tags.indexOf(inputValue) === -1) { tags = [...tags, inputValue]; } console.log(tags); this.setState({ tags, inputVisible: false, inputValue: "" }); }; saveInputRef = input => (this.input = input); forMap = tag => { const tagElem = ( { e.preventDefault(); this.handleClose(tag); }} > {tag} ); return ( {tagElem} ); }; render() { const { tags, inputVisible, inputValue } = this.state; const tagChild = tags.map(this.forMap); return (
{ e.target.style = ""; } }} leave={{ opacity: 0, width: 0, scale: 0, duration: 200 }} appear={false} > {tagChild}
{inputVisible && ( )} {!inputVisible && ( New Tag )}
); } } export default () => (
);