When you hover the cursor over it, the material-ui icon button shines with an elliptical background effect

There seems to be a strange issue with the IconButton in @material-ui/core/IconButton that is causing a weird elliptical background to appear when hovering over it.

https://i.stack.imgur.com/Xof8H.png

Even after copying the code directly from the material-ui website, the problem persists.

Interestingly, when I created a new React project and implemented an icon button, the background displayed as the usual circle.

https://i.stack.imgur.com/JzRSw.png

As a newcomer to React, I am unsure of what might be causing this issue. I have not applied any explicit styling to the icon button.

App.js

import React, { Component } from 'react';
import './App.css';
import { IconButton } from '@material-ui/core';
import WorkIcon from '@material-ui/icons/Work';
import CssBaseline from '@material-ui/core/CssBaseline';

class App extends Component {

    render() {
        return (
            <div>
                <CssBaseline />
                <IconButton>
                    <WorkIcon />
                </IconButton>
            </div>
        );
    }
}

export default App;

App.css

.App {
  text-align: center;
}

.App-logo {
  animation: App-logo-spin infinite 20s linear;
  height: 80px;
}

.App-header {
  background-color: #222;
  height: 150px;
  padding: 20px;
  color: white;
}

.App-title {
  font-size: 1.5em;
}

.App-intro {
  font-size: large;
}

@keyframes App-logo-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}


.MuiCardContent-root-29 {
    display: inline-block;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 500px;
    height: 300px;
    margin: auto;
    background-color: #f3f3f3;
}

.login {
    margin-top: 50px;
    margin-left: 50px;
}

.form-group {
    margin-bottom: 35px;
}

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from "react-redux";

import './index.css';
import App from './App';
import store from "./store/index";
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<Provider store={store}>
    <App />
  </Provider>, document.getElementById('root'));
registerServiceWorker();

index.css

body {
    background-color : #484848;
    margin: 0;
    padding: 0;
}
h1 {
    color : #000000;
    text-align : center;
    font-family: "SIMPSON";
}
form {
    width: 300px;
    margin: 50px auto;
}

button {
    background-color: #4CAF50;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    cursor: pointer;
    width: 100%;
    opacity: 0.9;
    width: 100px;
}

.tableHeader {
    background-color: green !important;
}

.header {
    color: green;
    font-weight: bold;
}

.edit {
    height: 30px;
    cursor: pointer;
}

.delete {
    height: 20px;
    cursor: pointer;
    padding-left: 10px;
}

The issue persists throughout my entire project wherever icon buttons are used, not just within this specific file. Interestingly, using the same file in a new project results in no elliptical backgrounds.

EDIT:
The solution provided above works effectively. In my case, setting the width property of the button in index.css to auto also resolved the issue.

Answer №1

Here is the solution I implemented to get rid of the elliptical shape:

<IconButton style={{borderRadius: 0}}>
     <DeleteIcon/>
</IconButton>

After this change, the shape will now be a perfect rectangle upon hovering.

Answer №2

Hey there! If you want to customize the ripple effect on your components, you can easily override the root and child styles. You can change things like border radius or background color to suit your design needs.

const useStyles = makeStyles({
  root: {
    borderRadius: 0, // Customize icon button root style here
    '.MuiTouchRipple-ripple .MuiTouchRipple-child': {  
      borderRadius: 0, // Change ripple style when clicked or touched
      backgroundColor: 'red'
    },
  },
});
<IconButton className={classes.rippleRoot}>
  <WorkIcon />
</IconButton>

If you're using MUI5 with sx props, you can achieve the same customization:

<IconButton
  sx={{
    borderRadius: 0,
    '.MuiTouchRipple-ripple .MuiTouchRipple-child': {
      borderRadius: 0,
      backgroundColor: 'red',
    },
  }}
>
  <WorkIcon />
</IconButton>

Answer №3

After trying a couple of solutions that didn't work for me, I decided to make some adjustments in my App.css file. I added margin and width properties to the parent element, as well as a padding-right property to the child element.

//Styling for buttons at the top

    button.MuiButtonBase-root {
      margin: 10px;
      width: 50px;
    }
    
    button.MuiButtonBase-root span span {
      padding-right: 50px;
    }
    
//Styling for checkboxes

    span.MuiButtonBase-root {
      margin-left: 10px;
      width: 45px;
    }
    
    span.MuiButtonBase-root span {
      padding-right: 10px;
    }

Answer №4

To achieve a circular shade effect on hover, set the height and width to the same value.

<IconButton sx={{height: "50px", width: "50px"}}>
   <WorkIcon />
</IconButton>

Answer №5

Success with this method

<ButtonWithIcon style={{height:"45px",marginTop:"20px"}}>
    <DeleteIcon/>
</ButtonWithIcon>

Answer №6

<CustomButton style={{ borderRadius: 10 }}>
   <OfficeIcon />
</CustomButton>

Answer №7

The issue lies within the CSS for the `button` in your index.css file. It appears to be setting the width of all buttons to 100px, affecting the appearance of the `IconButton` which is implemented as a button tag around the icon.

Fixing the styling of the `IconButton` can be easily resolved by removing the specific `button` CSS. However, the challenge arises when you still want that button style applied to other buttons on your page.

To address this, one approach would be to modify the `index.css` file as follows:

.standard-button {
    background-color: #4CAF50;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    cursor: pointer;
    width: 100%;
    opacity: 0.9;
    width: 100px;
}

Then, replace instances where you are rendering `button` elements with:

<button className="standard-button">

instead of just <button>.

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

Using Material UI to create a list item with a hyperlink

I have set up a menu using Material UI ListItem like this. When I click on the button, it changes the URL to http://localhost:3000/createIdea, but the page doesn't load through the router. If I manually enter the URL in the browser window and press ...

403 You are prohibited from adding more Parents in Google Drive API for React Native

For the past 4 months, my code with react-native-google-drive-api-wrapper was functioning perfectly. However, recently I encountered an issue where I am unable to upload files to any folder in Google Drive using my React Native app. Strangely, I can still ...

Issues arose when attempting to delete the values passed in the context provider using the 'useContext' hook

Try this code in your sandbox: https://codesandbox.io/s/goofy-dhawan-n2kk2?file=/src/components/NavBar.jsx An error occurred: TypeError: Cannot destructure property 'books' of 'Object(...)(...)' as it is undefined. ...

In React Native, I must include individual radio buttons for each item retrieved from the API

When I select a radio button on mobile, all radio buttons get selected instead of just the one clicked. Here is the current behavior: https://i.stack.imgur.com/qRJqV.jpg The expected behavior is to have only the clicked radio button selected, like in thi ...

Issues arising from TypeScript error regarding the absence of a property on an object

Having a STEPS_CONFIG object that contains various steps with different properties, including defaultValues, I encountered an issue while trying to access the defaultValues property from the currentStep object in TypeScript. The error message indicated tha ...

Images are appearing misaligned in certain sections

I have been utilizing the freewall jQuery plugin for organizing images in my website. While the layout of my first section, located at , is functioning properly, I am encountering some issues with its height. The code snippet that I am currently using is a ...

How to selectively disable buttons in a group using React

I am working with an array of data const projectTypeValues = [ { name: 'Hour', value: 'hour'}, { name: 'Day', value: 'day'}, { name: 'Session', value: 'session'}, { name: 'project', valu ...

Experiencing a problem with NextAuth on Vercel, I'm encountering a server error that needs to be resolved

I utilized Google as an authentication provider with NextAuth. I set up all necessary environment variables for both production and development environments. While it functions flawlessly in development mode on my local machine, I encounter the error "Serv ...

Issue with React and JavaScript: Object is displayed on the console briefly before disappearing

I am having an issue with my sign up page where the console log of the two fields disappears after a second. I would appreciate any assistance on this matter. Below is the code for the sign-up form: export default function SignUp() { const [firstNam ...

How can we combine refs in React to work together?

Let's consider this scenario: I need a user to pass a ref to a component, but I also have to access that same ref internally. import React, { useRef, forwardRef } from 'react'; import useId from 'hooks/useId'; interface Props ext ...

Sometimes the Navbar options fail to show up consistently on the Navbar bar

I recently launched my website at campusconnect.cc Unfortunately, I've noticed that when resizing the window, the navbar options are shifting up and down. Can anyone help me identify the issue and provide guidance on how to resolve it? ...

Error: Unable to retrieve the value of a null property | ReactJS |

There are two textboxes and one button designed as material UI components. </p> <TextField id="chatidField" /> <br /> <p> <code>Enter Your Name:</code> <hr /> & ...

When the mouse leaves the area, I would like the iframe within the div to be refreshed

When you hover over the button on the right, a slide panel appears with an iframe. Each time this page loads, it has a different background. I want a new background to load every time there is a new hover, requiring a refresh of the div. How can I achieve ...

"Using html_attr with the attribute "href" does not return any value in the rvest package

My objective is to extract the URLs linked with specific CSS elements on a website using rvest. Despite trying various methods, such as using the html_attr function with the 'href' argument, my current script only returns NA values instead of the ...

Having trouble with React updating the Array object?

I am facing an issue with my application where the selected seats are not greying out as expected when the user clicks on "reserve." It seems like the object array of seats is not updating properly, and the isReserved property is toggling back and forth ...

Exploring how to use React with a select component featuring objects

Hello, I am new to working with React and I have a question regarding the select component of Material UI. Here's my situation: I am creating functionality for creating and editing a User object. This User object has a primary key and some data, incl ...

The dispatch function in redux-thunk is not functioning as expected

Having trouble with thunk and async dispatching? Check out this code snippet: function fetchProvider() { return (dispatch) => { graphqlService(fetchProviderQuery) .then((result) => { dispatch({ type: FETCH_PROVIDER, ...

The value retrieved from the event handler function's state does not match the anticipated value

While debugging, I often minimize this particular component to understand its behavior later on. It was quite challenging to pinpoint the issue due to some intricate logic in place. Nonetheless: import { useContext, useEffect, useState } from "react&q ...

Configuration for secondary dependencies in Tailwind

As per the guidelines outlined in the official documentation, it is recommended to configure Tailwind to scan reusable components for class names when using them across multiple projects: If you’ve created your own set of components styled with Tailwin ...

The login page continues to show an error message for incorrect credentials unless the submit button is clicked

My current project involves a React component called "Signin.js". Within this component, there are login input fields as I am working on creating a login system using Node.js, Express.js, and MySQL. To achieve this, I have set up a post request that sends ...