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

Support providing our own Input component #24

Closed
mquandalle opened this issue Feb 1, 2017 · 9 comments
Closed

Support providing our own Input component #24

mquandalle opened this issue Feb 1, 2017 · 9 comments
Milestone

Comments

@mquandalle
Copy link
Contributor

Hello,

I would be interested in an additional Prop for the NumberFormat component, that would allow the user to provide its own Input component implementation. This functional composition pattern would permit, among other thing, the integration of NumberFormat logic with existing input components like http://react-toolbox.com/#/components/input and many others

import MaterialDesignInput from 'react-toolbox/lib/input';

<NumberFormat inputComponent={MaterialDesignInput} />

Any though on that?

@s-yadav
Copy link
Owner

s-yadav commented Feb 2, 2017

This can be little tricky as this will assume the custom input has onChange, onInput, onKeyDown.
But yes we can ask user to provide that if its not there.

@mquandalle
Copy link
Contributor Author

For Flow types of Typescript users, it is possible to statically enforce that the inputComponent parameter must have all required attributes and methods. For vanilla JS/ES6 users, we'll need to specify that in the documentation, but for the use case above, which is to use a styled input from a Material design library, the provided input extends the build-in input component, so it has all required attributes.

@s-yadav s-yadav added this to the 1.1.0 milestone Feb 3, 2017
@mquandalle
Copy link
Contributor Author

I tried to implement this feature, and assuming than the “wrapper” component will have all the properties and methods of an input element is indeed very tricky with the JavaScript inheritance model. I believe it would be easier to rely on a unique method on the wrapper, like getInputNode() which will return the internal input DOM node. For instance Material-UI already provide this method.

@s-yadav
Copy link
Owner

s-yadav commented Feb 7, 2017

I have added this on 1.1.0 alpha

@mquandalle
Copy link
Contributor Author

Are you sure this is already implemented? I can't see any code related to that feature...

@s-yadav
Copy link
Owner

s-yadav commented Feb 7, 2017

Oh I have not pushed it yet. I am finding input node using document.activeElement (This gives the current focused element). I will push it on the 1.1.0 branch

@s-yadav
Copy link
Owner

s-yadav commented Feb 7, 2017

Check the 1.1.0-alpha branch. Also added an example of material-ui

@mquandalle
Copy link
Contributor Author

mquandalle commented Feb 17, 2017

@s-yadav Any news on v1.1 release?

edit: I didn't see that the alpha was released on NPM, that's good for me :)

@s-yadav
Copy link
Owner

s-yadav commented Feb 19, 2017

1.1.0 is released. Thanks.

@s-yadav s-yadav closed this as completed Feb 19, 2017
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

No branches or pull requests

2 participants