使用自定义按钮打开DatePicker或DatePickerDialog

时间:2016-04-14 16:00:59

标签: reactjs material-ui

有没有办法触发DatePickerDialog使用除了DatePicker开箱即用的内置input之外的外部控件/按钮打开?

我们正在使用material-ui库。

1 个答案:

答案 0 :(得分:3)

由于对话open状态由material-ui组件内部处理,唯一的方法是使用ref中的DatePicker并调用focus() }。有点黑客 - 但它有效......

示例:

<DatePicker
    ref='datePickerStartDate'
    errorStyle={componentSyles.error}
    textFieldStyle={componentSyles.textField}
    DateTimeFormat={Intl.DateTimeFormat}
    cancelLabel={cancelLabel}
    autoOk={true}
    {...this.props}
     />

<FontIcon
    onClick={(e) => { this.refs.datePickerStartDate.focus() }}
    className="material-icons" style={componentSyles.icon}>
    date_range
</FontIcon>
相关问题