Removing focus in Meterial-UI [Select] component when clicked outside: Techniques and solutions

Looking to create a simple multiple select feature with Material-UI's Select component. One issue I have encountered is that when deselecting an option or clicking outside the dropdown, the label remains focused until clicked on again or another component is focused.

Any suggestions on how to address this?

My goal is to remove focus from the label/select component once the dropdown menu disappears.

https://i.sstatic.net/DXpwW.png

Check out the component here: https://material-ui.com/demos/selects/

Answer №1

Although this may not align exactly with what you are seeking, there is a significant reason behind the focused nature of those fields (even if they may seem overly outlined), and that reason is a11y.


By maintaining focus on the <select> element, users are able to easily reselect their chosen value, even using only the keyboard. This functionality covers instances where a user accidentally selects the wrong option and needs to quickly return to the select list, or, as in your case, select again effortlessly if the list was closed before the intended selection.

An important point to note is that the MD's <select> focus behavior remains consistent with that of native selects:

https://i.sstatic.net/VQZ8O.png https://i.sstatic.net/ijbDG.png

In general, this behavior should not be altered without a critical reason. See outlinenone.com for more information.

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

Convert a relative path to an absolute path using the file:// protocol

When I scrape a website with similar html content, I come across the following code: <a href="/pages/1></a> In addition to this, I have access to the window.location object which contains: origin:"http://www.example.org" This allows me to ...

In JavaScript, whenever there is an error for each variable A in B, it means that B is an array of arrays

I stumbled upon this code snippet: var B = []; var data = []; data.push("string"); // .... B.push(data); // ... for each (var A in B){ console.log(B); console.log(A); let obj = A[0].split("|", 3); console.log(obj[0]); ...

The React Bootstrap modal is encountering an error, specifically a TypeError where it is unable to read properties of undefined, specifically the 'classList'

Every time I try to open a modal, an error pops up saying "TypeError: Cannot read properties of undefined (reading 'classList')." I'm unsure about how to resolve this issue. Here is the code for the specific modal and the button that trigger ...

Component encounters issue with undefined props being passed

Encountering an issue where dummy data is not being passed to a component, resulting in undefined props. Even console.log() statements within the same page are not functioning properly. Can anyone identify what might be going wrong here? import AllPosts fr ...

Utilize socket communication with node.js to monitor and identify user

I'm attempting to find a method to unsubscribe from a Redis channel when the user navigates to another page within our website. I have attempted to detect a disconnect socket event when the user clicks on a link, but unfortunately, the event is never ...

What is the best way to create an oval-shaped background for a div element?

Can someone help me achieve an oval shape for my index page div? I tried using border-radius but the edges are too round for my liking. I am looking for a more specific result See the CSS code below for reference <div class="home-page"></div> ...

Page jumping vertically in Chrome upon reload, with Firefox and Internet Explorer functioning properly

Utilizing this jQuery script, I am able to center a website vertically within the browser window if it exceeds the height of the outer wrapper-div, which has fixed dimensions. $( document ).ready(function() { centerPage(); )}; // center page vertic ...

Loading a page via AJAX without triggering a reload of the entire website

I am experimenting with loading content from a different page using AJAX. The website I am currently testing on is dev.dog-company.com. Here's the code snippet that I have been working on: $('a[rel="load"]').click(function(){ //var sit ...

Utilizing a functional component to incorporate a "load more" button in ReactJS

Hey everyone, I've come across this ReactJS code that I need some help with: function DisplaySolutions({solutions}) { const topSolutions = solutions.slice(0, 4); const remainingSolutions = solutions.slice(4); const [isD ...

A completely css-based interpretation of google images

I am in the process of trying to recreate the layout found in Google Photos and stumbled upon this intriguing page https://github.com/xieranmaya/blog/issues/6 . I am particularly interested in the final result of the project, which can be viewed here: . U ...

Is it possible to create a component in React without using JSX?

Is it possible to create a React component without using JSX? I'm trying to render a header element with nested h1 and h2 tags, but only the paragraph tag is showing up. Why is only the React element rendering and not the rest? I referred to a Codepe ...

"Error encountered when attempting to execute the delete() function in Django

Having some trouble with my delete function. It successfully deletes the object but does not redirect to window.location as expected. Instead, I'm getting an error message: DoesNotExist at /api/personnel/delete/ Resource matching query does not exist ...

The surprising outcomes of using Map and If statements together

I am striving to accomplish the following results: If the name entered already exists in the "persons" array, an alert should be displayed saying "Name already exist". The code seems to have a flaw as I am consistently receiving the alert message. I susp ...

Is it possible to utilize the WebGL camera in order to create dynamic transitions between various polygons?

Recently, a friend suggested exploring WebGL as an alternative to CSS transitions. I have a collection of polygons that form a 2D board game. https://i.sstatic.net/D0dnc.png In essence, the application moves the player space by space starting at the top ...

Saving an Axios request array to a Laravel controller in Laravel using VueJs

I am working on a laravel 5.7 application that utilizes VueJS 2.0 for the front end. The issue I am facing involves two tables with a many-to-many relationship: 'commandes' and 'produits'. When trying to pass data into my 'commande ...

What is the reason for React's progressive bar displaying the complete percentage instead of progressively increasing it?

I am attempting to update the percentage state by adjusting setTimeout during the page load process, causing the filler to gradually fill the progressiveBar up to 100%. const { React, ReactDOM } = window const { useEffect, useState, Fragment } = React c ...

HTML and JavaScript code to desaturate or grayscale image rollovers without the need for additional image duplicates or sprites

Is there a way to achieve grayscale to color image rollover effects without duplicating images or using sprites? I'm looking for an alternative technique that can accomplish this. Any suggestions on how to implement it? ...

Oops! React js is throwing a TypeError because it cannot read the property 'payload' of something that is undefined

Encountered an error while trying to submit the form, the error details are as follows: TypeError: Cannot read property 'payload' of undefined If you need more information, please let me know reducer/index.js export default (posts =[], acti ...

One way to retrieve this attribute with jQuery is by specifying the div element in question

I am facing an issue with a div that is defined within a particular context. Let's consider the div as shown in the code snippet below: <td itemid='desired number'> <div>div 1</div> <div class="action">div 2</ ...

Vue: the parent template does not permit the use of v-for directives

Upon creating a simple post list component, I encountered an error when trying to utilize the v-for directive: "eslint-eslint: the template root disallows v-for directives" How can I go about iterating through and displaying each post? To pass data from ...