Background and checked styles for radio buttons

Thank you in advance for any assistance you can provide.

I am looking to create a unique radio button design. When the radio button is not checked, I want it to display as a simple white circle. However, once it is checked, I would like it to appear either as a fully filled circle without any margin or outline, or as the standard design shown here: https://i.stack.imgur.com/4P44P.png

Answer №1

To change the color of the inner circle when the radio is checked, you can utilize the radial-gradient() function. Check out the code snippet below for an example:

const useStyles = makeStyles({
  root: {
    "&:hover": {
      backgroundColor: "transparent"
    }
  },
  icon: {
    width: 16,
    height: 16,
    boxShadow: "inset 0 0 0 1px #f4f4f4, inset 0 -1px 0 #f4f4f4",
    borderRadius: "50%",
    backgroundColor: "white",
    "input:hover ~ &": {
      backgroundColor: "#ebf1f5"
    },
    "input:disabled ~ &": {
      boxShadow: "none",
      background: "rgba(206,217,224,.5)"
    }
  },
  checkedIcon: {
    "&:before": {
      boxShadow: "inset 0 0 0 1px #f4f4f4, inset 0 -1px 0 #f4f4f4",
      borderRadius: "50%",
      display: "block",
      width: 16,
      height: 16,
      backgroundImage: "radial-gradient(#b33bdd,#b33bdd 47%,white 47%)",
      content: '""'
    },
  }
});

How to Use

function StyledRadio(props) {
  const classes = useStyles();

  return (
    <Radio
      className={classes.root}
      disableRipple
      color="default"
      checkedIcon={<span className={clsx(classes.icon, classes.checkedIcon)} />}
      icon={<span className={classes.icon} />}
      {...props}
    />
  );
}

...

<FormControlLabel
  value="female"
  control={<StyledRadio />}
  label="Female"
/>

See It in Action

https://codesandbox.io/s/material-ui-styled-radio-1oy20?file=/src/App.js

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

Encountered a java.io.IOException while trying to run react-native on Android, resulting in failure

ERROR: The build process was unsuccessful due to an exception. What caused the issue: The task ':app:transformClassesAndResourcesWithProguardForDebug' execution failed. java.io.IOException: Unable to write [/home/user/Desktop/pratap/react-pr ...

What makes the select box transition in React Material UI stand out?

Why does the select box move up instead of being on the same level as the input field? If you'd like to see my code, click here. For more information, visit the following links: Material-UI Selects Demo https://i.stack.imgur.com/7WtGr.png https://i ...

How to Align the Button Vertically with the TextField in React Material-UI

Utilizing the Material-UI library for React, I have been working on creating a simple form with the following design: https://i.stack.imgur.com/LY3ZN.png My challenge lies in aligning the button with the TextField element. Adjusting the margin-top proper ...

JWT - Effective strategies for enhancing the user experience for a returning logged-in user

My client authentication system involves storing a JWT in `localStorage` once the user is verified. However, I'm not satisfied with the current user experience when a returning user is redirected straight to a new page without warning. window.locatio ...

_dirname does not have a defined scope within ES modules

After updating the package.json file and changing the type to "module", I ran into an issue with a reference error that said "_dirname is not defined in ES module scope". Does anyone have a solution for this problem? import { fileURLToPath } from "u ...

Tips for refreshing the apollo cache

I have been pondering why updating data within the Apollo Client cache seems more challenging compared to similar libraries such as react-query. For instance, when dealing with a query involving pagination (offset and limit) and receiving an array of item ...

Display full lines of nested tree view HTML lists upon hovering using HTML, CSS, Angular, and Bootstrap

I currently have an Angular 4 application where a left-side div displays a tree of items as recursive HTML lists. The issue I am facing is that long texts within this div get cut off by the right border, with a scrollbar appearing instead. What I would lik ...

I am attempting to store the primary array in local storage, but unfortunately, the value is not being saved within the React context API

I attempted to store the main array in local storage and retrieve it as global state, but I am facing an issue where the data is not being saved in the local storage. This file represents my context. import { createContext, useReducer, ReactNode, FC, use ...

Utilizing ObjectId for filtering and calculating overall cost in react.js: a guide

The table should only render once for Wade Ivan, with a total of 180 instead of 680. Seeking assistance to optimize my search class component. Currently, when searching for clients by their names based on ObjectId(clientdetails._id), the rendering returns ...

Choose CSS Option

I need assistance with customizing my dropdown select option - see the example below <select> <option value="volvo" title="NEED THIS BIGGER AND FORMATED" >Volvo</option> <option value="saab">Saab</option> <option val ...

Tips for troubleshooting grid display issues in Internet Explorer

.container{ display: grid; grid-template-columns: minmax(200px, 7fr) 4.4fr; grid-column-gap: 64px; } .item{ background: red; height: 100px; } <div class="container"> <div class='item item-1'></div> <div class=&a ...

Tips for ensuring the pop-up submenu remains visible even when the cursor is outside the parent container and submenu during hover

Is there a way to keep the pop submenu visible even when the mouse hovers outside of its parent container or the submenu? Currently, if the mouse doesn't move straight down from the parent container (B) .account-settings-container to the top arrow of ...

Enhance your React project by incorporating Material-UI card media elements with the ability to add

I am trying to figure out how to create an opaque colored overlay on top of an image using Material-UI. While it is possible with plain HTML, CSS, and JavaScript, I am facing some challenges with Material-UI. <Card> <CardMedia> <im ...

Error: The promise was not caught due to a network issue, resulting in a creation error

I'm trying to use Axios for API communication and I keep encountering this error. Despite researching online and attempting various solutions, I am still unable to resolve the problem. Can someone please assist me? All I want is to be able to click on ...

Using various conditions and operators to display or conceal HTML elements in React applications, particularly in NextJS

I am seeking ways to implement conditional logic in my React/Next.js web app to display different HTML elements. While I have managed to make it work with individual variable conditions, I am encountering difficulties when trying to show the same HTML if m ...

The Bootstrap accordion-toggle incorrectly displays the content symbol (+/-) upon initial page load

Hey there, I've implemented the accordion-toggle code below on my visualforce page. Everything is working smoothly with the collapsible toggle, except for one issue. When loading or refreshing the page for the first time, the collapsed panel shows the ...

What causes an absolutely positioned element to be positioned by its sibling rather than at the top corner of the page?

Can someone explain to me why my absolutely positioned element is displaying after my child_static div? I'm under the impression that absolutely positioned elements are removed from the normal flow. So why isn't child_absolute covering the child_ ...

Animations with absolute positioning not rendering correctly in Safari

I recently created a basic animation that involves setting an element to "position: absolute" in order to translate it. Everything functions perfectly as intended on Chrome, however, when testing it on Safari, the absolute positioning seems to be completel ...

Tips for arranging the Radio button, AutoComplete, and Input Base in a single row

I need assistance with formatting my code to display "Watch Movie Yes I agree" in one line. How can I achieve this layout? Visit this link for the code <Box padding={1}> <FormControl> <RadioGroup> <FormControlL ...

What is the best way to export image paths using require() from a single index.js file in a React Native project?

I am looking for a way to efficiently export all images from a single file named index.js, so that in the future, if I need to change the path of an image, I only have to make changes in one file. For example: export {default as avatar} from './avata ...