import React, { Component } from 'react'; interface Props { value: T; options: T[]; ariaLabel: string; extra?: any; formatTitle?(option: T): any; onChange(value: T): void; } interface State { expanded: boolean; } export default class DropdownComponent extends Component, State> { public state = { expanded: false }; public render() { const { options, value, ariaLabel, extra } = this.props; const { expanded } = this.state; return ( {expanded && ( )} ); } public formatTitle = (option: any) => { if (this.props.formatTitle) { return this.props.formatTitle(option); } }; public toggleExpanded = () => { this.setState(state => { return { expanded: !state.expanded }; }); }; public onChange = (value: any) => { this.props.onChange(value); this.setState({ expanded: false }); }; }