简体   繁体   English

如何让 Material UI React Textfield 不被文本覆盖,当它具有 position 粘性并且已向上滚动时?

[英]How can I get a Material UI React Textfield to not be overlayed by text, when it has position sticky and it has been scrolled up?

Context:语境:

I have a little chat app with the chat in the middle, and a sticky textfield on the bottom.我有一个小聊天应用程序,中间是聊天,底部是粘性文本字段。 I want to have it when I scroll up the chatlist, that the Textfield will always be on the bottom but over the chat messages (so it has zIndex presedence).我希望在向上滚动聊天列表时拥有它,文本字段将始终位于底部但在聊天消息上方(因此它具有 zIndex 存在)。

The Problem:问题:

But when I scroll now, the TextField from react material ui, is behind the text, almost like it has a opacity or something.但是当我现在滚动时,来自 react material ui 的TextField位于文本后面,几乎就像它有不透明度或其他东西一样。

What have I tried:我尝试了什么:

I have set a high zIndex on the TextField and also Elevation, but nothing changes the problem.我在TextField和 Elevation 上设置了很高的 zIndex,但没有任何改变。

Code snippet of the TextField: TextField 的代码片段:

<div
      style={{
        position: "sticky",
        bottom: 5,
      }}
    >

      <TextField
        placeholder="Your Message.."
        variant="outlined"
        fullWidth
        label="message"
        color="primary"
        value={message}
        onChange={(e) => setMessage(e.target.value)}
        onKeyDown={(e) => (e.keyCode === 13 ? submitMessage() : null)}
      />
    </div>

Here is a screenshot how it looks currently:这是当前的屏幕截图:

在此处输入图像描述

just add background-color to the TextField...只需将背景颜色添加到 TextField ...

  <TextField
    placeholder="Your Message.."
    variant="outlined"
    fullWidth
    label="message"
    color="primary"
    value={"aaaaaaaaaaa"}
    onChange={(e) => setMessage(e.target.value)}
    onKeyDown={(e) => (e.keyCode === 13 ? submitMessage() : null)}
    style={{backgroundColor: "white"}}
  />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何知道元素何时滚动到底部 - How to know when element has been scrolled to the bottom 如何在不移动窗口的情况下使用JavaScript检测div滚动了多远? - How can I use JavaScript to detect how far a div has been scrolled by without the window moving? 如何检测iPhone上滚动的页面比例? - How can I detect what proportion of a page has been scrolled through on iPhone? 我怎样才能弄干这个反应/材料的用户界面代码? - How can i dry up this react/material ui code? 在Facebook经过身份验证后,如何调用函数? 无法调用FB.ui - How can I call a function, when Facebook has been authourized? Not able to call FB.ui 如何检测溢出是否已滚动到底部? - How to detect if an overflow has been scrolled to the bottom? React:如何从 Material-UI TextField 组件中获取值 - React: How to get values from Material-UI TextField components 页面滚动到顶部后,返回到滚动位置 - Return to scroll position after the page has been scrolled to top 在用户滚动特定长度之前如何让部分变得粘滞 - How to get section to become sticky until the user has scrolled a specific length 我如何在React中知道何时添加或删除了子/孙组件? - How can I tell in React when a child/grandchild component has been added or removed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM