From ffa59fd0885c8032750dd7ae4104b7030afacf78 Mon Sep 17 00:00:00 2001 From: zhuyue Date: Tue, 2 Nov 2021 18:49:42 +0800 Subject: [PATCH] feat: Make ipProtocol can be entered by user Make ipProtocol can be entered by user Change-Id: I74122014b9e209af331db467f7d84e56d70cfc50 --- .../FormItem/SelectWithInput/index.jsx | 70 +++++++++++++++++++ src/components/FormItem/index.jsx | 2 + src/locales/en.json | 1 + src/locales/zh.json | 1 + .../Detail/Rule/actions/Create.jsx | 11 +-- 5 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 src/components/FormItem/SelectWithInput/index.jsx diff --git a/src/components/FormItem/SelectWithInput/index.jsx b/src/components/FormItem/SelectWithInput/index.jsx new file mode 100644 index 00000000..1302d692 --- /dev/null +++ b/src/components/FormItem/SelectWithInput/index.jsx @@ -0,0 +1,70 @@ +// Copyright 2021 99cloud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import React, { Component } from 'react'; +import { Select } from 'antd'; + +export default class Index extends Component { + constructor(props) { + super(props); + this.state = { + value: undefined, + inputVal: undefined + }; + } + + onChange = (val) => { + this.setState({ + value: val, + inputVal: undefined + }, () => { + const { formRef, onChange, name } = this.props; + formRef.current && + formRef.current.setFieldsValue({ [name]: val }); + onChange && onChange(val); + }); + }; + + onSearch = (value) => { + !!value && + this.setState({ + inputVal: value + }); + }; + + onBlur = () => { + const { inputVal } = this.state; + !!inputVal && this.onChange(inputVal); + }; + + render() { + const { options = [], filterOption = false } = this.props; + const { value } = this.state; + return ( +