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

The useStyles function does not automatically update properties in response to changes in variables

I have encountered an issue where the style of a component is not changing based on a boolean state change until I refresh the page. Here's what I'm doing: Within my parent App component, I have the following code: import React from "react"; imp ...

How can I modify the color of JavaFX text using CSS?

Looking to jazz up my JavaFX application with some custom CSS styling. Managed to link a stylesheet to my app using the following code: //Java code FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("/path/to/fxml")); Scene sce ...

Tips for integrating the C++ icon into a ReactJs project

For a ReactJs project, I needed to include icons of different Languages and Tools. When adding a Python icon, I used: <ListItem> <ListItemIcon className={classes.icon}> <span className="iconify" data-icon= ...

Tips on modifying the row height of a material-ui table component

Currently, I'm utilizing the Table component from material-ui within my React JS project. Despite including height:10px in the style prop, it seems like the individual row heights aren't adjusting accordingly. I would greatly appreciate any tips ...

Ensure the Next/Image component fits neatly inside a div without distorting its aspect ratio, and keep the

I've been attempting to style a NextJS image in a way that it has rounded corners, expands to fit its container div (which is blue in the image), and maintains its aspect ratio (only known at runtime). However, what I currently have is not working as ...

When using the setTimeout function to update the state, React useContext appears to be ineffective

As a newcomer to React, I have a question about refreshing the score in my card game within a forEach loop using setTimeout. While the state appears to update correctly, the DOM (Component overarching) does not reflect these changes. export function Refill ...

What steps should I follow to ensure that this table can be sorted efficiently?

I could use some help with this problem. I am new to ReactJS and struggling to implement table sorting based on the clicked column. Do I need to add a class for this? Any assistance would be greatly appreciated. function CreateGradeTable(props) { r ...

When using ReactJS, the table sorting feature may not work properly when the text in the table

While constructing a ReactJS checkbox table, I came across an issue where sorting would not function properly when the cell includes hyperlinks. Is there a method to attach data attributes to the cell wrapper for sorting purposes instead of just relying on ...

Using Jinja2/Python, is it possible to alter the parent's style depending on the child's value?

Initially, I found that the :has() combinator accomplishes my desired outcome. In my HTML, I have a table structured like this: <table class="table"> {% for dict_item in data | sort(attribute='name') %} <tr class=" ...

What is the best way to trigger useEffect when the state being used within the effect is expected to change during the course of the effect's

Exploring the following code snippet: const [list, setList] = useState([]); const [curPage, setCurPage] = useState(0); const fetchItem = useCallback(async ()=>{ const data = await callAPI(); // data is an object setList(prev => [...prev, data]) ...

I'm curious if there is a method in Next.js to dynamically replace all `<a>` tags within nested components in order to prevent full page refreshes

Our client requires the use of a React component library that offers various layout components such as Header/Footer elements and Navigation menus. However, only the href string value can be passed for navigation items, preventing any manipulation during r ...

Unable to deactivate button within component using setState is ineffective

Once the button within the RecipeListItem component is clicked and the handleFavorites function has been triggered, I want the button to become DISABLED. What am I missing in my logic? Because this code isn't functioning as expected... Child compone ...

What is the best way to make a gradient fill and rounded border with CSS?

I am interested in creating a gradient and rounded border similar to the top bar on Instagram. Although I know how to create a rounded and solid border, this one utilizes a gradient. It appears that Instagram uses a canvas, but I am wondering if it can b ...

Create a dynamic animation using Angular to smoothly move a div element across the

I currently have a div with the following content: <div ng-style="{'left': PageMap.ColumnWrap.OverviewPanelLeft + 'px'}"></div> Whenever I press the right key, an event is triggered to change the PageMap.ColumnWrap.Overvie ...

Encountering an error while using npx create-react-app command

After attempting to reinstall yarn and npm, I also tried running npm cache clean and yarn cache clean. The issue persists when trying to run npx create-react-app my-app While installing react, react-dom, and react-scripts with cra-template... yarn add v1 ...

Contrasting local storage and session storage

After implementing user authentication using the passport local strategy with session storage, I have a question. Each time a user logs in, their session is stored both in the database and browser. In my frontend, would it be appropriate to use the user. ...

What is the best method for eliminating the gap between div elements in CSS?

I am in the process of creating a simple website to brush up on my basic HTML and CSS skills. Utilizing Dreamweaver CS6, I aim to master every aspect of web design the correct way. While exploring how to position div elements, specifically using margins fo ...

Mobile devices offer a seamless vertical scrolling experience

Here is the HTML structure I am working with: <div> <a>..</a> <i>..</i> <a>..</a> <i>..</i> <a>..</a> <i>..</i> </div> On larger screens, all elements are dis ...

Encountering a problem with library functions while attempting to import a module

At the moment, I am utilizing NodeJS. I have been attempting to import a module into a component function and everything appears to be running smoothly. However, I keep encountering this error in the server console: error - src\modules\accountFu ...

Guide on how to retrieve a clicked element

When I click on the <ul> inside this div, I want to retrieve the id="nm". <div id="suggestionTags"> <ul> <li class="nm">Commonwealth</li> <span class="cty"> x GB</span> <li class="hse">C ...