React-Select Remove focus border
Asked Answered
G

11

67

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

Guyguyana answered 2/10, 2018 at 18:29 Comment(3)
Please add a relevant code snippet. There are already tons of examples of how to hide a border or outline #1458349Cabotage
@Cabotage There is realy no relevant code snippet for this i think. I need help removing border / outline specificaly from focused state of React-Select component. I have no idea what to select or how to adjust style options. I have went over all documenation and all topics i could find on this. But this is definitely not question about removing simple outline/border from normal component.Guyguyana
People, don't do this please—you'll end up excluding people relying on visual focus cues when using your interfaces (e.g. using keyboard nav). The only time you should do this is when you want to replace the focus styles with your ownHalibut
B
132

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.

Barbellate answered 2/10, 2018 at 19:40 Comment(4)
This solution is a bit excessive (although working), it is sufficient to use boxShadow: 'none'Pilcomayo
@AlexDobrushskiy depending your version of react-select, removing just the box-shadow with none is not working (specially in early v2)Barbellate
@AlexDobrushskiy I have edited my answer for newer version of react-selectBarbellate
Would it make sense to add a disclaimer at the beginning of this answer to tell developers they shouldn't do this, unless they're replacing the focus styles by their own? This is an accessibility issueHalibut
V
33

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.

Vowell answered 29/7, 2019 at 8:49 Comment(0)
E
9

For anyone using react-select with @tailwindcss/forms, the dreaded blue line aka box-shadow on the input is introduced by the forms plugin. You need to pass strategy: class to the forms plugin in tailwind.config.js file.

plugins: [
  ...
  require('@tailwindcss/forms')({
    strategy: 'class',
  }),
]

More on this here: https://github.com/tailwindlabs/tailwindcss-forms#using-only-global-styles-or-only-classes

Similar question: https://mcmap.net/q/296854/-how-to-remove-the-outline-and-box-shadow-on-input-tag-in-react-select

Edmundoedmunds answered 23/2, 2023 at 7:44 Comment(1)
thank heavens for you, @Akshay. This is exactly what I neededBignonia
N
6

This one is definitely working:

const style = {
    control: (base) => ({
      ...base,
      boxShadow: "none"
    })
}
Nikethamide answered 25/6, 2020 at 10:7 Comment(0)
T
3

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

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

}),

Tiffany answered 2/7, 2022 at 12:31 Comment(0)
U
1

This removes the thickness of the box-shadow, and removes the blue from the border.

const controlStyle = base => ({
    ...base, 
    boxShadow: "none", 
    borderColor: "#cccccc",
    "&:hover": {
        borderColor: "#cccccc"
    }
})
Unsettle answered 17/11, 2022 at 19:39 Comment(0)
C
1

Lord in heaven we needed:

import AsyncSelect from "react-select/async";

<AsyncSelect
  onChange={(v) => {
    props.onChange(v);
  }}
  
  {/* ... */}
  
  styles={{
    control: (base, state) => ({
      ...base,
      "*": {
        boxShadow: "none !important",
      },
    })
  }}
/>
Calgary answered 11/9, 2023 at 19:7 Comment(0)
B
0

Another approach of Akshay Kumar's awnser that worked for me:

input[id^="react-select-"] {
  @apply focus:outline-none focus:border-transparent focus:ring-0;
}
Bargeboard answered 5/5, 2023 at 15:34 Comment(0)
R
0

Rather than remove it you might want to change the color this is how you might go about this V3 ReactSelect

      styles = {{
        control: (baseStyles, state) => ({
          ...baseStyles,
          borderColor: state.isFocused ? 'limegreen' : 'red',
          boxShadow: state.isFocused ? '0 0 0px 4px rgba(255, 0, 0, 1)' : 'none',
          '&:hover': {
            borderColor: 'limegreen'
          }
        }),
      }}
Rochellerochemont answered 24/11, 2023 at 1:34 Comment(0)
B
0

This worked for me

styles={{
            control: (base) => ({
              ...base,
              zIndex: 9999,
              border: "1.5px solid #c9ccd0",
              boxShadow: "none !important",
              "*": {
                boxShadow: "none !important",
              },
              "&:hover": {
                border: "1.5px solid #7e22ce !important",
              },
            }),
          }}
Bordeaux answered 14/12, 2023 at 13:31 Comment(0)
P
0
 styles={{
                          control: (base, state) => ({
                            ...base,
                            border: "none",
                            boxShadow: "none",
                            "&:hover": {
                              border: "none",
                            },
                          }),
                        }}
Prejudge answered 1/2 at 12:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.