selectField.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import {Component, createRef} from 'react';
  2. import SelectControl, {ControlProps} from 'sentry/components/forms/selectControl';
  3. type Props = Pick<
  4. ControlProps,
  5. 'value' | 'placeholder' | 'name' | 'onChange' | 'options'
  6. >;
  7. class SelectField extends Component<Props> {
  8. componentDidMount() {
  9. if (!this.selectRef.current) {
  10. return;
  11. }
  12. if (this.selectRef.current?.select?.inputRef) {
  13. this.selectRef.current.select.inputRef.autocomplete = 'off';
  14. }
  15. }
  16. // TODO(ts) The generics in react-select make getting a good type here hard.
  17. selectRef = createRef<any>();
  18. render() {
  19. return (
  20. <SelectControl
  21. {...this.props}
  22. isSearchable={false}
  23. options={this.props.options.map(opt => ({
  24. ...opt,
  25. details: opt.description ? `(${opt.description})` : undefined,
  26. }))}
  27. styles={{
  28. control: (provided: {[x: string]: string | number | boolean}) => ({
  29. ...provided,
  30. minHeight: '41px',
  31. height: '41px',
  32. }),
  33. }}
  34. ref={this.selectRef}
  35. openOnFocus
  36. />
  37. );
  38. }
  39. }
  40. export default SelectField;