Skip to content

Commit

Permalink
Merge pull request #953 from jbetancur/docs/950
Browse files Browse the repository at this point in the history
update expandableComponentProps docs
  • Loading branch information
jbetancur authored Oct 27, 2021
2 parents 630e490 + 60dcd7e commit 5e652b4
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion stories/DataTable/expandable/basic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ You'll notice that `expandableRowsComponent` has a function signtaure of `({ dat

## TypeScript

With TypeScript we'll need to use `ExpanderComponentProps` and pass it our type or interface. Here's a fully working example:
### Basic Expandable component

With TypeScript we'll need to use the `ExpanderComponentProps` type and pass it our type or interface. Here's a fully working example:

```ts
import * as React from 'react';
Expand Down Expand Up @@ -68,6 +70,37 @@ function MyComponent() {
}
```

### expandableComponentProps

expandableComponentProps allows you to pass additional props to your expander component and prevents TypeScript from complaining:

```ts
import * as React from 'react';
import DataTable, { ExpanderComponentProps } from 'react-data-table-component';

interface Row {
title: string;
director: string;
year: string;
}

interface Props extends ExpanderComponentProps<Row> {
// currently, props that extend ExpanderComponentProps must be set to optional.
someTitleProp?: string;
}

const ExpandableRowComponent: React.FC<Props> = ({ data, someTitleProp }) => {
return (
<>
<p>{someTitleProp}</p>
<p>{data.title}</p>
<p>{data.director}</p>
<p>{data.year}</p>
</>
);
};
```

## Accessibility

You can tab through expanders and use the space bar or enter keys to expand.

0 comments on commit 5e652b4

Please sign in to comment.