AntdForm是否可以自定义allowClear方法?
创始人
2024-11-07 16:01:24
0

可以通过自定义控件的render方法,覆盖Antd Form默认的控件。例如,我们可以自定义一个Select控件,并在render方法中处理allowClear逻辑:

import React from 'react';
import { Select } from 'antd';

class CustomSelect extends React.Component {
  handleChange = (value) => {
    const { onChange } = this.props;
    onChange(value);
  }

  handleClear = () => {
    const { onChange } = this.props;
    onChange(undefined);
  }

  render() {
    const { allowClear, ...otherProps } = this.props;
    return (