question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AutoComplete:<li> cannot appear as a descendant of <li> when using ListItem in renderOption

See original GitHub issue

Hi 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:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

16reactions
oliviertassinaricommented, Mar 1, 2020

The alternative is to set a component=“div” on the list item to clear the warning.

1reaction
oliviertassinaricommented, Sep 11, 2020

@ImanMahmoudinasab See #19254 for a proper fix, in case you want to work on it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found