Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoComplete组件 BUG #4778

Closed
Liguo-Wang opened this issue Feb 7, 2017 · 10 comments · Fixed by #4768
Closed

AutoComplete组件 BUG #4778

Liguo-Wang opened this issue Feb 7, 2017 · 10 comments · Fixed by #4768
Assignees

Comments

@Liguo-Wang
Copy link

Liguo-Wang commented Feb 7, 2017

Environment(required)

  • antd version: 2.7.0
  • OS and its version:
  • Browser and its version:

What did you do? Please provide steps to re-produce your problem.

What do you expected?

What happen?

image
1.输入框高度变低了
2.自动补全的字符前端自动添加了其他不期望的字符".$"

Re-producible online demo

@RaoHai
Copy link
Contributor

RaoHai commented Feb 7, 2017

第一个问题在这 #4768
第二个问题有 demo 么。。

@Liguo-Wang
Copy link
Author

Liguo-Wang commented Feb 8, 2017

第二个问题的例子:

import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
import { Form, Select, AutoComplete } from 'antd';
const FormItem = Form.Item;
const Option = Select.Option;
const AutoOption = AutoComplete.Option;

import './public/style/main.less';
class Edit extends Component {
    constructor(props){
      super(props);
      this.state = {
        emailChildren: []
      };
      this.handleEmailChange = (value) => {
        let result, emailChildren;
        if (!value || value.indexOf('@') >= 0) {
          result = [];
        } else {
          result = ['126.com', '163.com', 'qq.com'].map(domain => `${value}@${domain}`);
        }
        emailChildren = result.map((email) => {
          return <Option key={email}>{email}</Option>;
        });
        console.log(emailChildren)
        this.setState({ emailChildren });
      }
    }
    render() {
      const { getFieldDecorator } = this.props.form;
      return(
        <div>
          <Form horizontal>
          <FormItem
            label='Email'
            hasFeedback
            >
            {getFieldDecorator('email', {
              rules: [{
                type: 'email', message: 'The input is not valid E-mail!',
              }, { 
                required: true, message: 'Please input Email!' 
              }]
            })(
              <AutoComplete
                onChange={this.handleEmailChange}
                placeholder='Email'
              >
                {this.state.emailChildren}
              </AutoComplete>
            )}
          </FormItem>
        </Form>
        </div>
      )
    }
}
const UserEdit = Form.create()(Edit);
//挂载点
const MOUNT_NODE = document.getElementById('app');
ReactDOM.render(
  <div>
    <UserEdit/>
  </div>,
  MOUNT_NODE
);

这个是加了表单控件的getFieldDecorator这个之后就有问题

@benjycui
Copy link
Contributor

benjycui commented Feb 8, 2017

Please learn how to write readable Markdown, and it's a good habit to preview your comment before submitting.

Please provide a re-producible demo: http://codepen.io/benjycui/pen/KgPZrE?editors=001

@Liguo-Wang
Copy link
Author

@benjycui @RaoHai OK,demo已经制作好了:http://codepen.io/wangliguo/pen/KaxvYO?editors=1010, 感谢指导

@afc163
Copy link
Member

afc163 commented Feb 8, 2017

https://facebook.github.io/react/docs/react-component.html#state

this.state 里应该只存 plain JavaScript object,不应该存放 Visual Dom。

@afc163 afc163 closed this as completed Feb 8, 2017
@RaoHai
Copy link
Contributor

RaoHai commented Feb 8, 2017

好像真不是放 virtualdom 的问题。。。

@afc163 afc163 reopened this Feb 8, 2017
@RaoHai
Copy link
Contributor

RaoHai commented Feb 8, 2017

找到问题了。。

此处 用了 React.Children.toArray(children);

然鹅,React.Children.toArray 会被 React 加一个 .$ 的 prefix。

https://github.com/facebook/react/blob/6810627a91f2020caee7fecf21580187dc6ef0fc/src/isomorphic/children/ReactChildren.js#L120

RaoHai added a commit to RaoHai/ant-design that referenced this issue Feb 8, 2017
@RaoHai
Copy link
Contributor

RaoHai commented Feb 8, 2017

@wangliguo6666 修复之前你可以暂时用 <AutoComplete dataSource={this.state.emailChildren} /> 规避一下这里。

@Liguo-Wang
Copy link
Author

Liguo-Wang commented Feb 8, 2017

@ALL, 感谢各位的解答帮助!^-^a

ddcat1115 pushed a commit that referenced this issue Feb 9, 2017
*  fix AutoComplete size

 + close #4766

* use input mixin

* use css variables

*  use children directly instead of React.Children.toArray

 + close #4778
@lock
Copy link

lock bot commented May 2, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants