简体   繁体   English

当文本字段没有值时,将 MUI TextField label 保持在顶部

[英]Keep MUI TextField label on top when text field has no value

So this should be simple but I don't see a clear answer.所以这应该很简单,但我没有看到明确的答案。 The labels I have looks like this:我的标签是这样的:

在此处输入图像描述 . .

As you can see the bottom 2 fields have the label on top since they have a default value whereas the top on "ML Features" does not and the label moves to the middle of the TextField .如您所见,底部的 2 个字段在顶部有 label,因为它们具有默认值,而“ML 功能”的顶部没有,并且 label 移动到TextField的中间。

The code looks like this:代码如下所示:

<TextField
    label="ML Features" // or any other field
    ...
   >
</TextField>

How can I keep the label always on the top?我怎样才能让 label 一直在最前面?

You can set shrink to true in InputLabelProps .您可以在InputLabelProps中将shrink设置为true For more reference, see InputLabel API here .如需更多参考,请参阅此处的InputLabel API。

<TextField label="ML Features" InputLabelProps={{ shrink: true }} />

you need to add focused so that it will be in top without any value您需要添加重点,以便它在没有任何价值的情况下排在首位

暂无
暂无

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

相关问题 在顶部材质 UI 上垂直对齐文本<Textfield /> - Align Text Vertically on top material UI <Textfield /> 当以编程方式设置 TextField 的值时,Material UI TextField label 不会向上移动 - Material UI TextField label does not move up when the value for TextField is set porgramatically 将“标签”道具传递给 Formik<field /> 与 Material UI 一起使用时<textfield /> - Passing a 'label' prop into Formik <Field /> when using alongside Material UI <TextField /> 在 TextField Material UI 中调整标签 - Adjust Label in TextField Material UI Material-UI TextField 变体 label 穿透值 - Material-UI TextField variant label striking through value React Material-UI TextField 与预加载值不会移动 label (标签与 TextField 内容重叠) - React Material-UI TextField with preloaded value does not move the label (label overlaps with the TextField content) 如何让 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? Label position 用于 Material-UI 文本字段,收缩时带有图标装饰 - Label position for Material-UI text field with icon adornment when shrink false Material UI:如何提取文本字段的值 - Material UI : How to extract the value of the text field 清除反应中的材质 UI 文本字段值 - clear the material UI text field Value in react
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM