Skip to content

Commit 38ca66c

Browse files
chore: revert overflowmenu child typing (#22197)
* revert overflowmenu child typing * test(overflowmenu): cover mixed children * fix(actions): update dockerfile to use npm --------- Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
1 parent 13c5c42 commit 38ca66c

7 files changed

Lines changed: 28 additions & 12 deletions

File tree

actions/add-review-labels/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ FROM node:slim
22

33
WORKDIR /usr/src/action
44
COPY . .
5-
RUN yarn install --production
5+
RUN npm install --omit=dev
66
ENTRYPOINT ["node", "/usr/src/action/index.js"]

actions/issues/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ FROM node:slim
22

33
WORKDIR /usr/src/action
44
COPY . .
5-
RUN yarn install --production
5+
RUN npm install --omit=dev
66
ENTRYPOINT ["node", "/usr/src/action/src/run.js"]

actions/promote/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ FROM node:slim
22

33
WORKDIR /usr/src/action
44
COPY . .
5-
RUN yarn install --production
5+
RUN npm install --omit=dev
66
ENTRYPOINT ["node", "/usr/src/action/index.js"]

actions/release-notifications/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ FROM node:slim
22

33
WORKDIR /usr/src/action
44
COPY . .
5-
RUN yarn install --production
5+
RUN npm install --omit=dev
66
ENTRYPOINT ["node", "/usr/src/action/index.js"]

actions/wait-for-it/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ FROM node:slim
22

33
WORKDIR /usr/src/action
44
COPY . .
5-
RUN yarn install --production
5+
RUN npm install --omit=dev
66
ENTRYPOINT ["node", "/usr/src/action/src/index.js"]
77

packages/react/src/components/OverflowMenu/OverflowMenu-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import OverflowMenuItem from '../OverflowMenuItem';
1313
import React from 'react';
1414
import userEvent from '@testing-library/user-event';
1515

16+
const MenuDivider = React.forwardRef(function MenuDivider(_props, ref) {
17+
return <li ref={ref} data-testid="menu-divider" role="separator" />;
18+
});
19+
1620
describe('OverflowMenu', () => {
1721
describe('Renders as expected', () => {
1822
const closeMenuMock = jest.fn();
@@ -250,6 +254,18 @@ describe('OverflowMenu', () => {
250254
// Check that the click handler was called only once
251255
expect(handleClick).toHaveBeenCalledTimes(1);
252256
});
257+
258+
it('should render custom child components alongside OverflowMenuItem children', () => {
259+
render(
260+
<OverflowMenu open aria-label="Overflow menu" className="extra-class">
261+
<OverflowMenuItem itemText="one" />
262+
<MenuDivider />
263+
<OverflowMenuItem itemText="two" />
264+
</OverflowMenu>
265+
);
266+
267+
expect(screen.getByTestId('menu-divider')).toBeInTheDocument();
268+
});
253269
});
254270
it('should not open menu when disabled', async () => {
255271
render(

packages/react/src/components/OverflowMenu/OverflowMenu.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import React, {
99
Children,
1010
cloneElement,
1111
forwardRef,
12+
isValidElement,
1213
RefObject,
1314
useCallback,
1415
useContext,
@@ -18,6 +19,7 @@ import React, {
1819
type ElementType,
1920
type KeyboardEvent,
2021
type MouseEvent,
22+
type ReactElement,
2123
type ReactNode,
2224
type Ref,
2325
} from 'react';
@@ -39,13 +41,10 @@ import { deprecate } from '../../prop-types/deprecate';
3941
import { mergeRefs } from '../../tools/mergeRefs';
4042
import { setupGetInstanceId } from '../../tools/setupGetInstanceId';
4143
import { IconButton, IconButtonProps } from '../IconButton';
42-
import OverflowMenuItem, {
43-
OverflowMenuItemProps,
44-
} from '../OverflowMenuItem/OverflowMenuItem';
44+
import { OverflowMenuItemProps } from '../OverflowMenuItem/OverflowMenuItem';
4545
import { useOutsideClick } from '../../internal/useOutsideClick';
4646
import { deprecateValuesWithin } from '../../prop-types/deprecateValuesWithin';
4747
import { mapPopoverAlign } from '../../tools/mapPopoverAlign';
48-
import { isComponentElement } from '../../internal';
4948

5049
const getInstanceId = setupGetInstanceId();
5150

@@ -532,9 +531,10 @@ export const OverflowMenu = forwardRef<HTMLButtonElement, OverflowMenuProps>(
532531
);
533532

534533
const childrenWithProps = Children.toArray(children).map((child, index) => {
535-
if (isComponentElement(child, OverflowMenuItem)) {
536-
return cloneElement(child, {
537-
closeMenu: child.props.closeMenu || closeMenuAndFocus,
534+
if (isValidElement(child)) {
535+
const childElement = child as ReactElement<OverflowMenuItemProps>;
536+
return cloneElement(childElement, {
537+
closeMenu: childElement.props.closeMenu || closeMenuAndFocus,
538538
handleOverflowMenuItemFocus,
539539
ref: (el: HTMLElement) => {
540540
menuItemRefs.current[index] = el;

0 commit comments

Comments
 (0)