简体   繁体   English

在 Material-ui 中显示 popper 时如何保持对输入字段的关注

[英]How to maintain a focus on Input field when popper is shown in Material-ui

I want to add Accept and Reject buttons on input fields which should appear only when user has focused on input fields.我想在输入字段上添加接受和拒绝按钮,这些按钮仅在用户专注于输入字段时才会出现。 Similar to what we get in Jira.类似于我们在 Jira 中得到的。 在此处输入图像描述

I tried creating a similar component with material-ui.我尝试使用 material-ui 创建一个类似的组件。 Problem is, when I focus in input field, it shows those two buttons but later I am unable to type inside input box.问题是,当我专注于输入字段时,它会显示这两个按钮,但后来我无法在输入框中输入。

Can someone please help me on this?有人可以帮我吗? Below is a code sandbox: https://codesandbox.io/s/material-demo-2hrc4?file=/demo.tsx下面是一个代码沙箱: https://codesandbox.io/s/material-demo-2hrc4?file=/demo.tsx

I was able to do what you wanted using ButtonGroup and conditional rendering (not with popover).我能够使用 ButtonGroup 和条件渲染(而不是弹出框)来做你想做的事情。 My guess is Popover has some z-index maybe because of which we can't enter anything in input, not entirely sure about it.我的猜测是 Popover 有一些 z-index 可能是因为我们无法在输入中输入任何内容,对此并不完全确定。

Check out if it works for you - https://codesandbox.io/s/material-demo-sgpt6?file=/demo.tsx检查它是否适合您 - https://codesandbox.io/s/material-demo-sgpt6?file=/demo.tsx

You forgot to handle state of your input too -您也忘记处理输入的 state -

     <FilledInput
        id="filled-adornment-weight"
        value={value}
        aria-describedby="filled-weight-helper-text"
        inputProps={{
          "aria-label": "weight"
        }}
        onFocus={handleClick}
        onChange={e => setValue(e.target.value)} //set value//
      />

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM