import React from 'react'; import ReactDOM from 'react-dom'; import Search from '..'; import { Button, Menu } from '../..'; const menuData = [ { label: 'Option 1', value: 'Option 1 Value', index: '1', }, { label: 'Option 2', value: 'Option 2 Value', index: '2', }, { label: 'Option 3', value: 'Option 3 Value', index: '3', }, { label: 'Option 4', value: 'Option 4 Value', index: '4', }, ]; interface IState { visible: boolean; value: string; menuData: { label: string; value: string; index: string; }[]; } class App extends React.Component<{}, IState> { constructor(props) { super(props); this.state = { visible: false, value: '111222', menuData, }; this.onVisibleChange = this.onVisibleChange.bind(this); this.onSearch = this.onSearch.bind(this); this.onChange = this.onChange.bind(this); this.onFocus = this.onFocus.bind(this); } renderMenu() { const menuData = this.state.menuData; return (
); } onSearch(value) { console.log(value); } onChange(value) { this.setState({ visible: value.length > 0, value, }); } onSelect(selectedKeys) { this.setState({ visible: false, value: selectedKeys[0], }); } onDelete(index, e) { e.stopPropagation(); const menuData = this.state.menuData; const menuDataNew = []; menuData.forEach(function(item) { if (item.index !== index) { menuDataNew.push(item); } }); this.setState({ menuData: menuDataNew, }); } onFocus() { this.setState({ visible: true, }); } onVisibleChange() { this.setState({ visible: false, }); } render() { const { visible, value } = this.state; return (