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

城市选择组件相关优化 #174

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/pages/picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PickerDemo extends React.Component {
onCancel={e=>this.setState({city_show: false})}
onChange={text=>this.setState({city_value: text, city_show: false})}
show={this.state.city_show}
lang={{ leftBtn: '取消', rightBtn: '确定' }}
/>


Expand Down
8 changes: 7 additions & 1 deletion src/components/picker/city_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ class CityPicker extends React.Component {
* display the component
*
*/
show: PropTypes.bool
show: PropTypes.bool,
/**
* language object consists of `leftBtn` and `rightBtn`
*
*/
lang: PropTypes.object,
}

static defaultProps = {
Expand Down Expand Up @@ -126,6 +131,7 @@ class CityPicker extends React.Component {
defaultSelect={this.state.selected}
groups={this.state.groups}
onCancel={this.props.onCancel}
lang={this.props.lang}
/>
)
}
Expand Down
11 changes: 10 additions & 1 deletion src/components/picker/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ class Picker extends Component {
}

handleChanges(){
this.handleClose( ()=> { if(this.props.onChange) this.props.onChange(this.state.selected, this) } )
this.handleClose( ()=> {
// choose default city
const chooseDefault = this.state.selected.find((item) => item != 0) === undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这个item != 0在 普通picker使用情况下 可能不是默认的值
picker最好不能受限于citypicker


if (chooseDefault && this.props.onGroupChange) {
this.props.onGroupChange({}, 0, 0, this.state.selected, this)
}

if(this.props.onChange) this.props.onChange(this.state.selected, this)
})
}

handleChange(item, i, groupIndex){
Expand Down