selectField.tsx 1.0 KB

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