react-datepicker input width will not adjust to 100%

前端 未结 8 2043
谎友^
谎友^ 2021-02-14 00:16

I am attempting to adjust the width of the react-datepicker input box and surprisingly have found little information out there and am unable to effect its width. I would just l

相关标签:
8条回答
  • 2021-02-14 00:46

    I also stumbled into this issue as well. To solve this, there is a property that you can add directly to the DatePicker component which is the "wrapperClassName" and this property will allow us to directly apply classes to the "react-datepicker-wrapper".

    Example:

    <DatePicker wrapperClassName="datepicker" />
    

    and then

    .datepicker {
        width: 100%;
    }
    

    or if you are using tailwindcss, just directly apply

    <DatePicker wrapperClassName="w-full" />
    

    Note: This will only make the wrapper to be full width, therefore you will also need to apply "width: 100%" on the datepicker component if you want the input field to occupy full width as well.

    0 讨论(0)
  • 2021-02-14 00:47
    //html file
      <div className="customDatePickerWidth">
                  <DatePicker
                    placeholderText="Select Schedule Date"
                 />
      </div>
    
    //css file    
    .customDatePickerWidth, 
        .customDatePickerWidth > div.react-datepicker-wrapper, 
        .customDatePickerWidth > div > div.react-datepicker__input-container
        .customDatePickerWidth > div > div.react-datepicker__input-container input {
           width: 100%;
           height: 100%;
        }
        .react-datepicker__input-container  {
            width: inherit;
            height: inherit;
          }
          .react-datepicker__input-container input {
            width: inherit;
            height: 100%;
          }
    
          .react-datepicker-wrapper {
            width: 100%;
          }
    
    0 讨论(0)
提交回复
热议问题