我正在使用material TextField为带有下移的提前选择器组件创建输入和标签。
我看过演示,并得到了这个:
<FormControl fullWidth className={classname}>
<TextField fullWidth InputProps={ inputProps } InputLabelProps={ inputLabelProps } />
</FormControl>我的inputProps等于:
const inputProps = getInputProps({ //passed in by {...downshiftProps} on the parent
onChange, onKeyDown, disabled, error, label, value: inputValue,
startAdornment: selectedItems.map(item => ...)
});
const inputLabelProps = getLabelProps({ //passed in by {...downshiftProps} on the parent
disabled, required, error, disabled, shrink: true, id: inputProps.id
});我的前任在material InputLabel组件上定义了这些InputLabel属性,但是为了使aria属性正常工作,我使用了一个TextField。
打印出输入和标签道具的内容:
//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,它封装输入,但不显示任何内容。
附注:我见过带有标签的资料界面文字栏位,但我不认为FloatingLAbelText已经存在了?答案中的链接已过时,与propGetters模式不兼容。
发布于 2019-02-08 16:48:59
下面是注释中提到的演示的一个稍微简化的版本:
演示的DownshiftMultiple部分使用了一个标签。我只在沙箱中包含了第一个下档演示,但是修改了它以与“多重”演示相同的方式使用标签。标签不属于InputLabelProps,它只是TextField的一个属性。在演示中,这有点让人困惑,因为label被指定为传递给renderInput的对象上的一个属性,因此它只是作为...other对象的一部分结束,即扩散到TextField。
如果您查看TextField的相关代码,您将看到:
{label && (
<InputLabel htmlFor={id} ref={this.labelRef} {...InputLabelProps}>
{label}
</InputLabel>
)}在这里,您可以看到InputLabelProps不会影响标签的content,只会影响其呈现的其他属性,因此您需要将label作为一个属性直接放在TextField上。
https://stackoverflow.com/questions/54571361
复制相似问题