Skip to content

Commit

Permalink
Fix EuiKeyPadMenu component ts prop defs (#1232)
Browse files Browse the repository at this point in the history
* Fix EuiKeyPadMenu component ts prop defs

* changelog, typescript documentation
  • Loading branch information
chandlerprall authored Oct 3, 2018
1 parent edcc92c commit 5a80b10
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `4.4.0`.
**Bug fixes**

- Fixes TypeScript definitions for `EuiKeyPadMenuItem` and `EuiKeyPadMenuItemButton` ([#1232](https://github.com/elastic/eui/pull/1232))

## [`4.4.0`](https://github.com/elastic/eui/tree/v4.4.0)

Expand Down
6 changes: 3 additions & 3 deletions src/components/key_pad_menu/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference path="../common.d.ts" />

import { HTMLAttributes, MouseEventHandler, ReactNode, SFC } from 'react';
import { AnchorHTMLAttributes, ButtonHTMLAttributes, HTMLAttributes, MouseEventHandler, ReactNode, SFC } from 'react';

declare module '@elastic/eui' {

Expand All @@ -16,10 +16,10 @@ declare module '@elastic/eui' {
}

export const EuiKeyPadMenuItemButton: SFC<
CommonProps & HTMLAttributes<HTMLButtonElement> & EuiKeyPadMenuItemCommonProps
CommonProps & ButtonHTMLAttributes<HTMLButtonElement> & EuiKeyPadMenuItemCommonProps
>;

export const EuiKeyPadMenuItem: SFC<
CommonProps & HTMLAttributes<HTMLAnchorElement> & EuiKeyPadMenuItemCommonProps
CommonProps & AnchorHTMLAttributes<HTMLAnchorElement> & EuiKeyPadMenuItemCommonProps
>;
}
33 changes: 33 additions & 0 deletions wiki/component-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,36 @@ We follow Kibana's [CSS style guide][kibana-css] and [SCSS style guide][kibana-s
[docs-manual]: creating-components-manually.md
[kibana-css]: https://github.com/elastic/kibana/blob/master/style_guides/css_style_guide.md
[kibana-scss]: https://github.com/elastic/kibana/blob/master/style_guides/scss_style_guide.md

## TypeScript definitions

### Pass-through props

Many of our components use `rest parameters` and the `spread` operator to pass props through to an underlying DOM element. In those instances the component's TypeScript definition needs to properly include the target DOM element's props.

A `Foo` component that passes `...rest` through to a `button` element would have the props interface

```
// passes extra props to a button
interface FooProps extends ButtonHTMLAttributes<HTMLButtonElement> {
title: string
}
```

Some DOM elements (e.g. `div`, `span`) do not have attributes beyond the basic ones provided by all HTML elements. In these cases there isn't a specific `*HTMLAttributes<T>` interface, and you should use `HTMLAttributes<HTMLDivElement>`.

```
// passes extra props to a div
interface FooProps extends HTMLAttributes<HTMLDivElement> {
title: string
}
```

If your component forwards the `ref` through to an underlying element, the interface is further extended with `DetailedHTMLProps`

```
// passes extra props and forwards the ref to a button
interface FooProps extends DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement> {
title: string
}
```

0 comments on commit 5a80b10

Please sign in to comment.