Cannot change the width of the react-select element

Viewed 7986

Whatever I do I cannot manage to change the width of the select. It always stays the same, some default width (like about 75px).

const Container = styled('div')`
  width: 100%;
  height: 100%;
  display: flex;
  flex-flow: row wrap;
  justify-content: space-around;
`;
const selectStyles = {
  valueContainer: base => ({
    width: 300,
  }),
  group: base => ({
    width: 300,
  }),
  container: base => ({
    width: 300,
  }),
  control: base => ({
    width: 300,
  }),
  singleValue: base => ({
    width: 300,
  }),
  input: base => ({
    width: 300,
    color: theme.palette.text.primary,
    '& input': {
      font: 'inherit',
    },
  }),
}

return (
  <SplitPane split='horizontal' defaultSize={260}>
    <Paper
      style={{ width: '100%' }}
    >
      <Container>
        <Select
          styles={selectStyles}
          options={suggestions}
          value={this.state.channel}
          onChange={(value) => (this.setState({ channel: value }))}
        />

What am I doing wrong?

2 Answers

Seems like you are actually looking for ways to have react-select width behave properly in a flexbox design (such as flex-growing), in that case refer to this reply, but in a nutshell you can just use this styling:

const styles = {
  container: base => ({
    ...base,
    flex: 1
  })
};

<Select styles={styles} />

You just did a misspell on the props name it's styles instead of style inside the Select component.

Related