react-datepicker icon indicating copy to clipboard operation
react-datepicker copied to clipboard

customInput doesn't respect className

Open heatherbooker opened this issue 9 years ago • 3 comments

When I pass a customInput with a div as the outermost wrapper, any classNames associated with that div are removed in rendering. For example,

<div className="potatoes">
  <input />
  <button>hi</button>
</div>

Is rendered as

<div>
  <input />
  <button>hi</button>
</div>

I also notice that an id is stripped from the outermost component, and that changing the element type of the outermost component doesn't prevent this from happening.

Is there a reason for this or it's just a quirk? Thanks!

heatherbooker avatar Aug 08 '17 19:08 heatherbooker

Hey! I was trying this out earlier and noticed that too - if I passed an element in with className, the html would show a class attribute with nothing else there.

In my case, I was just passing in a render function into customInput such as

render () {
    return <DatePicker
        customInput={this.renderInput()}
    />
}

renderInput () {
    return <div className="test" />;
}

I was able to get the classes to work when I took the custom input out of the React class and into its own CustomInput component. Hope that helps!

serkolch avatar Aug 09 '17 21:08 serkolch

@heatherbooker @serkolch The docs where not clear on this, I got the className to render on the customInput when providing it to the parent <DatePicker /> component.

This will render the custom-class on the button component

<DatePicker
  className="custom-class" 
  customInput={<Button>{value}</Button>}
/>

sonofjack avatar Nov 22 '17 04:11 sonofjack

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 30 '19 16:08 stale[bot]