更改文本时如何保持按钮大小?

时间:2019-05-15 10:08:21

标签: reactjs semantic-ui semantic-ui-react

我有一个切换按钮,每次单击时其文字必须更改:

<Button onClick={this.changeView}>{currentView === 'a' ? 'First' : 'Second Chance'}
                </Button>

changeView = (event, data) => {
    let nextView = (this.state.currentView === 'a') ? 'b' : 'a';
    this.setState({ currentView: nextView });
}

它可以工作,但是由于第二个标签比第一个标签大得多,因此按钮会不断调整大小。 我希望它保持固定的长度,这将是第二个标签的大小...可以吗?

1 个答案:

答案 0 :(得分:0)

为Button设置width属性。

2个选项:内联样式或CSS className。我建议使用className选项。

内联样式选项:

<Button style={{width: '<YOUR_WIDTH>px'}} onClick={this.changeView}>{currentView === 'a' ? 'First' : 'Second Chance'}
                </Button>

changeView = (event, data) => {
    let nextView = (this.state.currentView === 'a') ? 'b' : 'a';
    this.setState({ currentView: nextView });
}