Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put Calendar Icon to Datepicker in right side

Tags:

reactjs

I am working on a React project, In my project I am trying to put the calendar icon on the right

Side for Datepicker. Here I am using Fontawesome icons. But It is showing some error please

help me to solve this.

This is App.js

import React, { Component } from 'react';
import './App.css';
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";

class App extends Component {
  constructor(props) {
    super(props)

    this.state = {
      startDate: ''
    }
  }

  handleChange = date => {
    this.setState({
      startDate: date
    });
  };

  render() {
    return (
      <DatePicker
      placeholderText={'Select date'}
        selected={this.state.startDate}
        onChange={this.handleChange}
        <i class="far fa-calendar"></i>
      />
    )
  }
}

export default App
like image 718
Cruse Avatar asked Dec 21 '25 18:12

Cruse


1 Answers

Creating your own input in react-datepicker is possible using customInput option.

You can take a look at this component: DatePickerComponent. Here I used styled-components library but you can achieve similar result using simple CSS.

like image 57
patryk-szwed Avatar answered Dec 24 '25 07:12

patryk-szwed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!