From 93b1445862b976470ddaad59a23019b4a5f44163 Mon Sep 17 00:00:00 2001 From: Greg Thompson Date: Mon, 2 May 2022 14:05:55 -0500 Subject: [PATCH 01/19] enable shards; add default button shard for collapsible nav --- src/components/collapsible_nav/collapsible_nav.tsx | 7 +++++++ src/components/flyout/flyout.tsx | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/collapsible_nav/collapsible_nav.tsx b/src/components/collapsible_nav/collapsible_nav.tsx index 2531f2a5021..96a05f76af5 100644 --- a/src/components/collapsible_nav/collapsible_nav.tsx +++ b/src/components/collapsible_nav/collapsible_nav.tsx @@ -12,6 +12,7 @@ import React, { ReactElement, ReactNode, useEffect, + useRef, useState, } from 'react'; import classNames from 'classnames'; @@ -19,6 +20,7 @@ import { useGeneratedHtmlId, isWithinMinBreakpoint, throttle, + useCombinedRefs, } from '../../services'; import { EuiFlyout, EuiFlyoutProps } from '../flyout'; @@ -71,12 +73,15 @@ export const EuiCollapsibleNav: FunctionComponent = ({ outsideClickCloses = true, closeButtonPosition = 'outside', paddingSize = 'none', + shards = [], ...rest }) => { const flyoutID = useGeneratedHtmlId({ conditionalId: id, suffix: 'euiCollapsibleNav', }); + const buttonRef = useRef(); + const combinedButtonRef = useCombinedRefs([button?.props.ref, buttonRef]); /** * Setting the initial state of pushed based on the `type` prop @@ -136,6 +141,7 @@ export const EuiCollapsibleNav: FunctionComponent = ({ onMouseUpCapture: (e: React.MouseEvent) => { e.nativeEvent.stopImmediatePropagation(); }, + ref: combinedButtonRef, }); const flyout = ( @@ -151,6 +157,7 @@ export const EuiCollapsibleNav: FunctionComponent = ({ outsideClickCloses={outsideClickCloses} closeButtonPosition={closeButtonPosition} paddingSize={paddingSize} + shards={[buttonRef, ...shards]} {...rest} // Props dependent on internal docked status type={navIsDocked ? 'push' : 'overlay'} diff --git a/src/components/flyout/flyout.tsx b/src/components/flyout/flyout.tsx index 79aaa35ad0d..7d64d40a3ed 100644 --- a/src/components/flyout/flyout.tsx +++ b/src/components/flyout/flyout.tsx @@ -30,7 +30,7 @@ import { } from '../../services'; import { CommonProps, keysOf, PropsOfElement } from '../common'; -import { EuiFocusTrap } from '../focus_trap'; +import { EuiFocusTrap, EuiFocusTrapProps } from '../focus_trap'; import { EuiOverlayMask, EuiOverlayMaskProps } from '../overlay_mask'; import { EuiButtonIcon, EuiButtonIconPropsForButton } from '../button'; import { EuiI18n } from '../i18n'; @@ -151,6 +151,10 @@ interface _EuiFlyoutProps { */ pushMinBreakpoint?: EuiBreakpointSize | number; style?: CSSProperties; + /** + * Elements to consider part of the flyout and will not close the flyout when clicked (depends on your configuration) + */ + shards?: EuiFocusTrapProps['shards']; } const defaultElement = 'div'; @@ -189,6 +193,7 @@ export const EuiFlyout = forwardRef( outsideClickCloses, role = 'dialog', pushMinBreakpoint = 'l', + shards, ...rest }: EuiFlyoutProps, ref: @@ -362,6 +367,7 @@ export const EuiFlyout = forwardRef( disabled={isPushed} clickOutsideDisables={!ownFocus} onClickOutside={onClickOutside} + shards={shards} > )} From 251f4bbf3eb9df4076c12eac77996840b784252b Mon Sep 17 00:00:00 2001 From: Greg Thompson Date: Mon, 2 May 2022 14:06:41 -0500 Subject: [PATCH 02/19] elastic pattern spec --- .../collapsible_nav/collapsible_nav.spec.tsx | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/components/collapsible_nav/collapsible_nav.spec.tsx diff --git a/src/components/collapsible_nav/collapsible_nav.spec.tsx b/src/components/collapsible_nav/collapsible_nav.spec.tsx new file mode 100644 index 00000000000..a67152f426a --- /dev/null +++ b/src/components/collapsible_nav/collapsible_nav.spec.tsx @@ -0,0 +1,108 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +/// + +import React, { useState } from 'react'; + +import { EuiCollapsibleNav } from './collapsible_nav'; +import { EuiHeader, EuiHeaderSectionItemButton } from '../header'; +import { EuiIcon } from '../icon'; + +const childrenDefault = ( + <> + + + + + +); + +const Nav = ({ children = childrenDefault }) => { + const [isOpen, setIsOpen] = useState(false); + + return ( + setIsOpen(!isOpen)} + > +