Javascript ReactJS:当标签是“材质ui自动完成”中的长文本时,如何修剪标签
我正在使用材料界面自动完成。。。当标签是长文本时,我想修剪它Javascript ReactJS:当标签是“材质ui自动完成”中的长文本时,如何修剪标签,javascript,reactjs,ecmascript-6,material-ui,frontend,Javascript,Reactjs,Ecmascript 6,Material Ui,Frontend,我正在使用材料界面自动完成。。。当标签是长文本时,我想修剪它 <Autocomplete id="combo-box-demo" options={top100Films} getOptionLabel={(option) => option.title} style={{ width: 300 }} renderInput={(params) => <TextField
<Autocomplete
id="combo-box-demo"
options={top100Films}
getOptionLabel={(option) => option.title}
style={{ width: 300 }}
renderInput={(params) =>
<TextField {...params} label="This is very long
labellllllllllllllllllllllllllllllllllllllllllll" variant="outlined" />}
/>
您可以使用函数substring()
该方法返回开始索引和结束索引之间的字符串部分,或返回字符串的结尾
const str = 'labelllllllllllll';
console.log(str.substring(0, 6));
// expected output: "label"
console.log(str.substring(2));
// expected output: "bel"
然后在文本字段中,您可以使用:
label={str.substring(0, 6)}
对于类.MuiInputLabel outlined.MuiInputLabel shrink
,可以在css中使用文本溢出:省略号。。工作示例: