AutoComplete:<li> cannot appear as a descendant of <li> when using ListItem in renderOption
See original GitHub issueHi guys,
I have this boring warning when using a ListItem object as renderOption:
Warning: validateDOMNesting(...): <li> cannot appear as a descendant of <li>
.
Can’t find how to bypass it. Any idea?
import {
ListItem as MUIListItem,
ListItemProps,
TextField,
} from "@material-ui/core";
import RemoveIcon from "@material-ui/icons/RemoveCircleOutlineSharp";
import Autocomplete from "@material-ui/lab/Autocomplete";
import React, { useState } from "react";
import { ITextFieldProps } from "../InputField/BaseInputField";
import Chip from "./../Chip";
export interface IOptionsValue {
value: string;
label: string;
}
interface IMultiSelectChipsProps {
options: IOptionsValue[];
}
export interface IListItem extends ListItemProps {
option: IOptionsValue;
}
const ListItem: React.FC<IListItem> = (props: IListItem): JSX.Element => {
return (
<MUIListItem key={props.option.value} value={props.option.value}>
{props.option.label}
</MUIListItem>
);
};
const MultiSelectChips: React.FC<IMultiSelectChipsProps> = (
props: IMultiSelectChipsProps
) => {
const [val, setVal] = useState<IOptionsValue[]>([]);
return (
<div style={{ width: 500 }}>
<Autocomplete
multiple
id="tags-standard"
freeSolo
filterSelectedOptions
options={props.options}
onChange={(_, newValue: IOptionsValue[]) => setVal(newValue)}
getOptionLabel={(option: IOptionsValue) => option.label}
renderTags={(value: IOptionsValue[]) =>
value.map((option: IOptionsValue, index: number) => (
<Chip
key={index}
label={option.label}
deleteIcon={<RemoveIcon />}
onDelete={() => {
setVal(val.filter(entry => entry !== option));
}}
/>
))
}
value={val}
renderInput={(params: ITextFieldProps) => (
<TextField
{...params}
variant="standard"
placeholder="Select..."
margin="normal"
fullWidth
/>
)}
renderOption={(option: IOptionsValue) => (
<ListItem option={option} />
)}
{...props}
/>
</div>
);
};
export default MultiSelectChips;
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
AutoComplete:<li> cannot appear as a descendant of ... - GitHub
Hi guys, I have this boring warning when using a ListItem object as renderOption: Warning: validateDOMNesting(...): cannot appear as a ...
Read more >validateDOMNesting(...): <li> cannot appear as a descendant ...
I'm getting the warning message validateDOMNesting(...): cannot descendant of li in the console and it shows the error is on the treeview ...
Read more >validatedomnesting(...): <li> cannot appear as a descendant of ...
Hi guys, I have this boring warning when using a ListItem object as renderOption: Warning: validateDOMNesting(...): <li> cannot appear as a descendant of ......
Read more >li cannot appear as a descendant of li
li cannot appear as a descendant of li. descendant selector in action: ul li { ⋮ declarations} This selector matches all li elements...
Read more >23 - Warning: validateDOMNesting(...):cannot appear as a child
cannot appear as a child , Concept Fragments in React .Watch Full Part of this Series : https://www.youtube.com/playlist? li...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The alternative is to set a component=“div” on the list item to clear the warning.
@ImanMahmoudinasab See #19254 for a proper fix, in case you want to work on it.