Eliminate the focus border in React-Select

I've been struggling to remove the border or outline (not really sure which one it is) from React Select when it's focused.

Here is an image for reference. As you can see, I currently have no default border: https://i.stack.imgur.com/IubaN.png

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

Any help would be greatly appreciated. Thank you!

Answer №1

Styling React-select Components

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

Check out this live example

Resetting Borders in React-select Component

If you need to reset the border when the Select component is focused, here are two solutions:

  1. Using the state

    control: (base, state) => ({
        ...base,
        border: state.isFocused ? 0 : 0,
        // This line removes the blue border
        boxShadow: state.isFocused ? 0 : 0,
        '&:hover': {
           border: state.isFocused ? 0 : 0
        }
    })
    
  2. Using !important (this workaround works but it's recommended to opt for the first solution as using !important is not a good practice)

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

Remember to reset the boxShadow (blue border effect) that you may encounter.

Take a look at this live example.

Answer №2

Here's a solution that worked well for me:

styles: (element, status) => ({
    ...element,
    border: '1px solid black',
    boxShadow: 'none',
    '&:hover': {
        border: '1px solid black',
    }
})

Using this code will maintain the border in all states - inactive, hovered, or active - without the blue box shadow.

Answer №3

If you're working with react-select and @tailwindcss/forms, you may have noticed that the input displays a blue line or box-shadow, which is caused by the forms plugin. To fix this issue, make sure to add strategy: class in the forms plugin section of your tailwind.config.js file.

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

More information can be found here: https://github.com/tailwindlabs/tailwindcss-forms#using-only-global-styles-or-only-classes

For a similar question, check out:

Answer №4

Here's a code snippet that is confirmed to be functioning:

let style = {
    customizeControl: (baseStyle) => ({
      ...baseStyle,
      boxShadow: "none"
    })
}

Answer №5

I have experimented with numerous options and at last found success with this particular one.

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

}),

Answer №6

This code snippet eliminates the box-shadow thickness and changes the border color from blue to a lighter shade of gray.

const customizeControl = base => ({
    ...base, 
    boxShadow: "none", 
    borderColor: "#cccccc",
    "&:hover": {
        borderColor: "#cccccc"
    }
})

Answer №7

Dear heavenly Father, we call upon you:

import AsyncSelect from "react-select/async";

<AsyncSelect
  onChange={(selected) => {
    props.updateSelection(selected);
  }}
  
  {/* ... */}
  
  styles={{
    control: (baseStyle, state) => ({
      ...baseStyle,
      "*": {
        boxShadow: "none !important",
      },
    })
  }}
/>

Answer №8

Here is a different method from Akshay Kumar that I found effective:

input[id^="react-select-"] {
  @apply focus:outline-none focus:border-transparent focus:ring-0;
}

Answer №9

Instead of deleting it, you may consider altering the color. Here's a way to achieve this using 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'
          }
        }),
      }}

Answer №10

My issue was resolved using this method

styles={{
            control: (base) => ({
              ...base,
              zIndex: 9999,
              border: "1.5px solid #c9ccd0",
              boxShadow: "none !important",
              "*": {
                boxShadow: "none !important",
              },
              "&:hover": {
                border: "1.5px solid #7e22ce !important",
              },
            }),
          }}

Answer №11

 styles={{
                          customStyle: (base, state) => ({
                            ...base,
                            border: "none",
                            boxShadow: "none",
                            "&:hover": {
                              border: "none",
                            },
                          }),
                        }}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Stylish Pop-up Box appears hidden behind a different element

Is there a way to fix the issue of the FancyBox plugin being blocked by some part of the HTML on the page when trying to load a Vimeo movie into a popup? Here is the live link: click here : it's when you click on the slider image underneath the yello ...

Troubleshooting: Issue with fixed positioning in React (Next.js) causing problems with modal window functionality

I'm currently working on implementing a modal window in React, but I've encountered an issue where setting position: fixed results in the modal window's position being relative to the page rather than the browser window. For privacy reasons, ...

Unable to achieve horizontal alignment with DIV element set as inline-block

Currently, I have five columns that are aligned using the display:inline-block. Everything seems to be working fine, but there's a peculiar issue that arises when I refresh the page multiple times. Occasionally, while the first column remains at the t ...

Is it possible to create a translucent glass floating box over HTML elements, similar to the frosted glass effect seen in iOS7?

Creating an overlapping div with a frosted glass effect typically requires using an image background (like ). I am interested in having a floating div (position:fixed) that can apply a frosted glass effect over any content below it, whether it be an image ...

When working with Next.js Components, be aware that using a return statement in a forbidden context can lead to

Whenever I try to add a new component to my Next.js project, I encounter an error that displays the following: `./components/GridMember.js Error: error: Return statement is not allowed here | 6 | return (test); | ^^^^^^^^^^^^^^^^^^^^^^^^^ Caused ...

Issue with material-ui-dropzone, the DropzoneAreaBase component not displaying the preview of the uploaded files

Has anyone encountered issues with the DropzoneAreaBase component from the material-ui-dropzone library? I am having trouble getting it to display added file previews. Any insights into why this might be happening? <DropzoneAreaBase onAdd={(fileObjs) ...

I am attempting to gather outcomes from two separate arrays

I have a challenge of filtering the first array based on the text in the second array. I am trying to figure out how to update the count filter in the first array using values from the second array. First Array: var firstArray =[{text:"India",co ...

Establishing a connection between ReactJS and a database

How can I efficiently retrieve data from a one-field form in React JS on the front end and insert it into a MySQL database using Express on the backend? Can you outline the step-by-step process for me? ...

Expanding the blank area on the right margin of the page

Recently, I took a responsive website template and converted it into an ASP.NET MVC app. However, I've encountered some peculiar behavior when resizing the browser window. As the width of the window decreases below 986 pixels, a mysterious white "spac ...

After the upgrade to Material UI 4, I encountered an issue with the withStyles feature that is causing errors

After updating to MUI v4.0.2 from v3.9.x, I encountered this error: The function returned by connect requires a component to be passed. However, {"propTypes":{},"displayName":"WithStyles(MyComponent)","options":{"defaultTheme":{"breakpoints":{"keys":["x ...

Serve Webpack bundle on various routes - Express Way

I recently completed a web application using an Express backend and React frontend. Upon sending a request to the Express server, it undergoes a process where the URL is checked against the backend routes. If there isn't a match, the React bundle gen ...

Struggling with React Js and need some assistance?

I'm completely new to React Js and encountering issues with my code. Here's what I have: Here is the content of my script file named Main.jsx. This file gets compiled by React, and the output is stored in main.js under the 'dist' folde ...

Break up the JavaScript code into modules to avoid duplicating blocks of code detected by

There is a block of code that SONAR has identified as duplicate. I am looking for guidance on how to address this issue. import fields from '../../utils/utils'; dispatch( fields.change([ { id: 'userData', value: ...

Updating state before and after making an API request

I have implemented an asynchronous function with prevState in my code. The purpose of using prevState is twofold: 1) updating a deeply nested object and 2) sending data to an API based on the current state. Asynchronous programming is utilized for the API ...

Guide to personalizing checkbox design using react-bootstrap

I am working with react-bootstrap and attempting to style a custom checkbox, as it appears possible but is not working. I have followed the documentation provided here. Here is the code snippet: import * as React from "react"; import { t as typy } from & ...

Utilizing a forwardRef component in TypeScript to handle child elements

Working with @types/react version 16.8.2 and TypeScript version 3.3.1. This forward refs example was taken directly from the React documentation with added type parameters: const FancyButton = React.forwardRef<HTMLButtonElement>((props, ref) => ...

Which is the better choice in Material-UI v5: using the css prop or the sx prop?

Both of these props, in my opinion, utilize emotions at their core and appear to serve a similar purpose. Personally, I opt for the css prop due to my preference for template tags and actual CSS over JavaScript-style names for CSS properties. Is there an ...

Is there a way to insert images from a webpage in NextJs?

I am encountering issues while trying to incorporate the Coloplast logo into my project using this URL(https://www.coloplast.com/Global/1_Corporate_website/Press/Pics/CPlogo_Gray_RGB_300.png). **Unfortunately, I keep getting this error message ** Server ...

Using jquery to refresh several backgrounds at once

While I have some knowledge of CSS and various JavaScript libraries, I've encountered difficulty in integrating multiple backgrounds into the code that I found on this link: http://codepen.io/quasimondo/pen/lDdrF. My goal was to overlay a transparent ...

What is the best way to change the size of a QR code

My current HTML code: <input id="text" type="text"/> <div id="qrcode"></div> Previous version of JAVASCRIPT code: var qrcode = new QRCode("qrcode"); $("#text").on("keyup", function () { qrcode.makeCode($(this).val()); }).keyup().focus ...