Skip to content

Commit

Permalink
fix InputAutoComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
pmg1989 committed Dec 27, 2017
1 parent 6822b68 commit 334b81b
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 40 deletions.
66 changes: 66 additions & 0 deletions src/components/InputAutoComplete/InputAutoComplete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { AutoComplete } from 'antd'

class InputAutoComplete extends Component {
static propTypes = {
value: PropTypes.string,
placeholder: PropTypes.string,
disabled: PropTypes.bool,
dataSource: PropTypes.array,
onChange: PropTypes.func,
}

static defaultProps = {
disabled: false,
placeholder: '请输入邮箱',
dataSource: ['newband.com', '163.com', 'qq.com', 'sina.com'],
}

state = {
value: '',
dataSource: [],
}

componentWillReceiveProps (nextProps) {
// Should be a controlled component.
if ('value' in nextProps) {
const value = nextProps.value
let dataSource
if (!value || value.indexOf('@') >= 0) {
dataSource = []
} else {
dataSource = nextProps.dataSource.map(domain => `${value}@${domain}`)
}
this.setState({ value, dataSource })
}
}

handleChange = (value) => {
if (!('value' in this.props)) {
this.setState({ value })
}
const onChange = this.props.onChange
if (onChange) {
onChange(value)
}
}

render () {
const { placeholder, disabled } = this.props
const { value, dataSource } = this.state

return (
<AutoComplete
backfill
dataSource={dataSource}
onChange={this.handleChange}
placeholder={placeholder}
value={value}
disabled={disabled}
/>
)
}
}

export default InputAutoComplete
1 change: 1 addition & 0 deletions src/components/InputAutoComplete/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export InputAutoComplete from './InputAutoComplete'
6 changes: 6 additions & 0 deletions src/components/InputAutoComplete/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "InputAutoComplete",
"version": "0.0.1",
"private": true,
"main": "./InputAutoComplete.js"
}
29 changes: 0 additions & 29 deletions src/components/InputEmail/InputEmail.js

This file was deleted.

1 change: 0 additions & 1 deletion src/components/InputEmail/index.js

This file was deleted.

6 changes: 0 additions & 6 deletions src/components/InputEmail/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export DataTable from './DataTable'
export DropMenu from './DropMenu'
export InputEmail from './InputEmail'
export InputAutoComplete from './InputAutoComplete'
export MediaPlayer from './MediaPlayer'
export SearchGroup from './Search'
export UploadFile from './UploadFile'
4 changes: 2 additions & 2 deletions src/routes/account/Admin/ModalForm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Form, Input, Radio, Modal, Icon, Select } from 'antd'
import { InputAutoComplete } from 'components'
import { validPhone } from 'utils/utilsValid'

const FormItem = Form.Item
Expand Down Expand Up @@ -114,8 +115,7 @@ const ModalForm = ({
message: '邮箱格式不正确',
},
],
})(<Input type="email" />)}
{/* (<InputEmailComplete/>)} */}
})(<InputAutoComplete />)}
</FormItem>
<FormItem label="角色:" hasFeedback {...formItemLayout}>
{getFieldDecorator('roleId', {
Expand Down
3 changes: 2 additions & 1 deletion src/routes/account/User/ModalForm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Form, Input, Modal, Icon } from 'antd'
import { InputAutoComplete } from 'components'
import { validPhone } from 'utils/utilsValid'

const FormItem = Form.Item
Expand Down Expand Up @@ -91,7 +92,7 @@ const ModalForm = ({
message: '邮箱格式不正确',
},
],
})(<Input />)}
})(<InputAutoComplete />)}
</FormItem>
</Form>
</Modal>
Expand Down

0 comments on commit 334b81b

Please sign in to comment.