您可以将自定义输入DatePicker
作为道具传递给。创建一个带有 FA 图标的自定义输入组件并将其作为道具传递。
class CustomInput extends React.Component {
render() {
return (
<div className="wrapper">
<i onClick={this.props.onClick} aria-hidden="true" className="fa fa-calendar"></i>
<input onClick={this.props.onClick} className="dateInput" value={this.props.value} type="text" />
</div>
)
}
}
CSS
.wrapper { position: relative; }
i.fa-calendar { position: absolute; top: 1px; left: 5px; }
.dateInput {
padding-left: 20px;
}
演示
例子
.wrapper { position: relative; }
i.fa-calendar { position: absolute; top: 1px; left: 5px; }
.dateInput {
padding-left: 20px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.0/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.21.1/babel.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<div id="root"></div>
<script type="text/babel">
class CustomInput extends React.Component {
render() {
return (
<div className="wrapper">
<i onClick={this.props.onClick} aria-hidden="true" className="fa fa-calendar"></i>
<input onClick={this.props.onClick} className="dateInput" value={this.props.value} type="text" />
</div>
)
}
}
ReactDOM.render(
<CustomInput value='19-12-16, 02:00' />,
document.getElementById('root')
);
</script>