From b425dff5e2e3fe6dcde043a8a31cc51a6b675394 Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Tue, 19 Mar 2024 10:33:30 -0700 Subject: [PATCH 1/4] Add render prop option to allow consumers to close the mobile popover from within their content --- .../header/header_links/header_links.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/header/header_links/header_links.tsx b/src/components/header/header_links/header_links.tsx index fc3005a69cd..7b6acd05277 100644 --- a/src/components/header/header_links/header_links.tsx +++ b/src/components/header/header_links/header_links.tsx @@ -7,6 +7,7 @@ */ import React, { + ReactNode, HTMLAttributes, FunctionComponent, useState, @@ -39,7 +40,14 @@ type EuiHeaderLinksPopoverButtonProps = }; export type EuiHeaderLinksProps = CommonProps & - HTMLAttributes & { + Omit, 'children'> & { + /** + * Takes any rendered node(s), typically of `EuiHeaderLink`s. + * + * Optionally takes a render function that will pass a callback allowing you + * to close the mobile popover from within your popover content. + */ + children?: ReactNode | ((closeMobilePopover: () => void) => ReactNode); /** * Spacing between direct children */ @@ -116,6 +124,9 @@ export const EuiHeaderLinks: FunctionComponent = ({ ); + const renderedChildren = + typeof children === 'function' ? children(closeMenu) : children; + return ( {(appNavigation: string) => ( @@ -133,7 +144,7 @@ export const EuiHeaderLinks: FunctionComponent = ({ styles.gutterSizes[gutterSize], ]} > - {children} + {renderedChildren} @@ -151,7 +162,7 @@ export const EuiHeaderLinks: FunctionComponent = ({ className="euiHeaderLinks__mobileList" css={styles.euiHeaderLinks__mobileList} > - {children} + {renderedChildren} From 16007de4e21f8ee7a6c982dc2f90bcf1a7f1e9e9 Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Tue, 19 Mar 2024 10:33:34 -0700 Subject: [PATCH 2/4] Add/update tests + remove unnecessary snapshot --- .../__snapshots__/header_links.test.tsx.snap | 13 +------ .../header/header_links/header_links.test.tsx | 34 +++++++++++++++---- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/components/header/header_links/__snapshots__/header_links.test.tsx.snap b/src/components/header/header_links/__snapshots__/header_links.test.tsx.snap index 3551a61bd08..54583c09c2c 100644 --- a/src/components/header/header_links/__snapshots__/header_links.test.tsx.snap +++ b/src/components/header/header_links/__snapshots__/header_links.test.tsx.snap @@ -56,18 +56,7 @@ exports[`EuiHeaderLinks is rendered 1`] = ` `; -exports[`EuiHeaderLinks popover props is never rendered with "none" 1`] = ` - -`; - -exports[`EuiHeaderLinks popover props is rendered 1`] = ` +exports[`EuiHeaderLinks mobile menu/popover renders various popover props 1`] = `