在用户键入时停止使 react-select 宽度扩展

stop make react-select width expanding while user typing

我正在使用 React-select。但是,不知何故,当用户输入这么多字符时,输入容器会水平增长,甚至会打破屏幕(屏幕宽度)。如何使宽度在每种情况下都是静态的?示例条件是当用户键入或选项中显示的值太长时,我希望它只显示部分字符,例如:

真实字符串:'hello this is option one dude', 在选项和输入容器中显示:'hello this is option.....'

可以实现吗?怎么做?我尝试了 但没有用。

这里是 react-select 的完整样式代码:

const styles = {
  option: (base, state) => ({
    ...base,
    backgroundColor: state.isSelected ? 'grey' : 'grey',
    color: state.isSelected ? 'white' : 'black',
    ':active': {
      backgroundColor: state.isSelected ? 'grey' : 'grey',
      color: state.isSelected ? 'white' : 'white',
    },
  }),
  control: (base, state) => ({
    ...base,
    background: 'white',
    borderRadius: 0,
    borderTop: 0,
    borderLeft: 0,
    borderRight: 0,
    borderColor: state.isFocused ? 'black' : 'black', // disable blue color in the box when input focused
    boxShadow: state.isFocused ? 0 : 0,
    whiteSpace: 'nowrap',
    width: '100%',
  }),
  menu: base => ({
    ...base,
    borderRadius: 0,
    hyphens: 'auto', // beautify the word cut by adding a dash see https://caniuse.com/#search=hyphens for the compatibility
    marginTop: 0, // kill the gap
    textAlign: 'left',
  }),
  menuList: base => ({
    ...base,
    padding: 0, // kill the white space on first and last option
    backgroundColor: 'grey',
    maxHeight: '80px',
    overflowY: 'auto',
  }),
  indicatorSeparator: base => ({
    ...base,
    display: 'none',
  }),
  dropdownIndicator: (base, state) => ({
    ...base,
    transition: 'all .2s ease',
    transform: state.isFocused ? 'rotate(180deg)' : null,
  }),
  noOptionsMessage: base => ({
    ...base,
    color: 'white',
  }),
  valueContainer: base => ({
    ...base,
    overflowX: 'hidden',
    display: 'inline-block',
  }),
  input: base => ({
    ...base,
    display: 'inline-block',
  }),
};

谢谢!

您可以将以下样式添加到您的输入元素中吗(假设它是 valueContainer 并检查它是否隐藏了溢出

{
display: block;
width: 100px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}