- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 Material UI Multiple Select
,您可以 chop 选择后显示的值,而不是转到另一行(通过将 renderValue
设置为 .join
selected
选项,提供“选项 A,选项 B,...”的功能)。这里重要的一点是,当所选选项太长而无法容纳在一行时,它会添加“...”,而不是扩展到下一行。
例如,以下适用于 Multiple Select
:
// Truncated value (I DO want this, for `Autocomplete`)
<Select
labelId="demo-mutiple-name-label"
id="demo-mutiple-name"
multiple
value={personName}
onChange={handleChange}
input={<Input />}
renderValue={selected => selected.join(", ")}
MenuProps={MenuProps}
>
{names.map(name => (
<MenuItem
key={name}
value={name}
style={getStyles(name, personName, theme)}
>
{name}
</MenuItem>
))}
</Select>
// – VERUS –
// chips that wrap to multiple lines (DON'T want this)
<Select
labelId="demo-mutiple-chip-label"
id="demo-mutiple-chip"
multiple
value={personName}
onChange={handleChange}
input={<Input id="select-multiple-chip" />}
renderValue={selected => (
<div className={classes.chips}>
{selected.map(value => (
<Chip key={value} label={value} className={classes.chip} />
))}
</div>
)}
MenuProps={MenuProps}
>
{names.map(name => (
<MenuItem
key={name}
value={name}
style={getStyles(name, personName, theme)}
>
{name}
</MenuItem>
))}
</Select>
Autocomplete
但似乎没有明显的方法。
我尝试了几种方法:
<Autocomplete
multiple
id="tags-standard"
options={top100Films}
getOptionLabel={option => option.title}
defaultValue={[top100Films[13]]}
renderTags={selected => {
console.log("selected = ", selected);
let renderTagsValue = selected
.map(function(elem) {
return elem.title;
})
.join(", ");
return (
<Typography noWrap={true} color="textPrimary">
{renderTagsValue}
</Typography>
);
}}
renderInput={params => (
<TextField
{...params}
variant="standard"
label="Multiple values"
placeholder="Favorites"
/>
)}
/>
renderTags
– 因为 renderValue 不是 Autocomplete
的选项,我在 renderTags
.join
,但这只会创建一个继续换行到下一行的长字符串disableListWrap
- 我希望这会阻止任何东西换行到下一行,但它仍然换行到下一行limitTags
– 这不起作用,因为标签可以是可变长度的。根据选择的标签,1、2 或 3 可能适合一行renderTags
AND Typography
- 与 #1 相同,并返回一个 Typography
元素,其中 noWrap
设置为 true
(这很接近但仍然不对我最接近的尝试是#4,但仍然不对。它 chop ,但仍将占位符文本换行到下一行,使文本框的高度垂直扩展,而不是保持固定(如带有 Multiple Select
的演示)。
Autocomplete
复制 Material UI Multiple Select
chop 的 renderValue?最佳答案
我只需将 style={{ maxWidth: 360 }}
添加到您的沙盒中的 Typography
即可获得合理的行为,以便为占位符和一些空间留出空间输入。
这是完整的代码:
/* eslint-disable no-use-before-define */
import React from "react";
import Chip from "@material-ui/core/Chip";
import Autocomplete from "@material-ui/lab/Autocomplete";
import { makeStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
import Typography from "@material-ui/core/Typography";
const useStyles = makeStyles(theme => ({
root: {
width: 500,
"& > * + *": {
marginTop: theme.spacing(3)
}
}
}));
export default function Tags() {
const classes = useStyles();
return (
<div className={classes.root}>
<Autocomplete
multiple
disableListWrap={true}
disableCloseOnSelect
id="tags-standard"
options={top100Films}
getOptionLabel={option => option.title}
defaultValue={[top100Films[13]]}
renderTags={selected => {
console.log("selected = ", selected);
let renderTagsValue = selected
.map(function(elem) {
return elem.title;
})
.join(", ");
return (
<Typography
style={{ maxWidth: 360 }}
noWrap={true}
color="textPrimary"
>
{renderTagsValue}
</Typography>
);
}}
renderInput={params => (
<TextField
{...params}
variant="standard"
label="Multiple values"
placeholder="Favorites"
/>
)}
/>
</div>
);
}
// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
const top100Films = [
{ title: "The Shawshank Redemption", year: 1994 },
{ title: "The Godfather", year: 1972 },
{ title: "The Godfather: Part II", year: 1974 },
{ title: "The Dark Knight", year: 2008 },
{ title: "12 Angry Men", year: 1957 },
{ title: "Schindler's List", year: 1993 },
{ title: "Pulp Fiction", year: 1994 },
{ title: "The Lord of the Rings: The Return of the King", year: 2003 },
{ title: "The Good, the Bad and the Ugly", year: 1966 },
{ title: "Fight Club", year: 1999 },
{ title: "The Lord of the Rings: The Fellowship of the Ring", year: 2001 },
{ title: "Star Wars: Episode V - The Empire Strikes Back", year: 1980 },
{ title: "Forrest Gump", year: 1994 },
{ title: "Inception", year: 2010 },
{ title: "The Lord of the Rings: The Two Towers", year: 2002 },
{ title: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ title: "Goodfellas", year: 1990 },
{ title: "The Matrix", year: 1999 },
{ title: "Seven Samurai", year: 1954 },
{ title: "Star Wars: Episode IV - A New Hope", year: 1977 },
{ title: "City of God", year: 2002 },
{ title: "Se7en", year: 1995 },
{ title: "The Silence of the Lambs", year: 1991 },
{ title: "It's a Wonderful Life", year: 1946 },
{ title: "Life Is Beautiful", year: 1997 },
{ title: "The Usual Suspects", year: 1995 },
{ title: "Léon: The Professional", year: 1994 },
{ title: "Spirited Away", year: 2001 },
{ title: "Saving Private Ryan", year: 1998 },
{ title: "Once Upon a Time in the West", year: 1968 },
{ title: "American History X", year: 1998 },
{ title: "Interstellar", year: 2014 },
{ title: "Casablanca", year: 1942 },
{ title: "City Lights", year: 1931 },
{ title: "Psycho", year: 1960 },
{ title: "The Green Mile", year: 1999 },
{ title: "The Intouchables", year: 2011 },
{ title: "Modern Times", year: 1936 },
{ title: "Raiders of the Lost Ark", year: 1981 },
{ title: "Rear Window", year: 1954 },
{ title: "The Pianist", year: 2002 },
{ title: "The Departed", year: 2006 },
{ title: "Terminator 2: Judgment Day", year: 1991 },
{ title: "Back to the Future", year: 1985 },
{ title: "Whiplash", year: 2014 },
{ title: "Gladiator", year: 2000 },
{ title: "Memento", year: 2000 },
{ title: "The Prestige", year: 2006 },
{ title: "The Lion King", year: 1994 },
{ title: "Apocalypse Now", year: 1979 },
{ title: "Alien", year: 1979 },
{ title: "Sunset Boulevard", year: 1950 },
{
title:
"Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb",
year: 1964
},
{ title: "The Great Dictator", year: 1940 },
{ title: "Cinema Paradiso", year: 1988 },
{ title: "The Lives of Others", year: 2006 },
{ title: "Grave of the Fireflies", year: 1988 },
{ title: "Paths of Glory", year: 1957 },
{ title: "Django Unchained", year: 2012 },
{ title: "The Shining", year: 1980 },
{ title: "WALL·E", year: 2008 },
{ title: "American Beauty", year: 1999 },
{ title: "The Dark Knight Rises", year: 2012 },
{ title: "Princess Mononoke", year: 1997 },
{ title: "Aliens", year: 1986 },
{ title: "Oldboy", year: 2003 },
{ title: "Once Upon a Time in America", year: 1984 },
{ title: "Witness for the Prosecution", year: 1957 },
{ title: "Das Boot", year: 1981 },
{ title: "Citizen Kane", year: 1941 },
{ title: "North by Northwest", year: 1959 },
{ title: "Vertigo", year: 1958 },
{ title: "Star Wars: Episode VI - Return of the Jedi", year: 1983 },
{ title: "Reservoir Dogs", year: 1992 },
{ title: "Braveheart", year: 1995 },
{ title: "M", year: 1931 },
{ title: "Requiem for a Dream", year: 2000 },
{ title: "Amélie", year: 2001 },
{ title: "A Clockwork Orange", year: 1971 },
{ title: "Like Stars on Earth", year: 2007 },
{ title: "Taxi Driver", year: 1976 },
{ title: "Lawrence of Arabia", year: 1962 },
{ title: "Double Indemnity", year: 1944 },
{ title: "Eternal Sunshine of the Spotless Mind", year: 2004 },
{ title: "Amadeus", year: 1984 },
{ title: "To Kill a Mockingbird", year: 1962 },
{ title: "Toy Story 3", year: 2010 },
{ title: "Logan", year: 2017 },
{ title: "Full Metal Jacket", year: 1987 },
{ title: "Dangal", year: 2016 },
{ title: "The Sting", year: 1973 },
{ title: "2001: A Space Odyssey", year: 1968 },
{ title: "Singin' in the Rain", year: 1952 },
{ title: "Toy Story", year: 1995 },
{ title: "Bicycle Thieves", year: 1948 },
{ title: "The Kid", year: 1921 },
{ title: "Inglourious Basterds", year: 2009 },
{ title: "Snatch", year: 2000 },
{ title: "3 Idiots", year: 2009 },
{ title: "Monty Python and the Holy Grail", year: 1975 }
];
关于javascript - Material UI Autocomplete 的 chop 值(复制 Material UI Multiple Select 的 chop renderValue),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62820103/
我正在使用 onclick javascript 方法,动态内容如下: onclick="adviceEvent('${advice?.content}');" 建议内容介于字符串之间,例如: Che
我想 chop 一个具有字符限制的字符串,并且最后一个字符应该是空格的条件(这样我就没有被 chop 的单词) 示例: var sentence = "The string that I want t
我正在使用省略号 chop 文本并在工具提示上显示整个文本。如果文本溢出,则仅显示工具提示。工具提示在 Chrome 中看起来不错,但在 IE 和 Firefox 中却不行。在 IE 中,工具提示文本
我正在使用带有 rails ( http://jrvis.com/trunk8/#toggle ) 的 trunk8 jquery 插件,它只会 chop 前几个句子,直到第一个中断空格。这是我的代码
Readmore Js 只折叠 div block 而不折叠文本。请帮助我 chop 文本和 div 容器,而不仅仅是 div。非常感谢 London is the most popul
我有一个 div,它会动态填充一些可能包含或不包含链接的文本。 例如: Welcome to Stackoverflow. Someone will provide an answer to
作为一些背景 使用 Material UI Multiple Select,您可以 chop 选择后显示的值,而不是转到另一行(通过将 renderValue 设置为 .join selected 选
有人可以向我解释一下为什么不能将包含空格的字符串作为参数传递到 JavaScript 函数中吗? 这是我的代码,显示了这个问题,只需将鼠标悬停在链接上,您就会看到只有“mario”显示为标题,而不是“
我在打印模块内容时遇到了问题,这发生在所有浏览器上。当我打印模态内容时,它只预览第一页,第一页之后的任何内容都会被切断。我已经尝试在 Chrome 打印模拟器中进行调试,但仍然无法找到解决方案。 在某
我正在尝试检测是否使用 JS chop 了文本。解决方案mentioned here除了下面的边缘情况外,效果很好。您会注意到,如果文本在视觉上被 chop ,则鼠标悬停的第一个 block 将返回
我制作的模态面临一个罕见的问题。我有一个iframe,可以在该模式下加载嵌入式youtube视频,它在为测试该视频而创建的单独HTML文件(空白)上运行良好。 当我尝试将其加载到实际网站的本地模板上时
我有一个 Javascript,它从两个 HTML 下拉列表中读取文本,删除所有特殊字符,然后将文本存储在变量中。下拉列表中的文本来自 JSON 文件。问题是,只要下拉列表中的文本有撇号,Javasc
在node和chrome中,下面的代码只给了我10个堆栈帧,而我期望的是100个。有什么方法可以打印整个堆栈吗? function blowUp(n) { if(n > 100) {
所以我有一个对象数组,问题是返回的名称很长。我怎样才能让名字结果看起来像 returnedArray: [ {name:'reallyy..',age:'28',hobby:'blah'},{name
我遇到了一些字符串溢出其容器的问题。我当然可以使用溢出:隐藏,但它看起来不太好,因为我更喜欢文本溢出:省略号。然而,对此的跨平台支持充其量是不确定的,而且我发现的现有解决方案不允许字符串在包含空格时换
我正在编写 jQuery 应用程序,但遇到了障碍。 我需要我的双行描述简介能够在浏览器大小调整时随着文本回流而做出响应。下面的示例成功地收缩了字符串的大小,并在缩小浏览器时替换为省略号。但是当您扩大浏
当前版本: def chop(ar,size): p=len(ar)/size for i in xrange(p): yield ar[(i*size):((i+1)
My Codepen if("matchMedia" in window) { if(window.matchMedia("(max-width: 533px)").matches) {
我这里遇到了一些问题。 我基本上是在 div 中循环项目,以便每个项目都有一个可以使用的键,这样当单击图标时,就会出现一个编辑模式并填充所选项目的数据。 这可行,但我想为我的跨度添加功能 {{ $no
我有一个代码块,其中包含以下形式的行: 在接收端,我有一个像这样抓取数据的文档: $title = $_POST['title']; 这将被插入到数据库中,但任何包含撇号的“标题”都会在撇号处被
我是一名优秀的程序员,十分优秀!