Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Select Remove focus border

i cant figure out how do i remove border or outline ( not sure which one it is ) from react select, when its focused.

Uploaded image for reference. I have no border by default.enter image description here

customStyle = {      
        control: provided => ({
            ...provided,           
            height: 10,
            width: 300,
            padding: 10,
            margin: 0,
            marginLeft: 0,
            border: "0px solid black",
            fontSize: 13,
            backgroundColor: 'white',
            outline: 'none'            
        })
    }  

Thanks

like image 504
CosmicSeizure Avatar asked Oct 02 '18 18:10

CosmicSeizure


People also ask

How do you remove a focus border?

To remove or disable focus border of browser with CSS, we select the styles for the :focus pseudo-class. to set the outline style to none to remove the border of the element that's in focus.

How do I change the placeholder in react select?

Set the first option element of the select tag to disabled and give it an empty string value. Initialize the state for the select tag to an empty string.

How do I change the background color in react select?

To set the background color for react-select drop downs, we can return an object with the color values set. We set the styles prop to the customStyles object which has various styles. The control method in the object returns an object with the style values.


4 Answers

React-select v3

const style = {
  control: base => ({
    ...base,
    border: 0,
    // This line disable the blue border
    boxShadow: 'none'
  })
};

Here a live example

React-select v2

To reset border when Select is focused you have two solutions:

  1. Use the state

    control: (base, state) => ({
        ...base,
        border: state.isFocused ? 0 : 0,
        // This line disable the blue border
        boxShadow: state.isFocused ? 0 : 0,
        '&:hover': {
           border: state.isFocused ? 0 : 0
        }
    })
    
  2. Use !important (this one works but I recommend to use the first solution, !important is never a good thing to employ)

    control: base => ({
       ...base,
       border: '0 !important',
       // This line disable the blue border
       boxShadow: '0 !important',
       '&:hover': {
           border: '0 !important'
        }
    })
    

Don't forgot to reset the boxShadow (blue border) that you get.

Here a live example.

like image 107
Laura Avatar answered Oct 20 '22 12:10

Laura


This worked for me:

control: (base, state) => ({
    ...base,
    border: '1px solid black',
    boxShadow: 'none',
    '&:hover': {
        border: '1px solid black',
    }
})

This will ensure the border remains when inactive, hovered or active but there is no blue box shadow.

like image 31
Jeff S. Avatar answered Oct 20 '22 12:10

Jeff S.


This one is definitely working:

const style = {
    control: (base) => ({
      ...base,
      boxShadow: "none"
    })
}
like image 4
matrixb0ss Avatar answered Oct 20 '22 13:10

matrixb0ss


I have tried a lot! and finally This one worked for me.

control: (provided) => ({
...provided,
border: 0,
outline: '1px solid white',

}),

like image 1
Chandra Roy Avatar answered Oct 20 '22 11:10

Chandra Roy