Skip to content

Commit

Permalink
Add flexible tagName support to PanelProps (#414)
Browse files Browse the repository at this point in the history
related to (#407)

Instead of fixing the `tagName` type to `keyof HTMLElementTagNameMap`,
it has been made flexible by using a generic type.
This allows TypeScript to better infer `event` object types like
handleDrop when a specific tagName is provided in the component.

```jsx
<Panel
    onDrop={(e: DragEvent<HTMLDivElement>) => {
      if (e.currentTarget.contains(e.relatedTarget)) return;
    }}
    className={styles.PanelRow}
    defaultSize={20}
    minSize={10}
    tagName="div"
  >
    <div className={styles.Centered}>left</div>
</Panel>

```
  • Loading branch information
in-ch authored Sep 28, 2024
1 parent 7c8daad commit 909f014
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/react-resizable-panels/src/Panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ export type ImperativePanelHandle = {
resize: (size: number) => void;
};

export type PanelProps = Omit<
HTMLAttributes<keyof HTMLElementTagNameMap>,
"id" | "onResize"
> &
export type PanelProps<
T extends keyof HTMLElementTagNameMap = keyof HTMLElementTagNameMap,
> = Omit<HTMLAttributes<HTMLElementTagNameMap[T]>, "id" | "onResize"> &
PropsWithChildren<{
className?: string;
collapsedSize?: number | undefined;
Expand All @@ -71,7 +70,7 @@ export type PanelProps = Omit<
onResize?: PanelOnResize;
order?: number;
style?: object;
tagName?: keyof HTMLElementTagNameMap;
tagName?: T;
}>;

export function PanelWithForwardedRef({
Expand Down

0 comments on commit 909f014

Please sign in to comment.