Skip to content

Add TypeScript definitions for EuiRange and EuiRadio#1253

Merged
pugnascotia merged 2 commits into
elastic:masterfrom
pugnascotia:yet-more-ts-defs
Oct 22, 2018
Merged

Add TypeScript definitions for EuiRange and EuiRadio#1253
pugnascotia merged 2 commits into
elastic:masterfrom
pugnascotia:yet-more-ts-defs

Conversation

@pugnascotia
Copy link
Copy Markdown
Contributor

Add TypeScript definitions for EuiRange and EuiRadio, and correct the definitions for EuiRadioGroup.

Also correct the definitions for EuiRadioGroup.

export type EuiRadioGroupProps = CommonProps &
Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> & {
disabled?: boolean;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add disabled and name to the radio group's proptypes as well, so they're included in the documentation & runtime checks.

Comment thread src/components/form/radio/index.d.ts Outdated
}

export const EuiRadio: SFC<
CommonProps & InputHTMLAttributes<HTMLInputElement> & EuiRadioProps
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

EuiRadio applies its extra props to a div, not any kind of input. The props here need to reflect that with HTMLAttributes<HTMLDivElement>. This also means the input-related props (checked, value, disabled, autoFocus) on EuiRadio need to be added to EuiRadioProps. The onChange definition is correct as-is (other than not being an override after the other changes), because it is forwarded to the underlying input.

showTicks?: boolean;
showValue?: boolean;
tickInterval?: number;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

min and max are required in EuiRange but are optional in InputHTMLAttributes, so they must be overridden here. Also, our definition & usage of step requires it to be a number, whereas InputHTMLAttributes allows number or string values, so step requires an override too.

@pugnascotia
Copy link
Copy Markdown
Contributor Author

@chandlerprall I believe I've addressed all your comments. Please take another look.

Copy link
Copy Markdown
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@pugnascotia pugnascotia merged commit 2cc6052 into elastic:master Oct 22, 2018
@pugnascotia pugnascotia deleted the yet-more-ts-defs branch November 8, 2021 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants