小编And*_*rew的帖子

单击时更改样式



我有 ReactJS 项目,我想在单击期间更改按钮的颜色。我知道它是一个Ripple API,但使用它非常难以理解。有人可以建议我怎么做吗?

我尝试创建两个元素 - 父元素和子元素 - 并在单击时将子元素的背景更改为透明。不幸的是,如果按钮处于活动状态并且它不起作用,我也有“类”对象负责更改类。我的代码如下:

import React, { Component } from 'react';
import { withStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import PropTypes from 'prop-types';
import styles from './MydButton.style';

class MyButton extends Component {
  constructor(props) {
    super(props);
    this.state = {
      isClicked: false
    };
  }

  handleClick = () => {
    this.setState({ isClicked: !this.state.isClicked });
  }

  render() {
    const {
      classes,
      children,
      color,
      disabled,
      className,
      onClick,
      type,
      border,
      ...props
    } = this.props;

    const myClass = this.state.isClicked ? …
Run Code Online (Sandbox Code Playgroud)

css frontend button reactjs material-ui

3
推荐指数
1
解决办法
5456
查看次数

标签 统计

button ×1

css ×1

frontend ×1

material-ui ×1

reactjs ×1