Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EuiSuperSelect TS defs #1995

Merged
merged 5 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**Bug fixes**

- Fixed optional TS definitions for `EuiColorPicker` `onBlur` and `onFocus` callbacks ([#1993](https://github.com/elastic/eui/pull/1993))
- 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}
Copy link
Contributor Author

@thompsongl thompsongl Jun 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually do anything because it gets passed to a button. onClick handlers do all the change management

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