Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing ref via custom props #1166

Merged
merged 1 commit into from Dec 11, 2017
Merged

Conversation

lewisdiamond
Copy link
Contributor

When using react-datepicker with material-ui's TextField, you get an error because TextField is a stateless fn component and you can't pass ref to it. It however accepts inputRef. Allow users to define how the ref is passed to the custom input.

@aij
Copy link
Contributor

aij commented Dec 8, 2017

I think it would make more sense to wrap TextField in a component that follows the standard API.

@codecov
Copy link

codecov bot commented Dec 8, 2017

Codecov Report

Merging #1166 into master will increase coverage by 0.13%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1166      +/-   ##
==========================================
+ Coverage   86.25%   86.38%   +0.13%     
==========================================
  Files          13       13              
  Lines         851      852       +1     
  Branches      142      143       +1     
==========================================
+ Hits          734      736       +2     
+ Misses         32       31       -1     
  Partials       85       85
Impacted Files Coverage Δ
src/index.jsx 90.9% <100%> (+0.58%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d1fc705...1616bf8. Read the comment docs.

@lewisdiamond
Copy link
Contributor Author

@aij I disagree. Adding customInputRef just adds more flexibility, you can even wrap your custom input in a component (e.g. that does styling) without having to worry about the input API every time.

@aij
Copy link
Contributor

aij commented Dec 8, 2017

It doesn't just add more flexibility. It also adds more complexity.

What's the reasoning for not also adding customInputValue', 'customInputOnBlur, customInputId customInputClassName etc?

@lewisdiamond
Copy link
Contributor Author

lewisdiamond commented Dec 8, 2017

customInput already exists except it's limited to only class components because of the ref prop. ref isn't accessible from within the component, it's removed by React. ref is the only property like that.

Not only that, it also forces you to re-implement the API even if it's already provided by another child component.

https://reactjs.org/docs/refs-and-the-dom.html#exposing-dom-refs-to-parent-components

@aij aij merged commit f492511 into Hacker0x01:master Dec 11, 2017
@jwm0
Copy link

jwm0 commented Mar 24, 2018

@lewisdiamond Can I see an example of how it's supposed to be done using material-ui TextField?

Edit: nevermind, found the docs => change customInputRef's default value ("ref") to "inputRef"

Squar89 pushed a commit to Squar89/react-datepicker2 that referenced this pull request Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants