react-select

How can I use react-select to custom render subtext below each dropdown item?

元气小坏坏 提交于 2019-12-02 08:59:09
I'm trying to figure out how I can utilize the custom components in react-select to render a dropdown that has items with subtext. I've looked at each one of the components on: https://react-select.com/components and not sure which one would best fit my needs. From looking at the list of components, I believe the option component is meant for something like that and would probably work but i'm not sure. Can someone validate my thought? React-select V2 solution: You are absolutely right, using Option component will allow you to format each option in the menuList like the follow example: const

react-select in flex container

浪子不回头ぞ 提交于 2019-12-02 08:49:22
问题 How can I make react-select to respect flex layout? Nothing of the below worked. const Container = styled('div')` width: 100%; height: 100%; display: flex; flex-flow: row wrap; justify-content: space-around; align-items: baseline; `; const selectStyles = { input: base => ({ minWidth: 200, flex: 1, <Container> <Select style={{ flex: 1 }} styles={selectStyles} 回答1: To make your react-select component flex you need to apply flex:1 props on the container like this: const styles = { container:

react-select in flex container

不打扰是莪最后的温柔 提交于 2019-12-02 06:22:27
How can I make react-select to respect flex layout? Nothing of the below worked. const Container = styled('div')` width: 100%; height: 100%; display: flex; flex-flow: row wrap; justify-content: space-around; align-items: baseline; `; const selectStyles = { input: base => ({ minWidth: 200, flex: 1, <Container> <Select style={{ flex: 1 }} styles={selectStyles} To make your react-select component flex you need to apply flex:1 props on the container like this: const styles = { container: base => ({ ...base, flex: 1 }) }; <Select styles={styles} /> 来源: https://stackoverflow.com/questions/54234709

How to make a filter in react-select using the value of another react-select

我的未来我决定 提交于 2019-12-01 10:28:26
问题 I'm creating a solution using a react-select and that a select should contain only the options it does not contain in the other. Ex import React from 'react' import Select from 'react-select' const list = [ { label: 'foo', value: 1 }, { label: 'bar', value: 2 }, { label: 'bin', value: 3 }, ] export default Test extends React.Component { render = () => ( <> <Select ref="a" options={list} /> <Select ref="b" options={list} filterOption={o => /* devo omitir "a" */} /> </> ) } What do I need to do

how to test react-select with react-testing-library

蓝咒 提交于 2019-12-01 02:45:17
问题 App.js import React, { Component } from "react"; import Select from "react-select"; const SELECT_OPTIONS = ["FOO", "BAR"].map(e => { return { value: e, label: e }; }); class App extends Component { state = { selected: SELECT_OPTIONS[0].value }; handleSelectChange = e => { this.setState({ selected: e.value }); }; render() { const { selected } = this.state; const value = { value: selected, label: selected }; return ( <div className="App"> <div data-testid="select"> <Select multi={false} value=

react-select styling issues with style props

风格不统一 提交于 2019-11-30 15:44:06
I wanted to use react-select and ran into a whole array of issues after I changed the page background color from white to custom. (The issues aren't so evident on the white background as on react-select's github page) I'm doing the above through styles prop as the className prop wouldn't work properly. Here is the styles prop. const colourStyles = { control: styles => ({ ...styles, backgroundColor: '#023950', color: 'white', border: 0 }), option: (styles) => { return { backgroundColor: '#023950', color: 'white' }; }, singleValue: styles => ({ ...styles, color: 'white' }), }; Here is a list of

How to programmatically clear/reset React-Select?

谁都会走 提交于 2019-11-30 07:26:06
问题 ReactSelect V2 and V3 seems to have several props like clearValue , resetValue and setValue . Whatever I'm trying, I'm not able to clear the selections programmatically. resetValue seems not to be accessible from the outside. selectRef.setValue([], 'clear') // or selectRef.clearValue() This does not clear the current selection. Do I miss something here or is it not fully implemented yet? 回答1: If you're using react-select you can try to pass null to value prop. For example: import React from

How to style react-select options

隐身守侯 提交于 2019-11-30 04:56:43
What's the best way to style a react-select component's ( https://github.com/JedWatson/react-select ) options? I can target the select itself just fine, with something like: ... import Select from 'react-select' ... const styles = { fontSize: 14, color: 'blue', } <Select options={[1,2,3,4]} placeholder={'Select something'} clearable={false} style={styles.select} /> The problem is, the actual options when the select is expanded remain styled as the default. How can I target these options for styling? Here is an example of what I'm talking about. I can style the placeholder, but not the options:

How to set a default value in react-select

不打扰是莪最后的温柔 提交于 2019-11-28 07:14:34
i have an issue using react-select. I use redux form and i've made my react-select component compatible with redux form. Here is the code: const MySelect = props => ( <Select {...props} value={props.input.value} onChange={value => props.input.onChange(value)} onBlur={() => props.input.onBlur(props.input.value)} options={props.options} placeholder={props.placeholder} selectedValue={props.selectedValue} /> ); and here how i render it: <div className="select-box__container"> <Field id="side" name="side" component={SelectInput} options={sideOptions} clearable={false} placeholder="Select Side"

Use async react-select with redux-saga

岁酱吖の 提交于 2019-11-27 16:22:48
问题 I try to implement a async react-select (Select.Async). The problem is, we want to do the fetch in redux-saga. So if a user types something, the fetch-action should be triggered. Saga then fetches the record and saved them to the store. This works so far. Unfortunately loadOptions has to return a promise or the callback should be called. Since the newly retrieved options get propagated with a changing property, I see no way to use Select.Async together with saga to do the async fetch call.