alibaba-fusion / next

🦍 A configurable component library for web built on React.
https://fusion.design
MIT License
4.58k stars 584 forks source link

[Form] cant input while FormItem wrapped by PureComponent #1074

Closed bindoon closed 3 years ago

bindoon commented 5 years ago

Component

Form/Field

Steps to reproduce

import React from 'react@16';
import ReactDOM from 'react-dom@16';
import { Form, Input, Radio, Field, Button } from '@alife/next@1.x';

const FormItem = Form.Item;
const RadioGroup = Radio.Group;

class PPureComponent extends React.PureComponent {
  render() {
    console.log(/pure render/);
    return <div>{this.props.children}</div>;
  }
}

class NormalComponent extends React.Component {
  render() {
    console.log(/normal render/);
    return <div>{this.props.children}</div>;
  }
}

class BasicDemo extends React.Component {
  field = new Field(this);

  render() {
    return (
      <Form fieldOptions={{ forceUpdate: true }}>
        <PPureComponent>
          <FormItem label="Password:" hasFeedback required>
            <Input name="passwd" />
          </FormItem>
        </PPureComponent>
        <NormalComponent>
          <FormItem label="normal:" hasFeedback required>
            <Input name="name" />
          </FormItem>
        </NormalComponent>
      </Form>
    );
  }
}

ReactDOM.render(<BasicDemo />, mountNode);

https://riddle.alibaba-inc.com/riddles/4acb337d

bindoon commented 5 years ago

刚刚发现把 Input 换成原生的 input 是可以工作的,后续再定位下原因!!

bindoon commented 3 years ago

根本原因在于 原生input 把 value={undefined} 当成 props.value 不存在。而 Fusion Input 认为 value in props 即为受控。所以 input 可输入。

value={undefined} 为受控已经是规范之一,不再处理。

后续优化点:可以把标准规范往 value={null} 去引导。

AlexVagrant commented 3 years ago

Fusion中Inputundefined当做props的value,默认为受控组件, Fusion中Inputvalue值为null默认为受控组件 image antd也出现过相同问题,还希望能改进就改进一下

bindoon commented 3 years ago

目前 undefined 和 null 都认为是受控组件

AlexVagrant commented 3 years ago

目前 undefined 和 null 都认为是受控组件

已更改上述描述防止误导