diff --git a/CHANGELOG.md b/CHANGELOG.md index 4035559c5d3..05865527732 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Fixed `EuiTitle` not rendering child classes ([#2925](https://github.com/elastic/eui/pull/2925)) - Extended `div` element in `EuiFlyout` type ([#2914](https://github.com/elastic/eui/pull/2914)) - Fixed popover positioning service to be more lenient when positioning 0-width or 0-height content ([#2948](https://github.com/elastic/eui/pull/2948)) +- Fixed type definitions for `EuiComboBox` ([#2971](https://github.com/elastic/eui/pull/2971)) **Theme: Amsterdam** diff --git a/src/components/combo_box/combo_box.tsx b/src/components/combo_box/combo_box.tsx index 47b81847d39..cd29bea80b8 100644 --- a/src/components/combo_box/combo_box.tsx +++ b/src/components/combo_box/combo_box.tsx @@ -49,7 +49,7 @@ type DrillProps = Pick< 'onCreateOption' | 'options' | 'renderOption' | 'selectedOptions' >; -export interface EuiComboBoxProps +interface _EuiComboBoxProps extends CommonProps, Omit, 'onChange'>, DrillProps { @@ -75,6 +75,27 @@ export interface EuiComboBoxProps singleSelection: boolean | EuiComboBoxSingleSelectionShape; } +/** + * Because of how TypeScript's LibraryManagedAttributes is designed to handle defaultProps (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#support-for-defaultprops-in-jsx) + * we can't directly export the above Props definitions, as the defaulted values are not made optional + * as it isn't processed by LibraryManagedAttributes. To get around this, we: + * - remove the props which have default values applied + * - additionally re-define `options` and `selectedOptions` defaults, necessary as static members can't access generics and become never[] + * - export (Props - Defaults) & Partial + */ +type DefaultProps = Omit< + typeof EuiComboBox['defaultProps'], + 'options' | 'selectedOptions' +> & { + options: Array>; + selectedOptions: Array>; +}; +export type EuiComboBoxProps = Omit< + _EuiComboBoxProps, + keyof DefaultProps +> & + Partial>; + interface EuiComboBoxState { activeOptionIndex: number; hasFocus: boolean; @@ -89,7 +110,7 @@ interface EuiComboBoxState { const initialSearchValue = ''; export class EuiComboBox extends Component< - EuiComboBoxProps, + _EuiComboBoxProps, EuiComboBoxState > { static defaultProps = { @@ -654,7 +675,7 @@ export class EuiComboBox extends Component< } static getDerivedStateFromProps( - nextProps: EuiComboBoxProps, + nextProps: _EuiComboBoxProps, prevState: EuiComboBoxState ) { const { options, selectedOptions, singleSelection } = nextProps; diff --git a/src/components/combo_box/combo_box_options_list/combo_box_options_list.tsx b/src/components/combo_box/combo_box_options_list/combo_box_options_list.tsx index 2a69172730a..5530df3027b 100644 --- a/src/components/combo_box/combo_box_options_list/combo_box_options_list.tsx +++ b/src/components/combo_box/combo_box_options_list/combo_box_options_list.tsx @@ -52,7 +52,7 @@ export type EuiComboBoxOptionsListProps = CommonProps & onCreateOption?: ( searchValue: string, options: Array> - ) => boolean; + ) => boolean | void; onOptionClick?: OptionHandler; onOptionEnterKey?: OptionHandler; onScroll?: ListProps['onScroll'];