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.

Dropdown does not appear on clicking inside value but appears on click of down arrow icon in React Select

See original GitHub issue

I am using Multi Select and want to render just 1 item and then show additional selected item as +(this) more inside the selected area, it works fine when there is no value selected, but when the select component is populated from api response i.e when it already has value inside it the dropdown doesn’t appear on clicking of the area where selected value are shown but it opens when I click on down arrow icon. I am using styled component for styling. I asked in StackOverflow but didn’t got any answer, so posting here hope I get some solution. `

       const ValueContainer = ({ children, getValue, hasValue, ...props }) => {

	let maxToShow = 1;
	let length = getValue().length;
	let displayChips = React.Children.toArray(children).slice(0, maxToShow);
	let shouldBadgeShow = length > maxToShow;
	let displayLength = length - maxToShow;

	if (!hasValue) {
		return (
			<components.ValueContainer {...props}>
				{children}
			</components.ValueContainer>
		);
	}

	return (
		<components.ValueContainer {...props}>
			{!props.selectProps.inputValue && displayChips}
			<Div
				fontSize={0}
				fontWeight={5}
				color="#4380FF"
				ml="auto"
				pl="3px"
				minWidth="56px">
				{shouldBadgeShow && `+ ${displayLength} more`}
			</Div>
		</components.ValueContainer>
	);
};
   const Option = props => {
	return (
		<Div>
			<components.Option {...props}>
				<Flex alignItems="center">
					<CheckBox
						checked={props.isSelected}
						width="20px"
						height="20px"
						mr="10px"
					/>
					<Div width={0.85}>{props.label} </Div>
				</Flex>
			</components.Option>
		</Div>
	);
};
    <Select
	classNamePrefix="faq__dropdown"
        className={
	'faq__dropdown--empty'
	}
	isClearable={false}
	isSearchable={false}
        isMulti
	hideSelectedOptions={false}
	closeMenuOnSelect={false}
	components={{ Option, MultiValue }}
	options={attributeMsgs}
	value={selectedAttributeMsgs}
	onChange={e => handleAttributeMsg(e)}
								
	/>

`

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
Shivraj97commented, Mar 8, 2021

@ebonow I was able to solve the issue, Thanks for the help.

0reactions
ebonowcommented, Mar 1, 2021

@Shivraj97 the solution you are referring to filters out all children elements of the ValueContainer including the Placeholder. You would need to make sure you specify it as a filtered item. If you wanted to achieve it with the solution that was recommended then it would look similar to this:

const IndicatorsContainer = ({ children, ...props }) => {
  const allowedTypes = ["Placeholder", "Input"];
  const allowedChildren = Children.map(children, (child) => {
    return child && allowedTypes.includes(child.type.name) ? child : null;
  });

  return (
    <components.ValueContainer {...props}>
      // Put your other custom JSX stuff here 
      {allowedChildren}
    </components.ValueContainer>
  );
};

It’s also worth noting that there is a prop called controlShouldRenderValue which will filter out the value component for you so it could be better simplified by removing all of the filtering and just passing in that prop as true with the extra JSX you want to put in the ValueContainer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-select, down arrow is not opening the dropdown
1", down arrow won't open the menu. I see this work in demo examples and I am using the same code. <Select id="state-select"...
Read more >
react-select dropdown doesn't show dropdown menu ... - Reddit
However, when adding it to the page I want to display it on, while the bar itself shows, clicking it does nothing but...
Read more >
Dropdown - Multiselect - Carbon Design System
Dropdowns present a list of options from which a user can select one option, or several. ... dropdown, click the “x” icon next...
Read more >
Dropdown - Ant Design
When there are more than a few options to choose from, you can wrap them in a Dropdown . By hovering or clicking...
Read more >
Dropdown | Webflow University
The Menu is set to Show in the Dropdown settings of the Settings panel. By default, the dropdown list appears when a user...
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