Skip to content

Commit a6b6b0e

Browse files
fix: Menu/MenuItem/Stack types weren't accepting extra HTML props (#3955)
1 parent cce7beb commit a6b6b0e

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

src/Menu/MenuItem.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
import React, {
2-
ReactElement, ReactNode, ElementType, createElement, ComponentType,
2+
type ReactElement,
3+
type ReactNode,
4+
type ElementType,
5+
createElement,
6+
type ComponentType,
7+
type ComponentPropsWithoutRef,
38
} from 'react';
49
import classNames from 'classnames';
510
import Icon from '../Icon';
611

7-
interface MenuItemProps {
12+
interface MenuItemProps<As extends ElementType> {
813
/** Specifies that this `MenuItem` is selected inside the `SelectMenu` */
914
defaultSelected?: boolean;
1015
/** Specifies class name to append to the base element */
1116
className?: string;
1217
/** Specifies the content of the `MenuItem` */
1318
children: ReactNode;
1419
/** Specifies the base element */
15-
as?: ElementType;
20+
as?: As;
1621
/** Specifies the jsx before the content of the `MenuItem` */
1722
iconBefore?: ReactElement | ElementType;
1823
/** Specifies the jsx after the content of the `MenuItem` */
1924
iconAfter?: ReactElement | ElementType;
2025
}
21-
function MenuItem({
22-
as = 'button',
26+
27+
function MenuItem<As extends ElementType = 'button'>({
28+
as = 'button' as As,
2329
children,
2430
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2531
defaultSelected = false,
2632
iconAfter,
2733
iconBefore,
2834
...props
29-
}: MenuItemProps) {
35+
}: MenuItemProps<As> & ComponentPropsWithoutRef<As>) {
3036
const className = classNames(props.className, 'pgn__menu-item');
3137

3238
return createElement(

src/Menu/index.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import React, { ElementType, ReactNode, createElement } from 'react';
1+
import React, {
2+
createElement,
3+
type ElementType,
4+
type ReactNode,
5+
type ComponentPropsWithoutRef,
6+
} from 'react';
27
import classNames from 'classnames';
38
import useArrowKeyNavigation from '../hooks/useArrowKeyNavigationHook';
49

5-
interface MenuProps {
10+
interface MenuProps<As extends ElementType> {
611
/** Specifies class name to append to the base element */
712
className?: string;
813
/**
@@ -11,16 +16,17 @@ interface MenuProps {
1116
*/
1217
arrowKeyNavigationSelector?: string;
1318
/** Specifies the base element */
14-
as?: ElementType;
19+
as?: As;
1520
/** Specifies the content of the menu */
1621
children?: ReactNode;
1722
}
18-
function Menu({
19-
as = 'div',
23+
24+
function Menu<As extends ElementType = 'div'>({
25+
as = 'div' as As,
2026
arrowKeyNavigationSelector = 'a:not(:disabled),button:not(:disabled),input:not(:disabled)',
2127
children,
2228
...props
23-
}: MenuProps) {
29+
}: MenuProps<As> & ComponentPropsWithoutRef<As>) {
2430
const parentRef = useArrowKeyNavigation({ selectors: arrowKeyNavigationSelector });
2531
const className = classNames(props.className, 'pgn__menu');
2632

src/Stack/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { forwardRef, ForwardedRef } from 'react';
1+
import React, { forwardRef, ForwardedRef, HTMLProps } from 'react';
22
import classNames from 'classnames';
33

44
interface StackProps {
@@ -26,7 +26,7 @@ const Stack = forwardRef(({
2626
children,
2727
className,
2828
...rest
29-
}: StackProps, ref: ForwardedRef<HTMLDivElement>) => (
29+
}: StackProps & HTMLProps<HTMLDivElement>, ref: ForwardedRef<HTMLDivElement>) => (
3030
<div
3131
ref={ref}
3232
className={classNames(

0 commit comments

Comments
 (0)