Steps to modify the background color of an IconButton upon clicking in Material UI

After clicking on the IconButton, the background color changes to an oval shape. I now need to modify the background color when it is clicked.

CSS

The CSS code for the IconButton changes the background color upon hover. I require a similar effect for the onClick event.

const customStyles = makeStyles(theme => ({
    paper: {
        backgroundColor: theme.palette.accent[100],
      },
      iconButton: {
        padding: "10px",
        margin: "0 5px 1px 0",
        "&:hover, &.Mui-focusVisible, &:active": {
          backgroundColor: theme.palette.accent[100],
        },
        "&$buttonDisabled": {
          color: theme.palette.accent[100],
        },
      },
    })

Material UI

<Paper className={classes.paper}>
    <Box display={"flex"} height={theme.spacing(2.3)}>
        <IconButton
         color={"inherit"}
         size={"small"}
         className={classes.iconButton}
         onClick={() => {
             history.push("/a")
         }}>
            <img src={"/static/images//a.svg"} />
            <Box pl={1} mt={"-4px"} maxWidth={theme.spacing(10)}>
                <Typography variant={"subtitle1"} component="p">
                    {" Hello"}
                </Typography>
            </Box>
        </IconButton>
    </Box>
</Paper>

Answer №1

After researching, I discovered a clever method to create an onclick effect in CSS mentioned in this helpful post: Can I have an onclick effect in CSS?. The suggested approach involves utilizing a checkbox trick, though alternative methods are also detailed on the linked page.

If you have more flexibility, implementing JavaScript is another viable option.

Wishing you a wonderful day!

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

Is there a method to incorporate lists of varying types in a single v-for loop without causing any issues with type validations?

My current component is designed to display two different datasets, each with their own unique nature of data: state.articleTypeList: string[] state.renderPriceClassNameList: {[key: string]: string[]} To render both datasets within a single v-for componen ...

Is it possible to verify if the @Output is correctly wired up within an Angular component?

When working with Angular and TypeScript, it is possible to access the bound @Input values in the ngOnInit method of a component. However, there isn't a straightforward way to check if a particular @Output event binding has been set up on the componen ...

Content within this specific div should move in a marquee fashion

#player #title{ left: 90px; width: 200px; overflow: hidden; } Within this specific div (#Title), the text should scroll like a marquee. The challenge is to achieve this effect using only JavaScript without altering the HTML structure. How can this be acco ...

What strategies should be followed for managing constant types effectively in TypeScript?

enum ENUM_POSITION_TYPE { LEFT = 1, RIGHT = 2 } // type PositionType = 1 | 2 type PositionType = ??? export let a1: PositionType = ENUM_POSITION_TYPE.RIGHT //correct export let a2: PositionType = 1 as const //correct export let a3: PositionType = 3 / ...

Exploring the art of div transitions and animations using React and Tailwind CSS

I successfully implemented the sidebar to appear upon clicking the hamburger icon with a transition. However, I am now facing the challenge of triggering the transition when the close button is clicked instead. I have attempted using conditional operations ...

Remove an item from the DOM instantly with React

Having trouble synchronously removing a child from the container? Here is a simplified code snippet demonstrating the current solution using the useState hook. type ChildProps = { index: number; id: string; remove: (index: number) => void; }; fun ...

How can jQuery be used to display the size and type of linked files in title attributes?

For instance: Prior to <a target="_blank" href="http://www.adobe.com/devnet/acrobat/pdfs/reader_overview.pdf"> Adobe Reader JavaScript specification </a> As the file is in PDF format, the title should read title="PDF, 93KB, opens in a new ...

Assessing the validity of a boolean condition as either true or false while iterating through a for loop

I am facing an issue that involves converting a boolean value to true or false if a string contains the word "unlimited". Additionally, I am adding a subscription to a set of values and need to use *NgIf to control page rendering based on this boolean. &l ...

The React state persists to reset back to its initial state consistently

Currently, I am developing a mobile signature feature for my website which involves three components: Form.js (the parent component using Formik for the form), Admin.js (a child of Form), and Signature.js (a child of Admin). Upon entering the Admin sectio ...

Extracting Text from a Span Element Using XPath in Selenium

Here is the HTML code snippet: <div class="a-row a-spacing-small a-size-small"> <div class="a-row"> <a class="a-link-normal a-declarative g-visible-js reviewStarsPopoverLink" href="#" data-action="a-popover" data-a-popover="{"closeButton":" ...

Display the latest item using React

I've encountered a problem with displaying the last message in my pet chat application. Currently, I have to manually scroll to the bottom every time I open the chat in order to see the latest message. This scrolling behavior is not very user-friendly ...

Troubleshooting a CSS problem on a table filled with images - See attached screenshots for

I've been working on a project involving my phpmyadmin database generating a series of 6 images on my website. I've placed them in a table, but now I'm facing some challenges - even though it seemed simple at first! The goal is to display t ...

The noUnusedLocal rule in the Typescript tsconfig is not being followed as expected

I am currently working on a project that utilizes typescript 3.6.3. Within my main directory, I have a tsconfig.json file with the setting noUnusedLocals: true: { "compilerOptions": { "noUnusedLocals": true, "noUnusedParameters": true, }, ...

The data type 'Observable<any>' cannot be assigned to the type 'StoresSummaryResults'. The property 'Data' is not present in the 'Observable<any>' type

As a newcomer to using the Observable with Angular 2, I am facing an issue where my structure is not receiving the results despite being able to validate the response from my REST API. Below is the data class in Typescript that I have: import { RESTResul ...

Adjust the checkmark color of MUI Checkbox

When using Material UI's MUI library for React, I encountered an issue with the checkbox checkmark color. By default, the checkmark takes on the background color of the container element, which is great for light backgrounds but not ideal for dark one ...

Issue with Angular MatSelect Losing Selected Value in Reactive Form Upon Submission

Working on an Angular project with a reactive form that features a <mat-select> for selecting cities. Although the dropdown functions properly in displaying and allowing city selection, there's a problem when attempting to submit the form: the s ...

Ways to troubleshoot errors that arise while building Next.js with Mui framework

After running npm install @mui/material @emotion/react @emotion/server, I encountered an error while trying to build my Next.js app during linting and type checking. info - Linting and checking validity of types ...Failed to compile. ./node_modules/@mui/ ...

What is the method for specifying a null value in Typescript?

I'm curious if this code snippet is accurate, or if there's a better way to define it. Is there an alternative to using error!? I'm unsure of its meaning and would appreciate clarification. ...

Transitioning between fragments or activities on Android using a hamburger arrow animation

I have a situation where I need to transition from activity A to a new Activity B (or potentially a fragment). On A, there is a hamburger icon and on B, there should be a left arrow icon. However, when I create B from A, the left arrow icon appears without ...

Tips for utilizing the CSS API of the Grid Component

I am currently attempting to utilize the Grid component, however I am struggling to understand how to use the CSS API. The documentation is not providing me with the guidance I need. It's really confusing for me... Can anybody offer some assistance? ...