selectField.tsx 963 B

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