Hiding input spinner using styled-component
Asked Answered
S

2

6

There are lot of solutions out there to hide the input spinner using css. One of them being:

input::-webkit-inner-spin-button, input::-webkit-outer-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
    -moz-appearance:textfield !important;
}

I want to know how I can implement it in styled-component? Thanks

Salt answered 29/5, 2019 at 2:28 Comment(0)
L
17

Declare like this:

const Input = styled.input`
    ::-webkit-inner-spin-button{
        -webkit-appearance: none; 
        margin: 0; 
    }
    ::-webkit-outer-spin-button{
        -webkit-appearance: none; 
        margin: 0; 
    }    
`;

Use like this:

<Input type="number">

Leighannleighland answered 29/5, 2019 at 2:41 Comment(0)
K
0

If you are using styled-components nowadays, use "&::" at the beginning of the pseudo-element, in your "input" component, as follows:

&::-webkit-inner-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
} 
&::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}
Karmakarmadharaya answered 2/8, 2023 at 19:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.