【问题标题】:Material-UI List items scroll on top of AppBarMaterial-UI 列表项在 AppBar 顶部滚动
【发布时间】:2017-02-07 08:03:06
【问题描述】:

我正在使用 React.JS 的 Material-UI (http://material-ui.com) 来制作移动应用程序。列表项在应用栏顶部滚动其内容时遇到问题。其他内容(例如 中的普通段落文本)滚动良好。

这张图显示了滚动内容是如何到达应用栏顶部的:

虽然这些图片显示了一些添加的普通文本(来源如下),但滚动效果很好:

“一些文本”元素在 AppBar 下正确滚动:

“普通”文本(即不是从 ListItem 属性生成的文本)滚动良好:

这是主列表渲染代码:

renderConcerts() {
    return this.props.search.list.map((concert) => {
        return (
            <ListItem key={concert.id}
              primaryText={concert.work}
              secondaryText={concert.composer}
            />
        )
    });
}
renderContent() {
    console.log("renderContent ", this.props.search.classifier);
    const style = {
        margin: 12,
    };
    ....

    return <div id="mypaper">
      <p>Some text1</p>
      <Paper style={style}>
        <p>Some text2</p>
        <div className="content">
          <p>Some text3</p>
          <List>
            {this.renderConcerts()}
          </List>
        </div>
      </Paper>
    </div>;
}

render() {
    console.log("render");
    return (
        <div>
            <ResultHeader/>
            {this.renderContent()}
        </div>
    );
}

ResultHeader 组件:

export const ResultHeader = (props) =>
    <header>
        <AppBar
            title="Results"
            onLeftIconButtonTouchTap={hashHistory.goBack}
            iconElementLeft={<IconButton><ArrowBack /></IconButton>}
        />
    </header>;

样式:

#mypaper {
    width: 100%;
    margin: 0 auto;
    padding: 60px 0;
    overflow: auto; !important;
}
.content {
    margin: 10px;
    padding-bottom: 26pt;
    font-size: 12px;
    text-align: left;
}
.content table, .season tbody {
    border: none;
    font-size: 12px ;
}
.content h2 {
    font-size: x-large;
    color: #19768F;
    margin-top: 10px;
    margin-bottom: 3px;
}
.content h3 {
    font-size: 14px ;
    font-style: normal;
    font-weight: bold;
    margin-top: 10px;
    margin-bottom: 2px;
    color: #313C3F;
}

更新:我尝试将 z-index: 100 添加到 AppBar,但没有任何帮助:

此外,将 List 替换为 Table 提供了几乎相同的行为,即某些内容(标题和选择框)位于 AppBar 上方,而其他内容则在其下方很好地滚动:

【问题讨论】:

  • 你使用哪个版本的material-ui
  • 版本 0.16.7(今天最新)

标签: reactjs material-ui


【解决方案1】:

添加z-index: 100或更多,如果您需要AppBar

【讨论】:

  • 试过了,没用。
  • 好的,尝试将position:relativez-index:1000添加到appbar,同样的,但z-inex:100添加到列表中。
  • 感谢您的提示!尽管没有直接解决问题,但它使我走上了正确的道路!我的问题是 周围的
    标签。它有自己的样式,混淆了 z 索引;在调试 z-indices 时,我可以看到 z-index 为 1000 的区域正在有效地与屏幕上的文本一起滚动。将您的 1000 建议添加到标题中(标题已固定位置),解决了问题,谢谢,
猜你喜欢
  • 1970-01-01
  • 2020-09-15
  • 1970-01-01
  • 2023-02-05
  • 2019-11-29
  • 1970-01-01
  • 2021-02-21
  • 2015-02-17
  • 2020-11-02
相关资源
最近更新 更多