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

customInput failed prop type with styled-component passed #272

Closed
alamchrstn opened this issue Jan 18, 2019 · 6 comments
Closed

customInput failed prop type with styled-component passed #272

alamchrstn opened this issue Jan 18, 2019 · 6 comments

Comments

@alamchrstn
Copy link

alamchrstn commented Jan 18, 2019

Hi, sorry but I got this error when I try to pass a styled-component

import styled from 'styled-components';

const StyledInput = styled((props) => (
  <input {...props} />
))`
  // my stylings...
`

to the customInput prop. The error that I got is the following

Failed prop type: Invalid prop customInput of type object supplied to NumberFormat, expected function.

However the app works just fine.
What's the cause of this if I may get a better understanding? Thank you in advance!

@ferdinandsalis
Copy link

I am getting the same warning.

@harry-sm
Copy link

I am too.

@blaiprat
Copy link

blaiprat commented Apr 21, 2019

Had the same issue, but after changing the prop to a function wrapper seems to be workign as expecteed. The code that works:

<NumberFormat
    type="text"
    value={value}
    customInput={(props) => <StyledInput {...props} />}
/>

Update:
Seems that after applying this only the first key is registered, so still not working as expected

@harry-sm
Copy link

@blaiprat
Tried that too same issue, after the first keystroke it fails.

@blaiprat
Copy link

blaiprat commented Apr 23, 2019

In the end, I approached this in another way, by instead creating the styled components definition using NumberFormat this way. This allows to customise it and works as expected

import styled from "styled-components";
import NumberFormat from "react-number-format";


const NumberFormatStyled = styled(NumberFormat)`
    background: transparent;
    border: 0;
`;

const MyComponent = () => {
    return (
        <div>
            My custom format input
            <NumberFormatStyled
                type="text"
                value={value}
            />
        </div>
    )
}

@alextiley
Copy link
Contributor

I have created a pull request which fixes this - the function prop-type is not quite correct and can now be replaced with PropTypes.elementType. As a temporary workaround it's possible to suppress the prop-type warning by wrapping your styled-component in a class component, e.g:

const StyledInput = styled.input`
  // Your styles
`;

class Input extends React.Component {
  render() {
    return (
      <StyledInput {...this.props} />
    );
  }
}

This is not ideal but is another solution for those who stumble upon this.

s-yadav added a commit that referenced this issue May 12, 2019
Use elementType PropType for customInput prop (fixes #272)
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 a pull request may close this issue.

5 participants