reactjs - 什么是应用栏与工具栏?

标签 reactjs material-ui material-components

所有的material-ui示例都在Appbar中显示了Toolbar。为什么不只是应用栏呢?两者有什么区别?

https://material.io/design/components/ 没有有工具栏组件,只有“应用栏:顶部”。

https://material.io/develop/web/components/toolbar/说“现有的 MDCToolbar 组件和样式将在未来的版本中删除”

那么material-ui工具栏最终会消失吗?

最佳答案

我正在查看每个组件生成的默认 CSS 属性。 工具栏的主要目的是通过内联显示来显示其子项(元素彼此相邻放置),这是应用栏所不具备的。 AppBar 组件使用 display: flexflex-direction: column,这意味着直接后代堆叠在一起。另一方面,工具栏也使用display: flex,但没有设置flex-direction,这意味着它使用其默认值:< em>行。也就是说,Button 组件使用 display: inline-block。这就是为什么元素在工具栏组件内彼此相邻放置的原因。

例如,我们有一个 Appbar 和一个 Toolbar,其中有两个 Button 作为子项:

<AppBar>
    <Toolbar>
        <Button variant="outlined" color="inherit" >
            Button 1
        </Button>
        <Button variant="outlined" color="inherit">
            Button 2
        </Button>
    </Toolbar>
</AppBar>

这段代码的结果是:

here

但是,如果我们删除工具栏并将按钮直接放在AppBar组件下:

<AppBar>
    <Button variant="outlined" color="inherit" >
        Button 1
    </Button>
    <Button variant="outlined" color="inherit">
        Button 2
    </Button>
</AppBar>

结果将非常不同,如下所示,因为现在按钮是 AppBar 组件的直接后代,因此它们将堆叠在彼此的顶部。

here

如您所见,AppBarToolbar 具有不同的用途。这就是为什么我认为工具栏永远不会消失。

关于reactjs - 什么是应用栏与工具栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52653103/

相关文章:

javascript - 如何在我的 react 代码中强制更新我的组件以将深色主题切换为浅色主题

javascript - Material UI 中的 sx Prop 和 makeStyles 函数之间是否存在性能差异?

android - 在 android 中膨胀类 android.support.design.widget.CollapsingToolbarLayout 时出错

reactjs - 在 react 脚本测试中禁用颜色输出

reactjs - reactjs nextjs 中的 "Error: zoid destroyed all components↵"错误

javascript - ReactJS 将状态从父级传递给子级

android - 将边距设置为抽屉导航中的菜单项,但不设置标题部分

javascript - 为什么这个组件根本不显示? react 日期选择器

reactjs - 如何将当前页码发送到分页中的 onChange 到 Material ui?

android - 应用程序 :cornerRadius doesn't work for MaterialButton