如何让我的按钮触发元素

时间:2019-03-24 10:55:37

标签: html reactjs next.js

我正在使用nextjs编译我的代码和antd框架。我无法设置按钮位置的样式,也希望start按钮触发一组按钮,但是由于某种原因它无法正常工作。下面是我的代码

import React, { Component } from "react";
import Layout from "./Layout";
import { Radio } from "antd";

export default class PositiveAffirmation extends Component {
  state = {
    changeButton: false
  };

  toggleChangeButton = e => {
    this.setState({
      changeButton: e.target.value
    });
  };

  render() {
    const { changeButton } = this.state;
    return (
      <Layout>
        <Radio.Group
          defaultValue="false"
          buttonStyle="solid"
          onChange={this.changeButton}
          className="radio-buttons"
        >
          <Radio.Button value={true}>Start</Radio.Button>
          <Radio.Button value={false}>Stop</Radio.Button>
        </Radio.Group>
        {changeButton && (
          <Button.Group size={size}>
            <Button type="primary">Happy</Button>
            <Button type="primary">Sad</Button>
            <Button type="primary">Fullfiled</Button>
          </Button.Group>
        )}
        <style jsx>{`
          Radio.Button {
            font-size: 100px;
            margin-left: 20px;
            margin-top: 5px;
            margin-bottom: 5px;
            display: flex;
            justify-content: center;
          }
        `}</style>
      </Layout>
    );
  }
}

1 个答案:

答案 0 :(得分:0)

您在将onChange={this.changeButton}更改为onChange={this.toggleChangeButton}时打错电话了