【问题标题】:How to get MuiList to auto scroll如何让 MuiList 自动滚动
【发布时间】:2020-07-01 19:48:27
【问题描述】:

我正在创建一个聊天窗口组件,并且我正在使用 Material UI。我原以为在列表周围的 MuiList 或 MuiBox 上放置一个高度或最大高度会使其在每次发送新消息时自动滚动,但它似乎并没有奏效。我对此感到有些困惑,任何方向都会很棒。下面是我的代码。我正在使用 Styled Components 进行样式设置。

export const ChatWindow = styled(MuiBox)`
  && {
    position: absolute;
    right: 0px;
    bottom: 0px;
    box-shadow: 0px 7px 40px 2px rgba(148, 149, 150, 0.3);
    background: ${Color.white};
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: 0.3s ease-in-out;
    border-radius: 5px;
    width: ${props => (props.fullscreen ? '100%' : `${450}px`)};
    height: ${props => (props.fullscreen ? '100%' : `${584}px`)};
    /* max-height: 550px; */
  }
`;

export const ChatWindowHeader = styled(MuiBox)`
  && {
    background: ${Color.primary};
    min-height: 40px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    color: white;
    padding: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
`;

export const MessageList = styled(MuiList)`
  && {
    height: 80%;
    overflow-y: auto;
  }
`;

export const MessageListItem = styled(MuiListItem)`
  && {
    margin: auto;
    padding-bottom: 10px;
    display: flex;
  }
`;

export const MessageReceivedBubble = styled(MuiBox)`
  && {
    padding: 8px 16px;
    margin-bottom: 10px;
    border-radius: 10px 10px 10px 2px;
    font-weight: 300;
    font-size: 14px;
    word-wrap: break-word;
  }
`;

export const MessageSentBubble = styled(MuiBox)`
  && {
    padding: 8px 16px;
    margin-bottom: 10px;
    border-radius: 10px 10px 2px 10px;
    font-weight: 300;
    font-size: 14px;
    word-wrap: break-word;
  }
`;

【问题讨论】:

    标签: javascript css reactjs material-ui styled-components


    【解决方案1】:

    通过使用 Diego Lara 对堆栈溢出问题的回答,我能够完成我想要的事情:How to scroll to bottom in react?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      相关资源
      最近更新 更多