react-otp-input icon indicating copy to clipboard operation
react-otp-input copied to clipboard

styling

Open yasasvy opened this issue 4 years ago • 6 comments

  • Describe the Feature Request how to apply styling to the individual default boxes after using OtpInput component? Like padding, margin or spacing in-between, size and all...?

yasasvy avatar Oct 20 '20 16:10 yasasvy

I am actually yet to try this but I believe nth child selectors should help you with styling individual inputs!

apollonian avatar Oct 21 '20 06:10 apollonian

Can't we pass an InputBox component that can override the default box styles. If we are able to give this component the position number of the box, then we can style then individually also.

<OtpInput
    value={this.state.otp}
    onChange={this.handleChange}
    numInputs={6}
    separator={<span>-</span>}
    inputBox={({pos})=>{
    if(pos === 2)
       return <input pos2style/>
   else 
      return <input defaultCustomStyle/>
    }}
 />

user9747 avatar Oct 21 '20 12:10 user9747

I guess that some properties of the child boxes (which are none other than inputs) should be exposed. That would allow styling them separately as well.

ARKEOLOGIST avatar Oct 28 '20 06:10 ARKEOLOGIST

I guess that some properties of the child boxes (which are none other than inputs) should be exposed. That would allow styling them separately as well.

I dont know anybody tried? Because I am really stuck

yasasvy avatar Nov 08 '20 02:11 yasasvy

Can't we pass an InputBox component that can override the default box styles. If we are able to give this component the position number of the box, then we can style then individually also.

<OtpInput
    value={this.state.otp}
    onChange={this.handleChange}
    numInputs={6}
    separator={<span>-</span>}
    inputBox={({pos})=>{
    if(pos === 2)
       return <input pos2style/>
   else 
      return <input defaultCustomStyle/>
    }}
 />

Will this work?

yasasvy avatar Nov 08 '20 02:11 yasasvy

Not right now. I was suggesting such a feature should added or something like @ARKEOLOGIST suggested. For now like @apollonian said you might need to use the css nth selector to style each component.

user9747 avatar Nov 08 '20 09:11 user9747

You can now customize individual inputs with v3

prateek3255 avatar Mar 25 '23 15:03 prateek3255