Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用材质ui';在输入旁边创建标签;s TextField和getInputProps_Javascript_Reactjs_Material Ui_Downshift - Fatal编程技术网

Javascript 使用材质ui';在输入旁边创建标签;s TextField和getInputProps

Javascript 使用材质ui';在输入旁边创建标签;s TextField和getInputProps,javascript,reactjs,material-ui,downshift,Javascript,Reactjs,Material Ui,Downshift,我正在使用材质ui为具有的typeahead选择器类型组件创建输入和标签 我已经看过了,并且得到了: <FormControl fullWidth className={classname}> <TextField fullWidth InputProps={ inputProps } InputLabelProps={ inputLabelProps } /> </FormControl> 我的前任在material ui组件上定义了那些input

我正在使用材质ui为具有的typeahead选择器类型组件创建输入和标签

我已经看过了,并且得到了:

<FormControl fullWidth className={classname}>
    <TextField fullWidth InputProps={ inputProps } InputLabelProps={ inputLabelProps } />
</FormControl>
我的前任在material ui组件上定义了那些inputLabelProps属性,但为了让aria labelledby属性正常工作,我使用了一个单一的

打印出输入和标签道具的内容可提供:

//labelProps
{
    disabled: false,
    error: false,
    htmlFor: "downshift-0-input",
    id: "downshift-0-label",
    required: undefined,
    shrink: false
}

//inputProps
{
    aria-activedecendant: null,
    aria-autocomplete: "list"
    aria-controls: null,
    aria-labelledby: "downshift-0-label",
    autoComplete: "off"
    disabled: false,
    error: false,
    id: "downshift-0-input",
    onBlur: f(event),
    onChange: f(event),
    onKeyDown: f(event),
    startAdornment: [],
    value: ""
}
我的问题是没有标签呈现给DOM。我得到的最接近的是一个带有label属性的div,它包装了输入,但不显示任何内容


p、 我见过,但我认为浮动标签文本已经不存在了?答案中的链接已过时,并且与Proggetters模式不兼容。

以下是评论中提到的略为简化的版本:

演示的
downshift multiple
部分使用了一个标签。我只在我的沙盒中包含了第一个降档演示,但是修改了它,使其以与“多个”演示相同的方式使用标签。标签不属于InputLabelProps,它只是
TextField
的一个属性。在演示中,这有点让人困惑,因为
标签
被指定为传递给
renderInput
的对象的属性,因此它只是作为扩展到
文本字段
的另一个
对象的一部分

如果查看相关代码,您将看到:

    {label && (
      <InputLabel htmlFor={id} ref={this.labelRef} {...InputLabelProps}>
        {label}
      </InputLabel>
    )}
{label&&(
{label}
)}

这里您可以看到,
InputLabelProps
不会影响标签的内容,只是影响其呈现的其他属性,因此您需要将
label
直接作为
TextField

上的属性,我无法正确理解您正在尝试做什么以及出现什么问题。但是,如果他们的文档上有一个文本字段的降档演示,这可能会有所帮助you@VaibhavVishal谢谢,在研究这个特殊问题之前,我已经看到了这一点。我的假设是,
getItemProps
将接受具有label属性的对象……但它不接受。您链接到了TextField演示,但查看了降档演示了吗@RyanCogswell看到了Vaibhav的评论和我的回应。我已经看过两套演示。
    {label && (
      <InputLabel htmlFor={id} ref={this.labelRef} {...InputLabelProps}>
        {label}
      </InputLabel>
    )}