【发布时间】:2021-04-17 11:41:02
【问题描述】:
我试图通过添加 hidden 属性来隐藏 Material-UI Button 组件,但似乎该属性被忽略了。我在其他 Material-UI 组件(例如 Typography、Grid 和 Box)上使用了 hidden 属性,并且效果很好。下面是我的代码的简化 sn-p。 Click here to try it out on CodeSandbox.
<Typography hidden={loading}>
Works. This text is not displayed when `loading` is truthy.
</Typography>
<Button hidden={loading}>
Doesn't work. This Button is still there!
</Button >
【问题讨论】:
-
material-ui.com/api/button 它没有隐藏道具。我建议条件渲染。
-
@MindaugasNakrosis material-ui.com/api/typography 没有
hidden属性。虽然我同意您使用条件渲染的建议,但了解这两个组件的行为为何不同仍然很有趣。 -
两个组件都从
HTMLAttributes继承了它们的hidden属性,以及一堆其他标准属性,如id、style、className等。我不应该使用这些属性?
标签: javascript html reactjs material-ui