Skip to content

Commit

Permalink
Fix EuiSuperSelect TS defs (#1995)
Browse files Browse the repository at this point in the history
* fix euiSuperSelect ts defs

* #1995 CL entry
  • Loading branch information
thompsongl authored Jun 5, 2019
1 parent e999327 commit 2548b19
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fixed optional TS definitions for `EuiColorPicker` `onBlur` and `onFocus` callbacks ([#1993](https://github.com/elastic/eui/pull/1993))
- Fixed `EuiIcon` again so that webpack can build dynamic require contexts ([#1998](https://github.com/elastic/eui/pull/1998))
- Fixed double borders on prepend/append items in `EuiFormControlLayout` ([#1996](https://github.com/elastic/eui/pull/1996))
- Fixed `EuiSuperSelect` TS definitions ([#1995](https://github.com/elastic/eui/pull/1995))

## [`11.3.0`](https://github.com/elastic/eui/tree/v11.3.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ exports[`EuiSuperSelect props more props are propogated to each option 2`] = `
fullWidth={false}
isInvalid={false}
isLoading={false}
onChange={[Function]}
onClick={[Function]}
onKeyDown={[Function]}
options={
Expand Down Expand Up @@ -499,7 +498,6 @@ exports[`EuiSuperSelect props more props are propogated to each option 2`] = `
fullWidth={false}
isInvalid={false}
isLoading={false}
onChange={[Function]}
onClick={[Function]}
onKeyDown={[Function]}
options={
Expand Down Expand Up @@ -563,7 +561,6 @@ exports[`EuiSuperSelect props more props are propogated to each option 2`] = `
aria-selected={true}
className="euiSuperSelectControl euiSuperSelect--isOpen__button"
data-test-subj="superSelect"
onChange={[Function]}
onClick={[Function]}
onKeyDown={[Function]}
role="option"
Expand Down
23 changes: 16 additions & 7 deletions src/components/form/super_select/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommonProps } from '../../common';
import { CommonProps, Omit } from '../../common';

import { FunctionComponent, ReactNode, ButtonHTMLAttributes } from 'react';

Expand All @@ -7,21 +7,23 @@ declare module '@elastic/eui' {
* @see './super_select.js'
*/

export type EuiSuperSelectProps = CommonProps &
ButtonHTMLAttributes<HTMLButtonElement> & {
export type EuiSuperSelectProps<T extends string> = CommonProps &
Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onChange'> & {
/**
* Pass an array of options that must at least include:
* `value`: storing unique value of item,
* `inputDisplay`: what shows inside the form input when selected
* `dropdownDisplay` (optional): what shows for the item in the dropdown
*/
options: Array<{
value: string;
value: T;
inputDisplay?: ReactNode;
dropdownDisplay?: ReactNode;
disabled?: boolean;
'data-test-subj'?: string;
}>;

valueOfSelected?: string;
valueOfSelected?: T;

/**
* Classes for the context menu item
Expand All @@ -31,7 +33,7 @@ declare module '@elastic/eui' {
/**
* You must pass an `onChange` function to handle the update of the value
*/
onChange?: (value: string) => void;
onChange?: (value: T) => void;

/**
* Change to `true` if you want horizontal lines between options.
Expand All @@ -54,6 +56,11 @@ declare module '@elastic/eui' {
*/
isInvalid?: boolean;

/**
* Provides a loading indicator. Default: false
*/
isLoading?: boolean;

/**
* Make it short. Default: false
*/
Expand All @@ -70,5 +77,7 @@ declare module '@elastic/eui' {
isOpen?: boolean;
};

export const EuiSuperSelect: FunctionComponent<EuiSuperSelectProps>;
export const EuiSuperSelect: <T extends string>(
props: EuiSuperSelectProps<T>
) => ReturnType<FunctionComponent<EuiSuperSelectProps<T>>>;
}
5 changes: 4 additions & 1 deletion src/components/form/super_select/super_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ export class EuiSuperSelect extends Component {
<EuiSuperSelectControl
options={options}
value={valueOfSelected}
onChange={onChange}
onClick={
this.state.isPopoverOpen ? this.closePopover : this.openPopover
}
Expand Down Expand Up @@ -307,6 +306,10 @@ EuiSuperSelect.propTypes = {
* Provides invalid styling
*/
isInvalid: PropTypes.bool,
/**
* Provides loading indictor
*/
isLoading: PropTypes.bool,
/**
* Make it short
*/
Expand Down

0 comments on commit 2548b19

Please sign in to comment.