-
Notifications
You must be signed in to change notification settings - Fork 863
[EuiFlyout] Enable shards for scoping element clicks; Optionally delay close event
#5860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
93b1445
enable shards; add default button shard for collapsible nav
thompsongl 251f4bb
elastic pattern spec
thompsongl 389e017
update comment
thompsongl ae1acc2
CL
thompsongl 83c38dc
closeOnMouseup to delay close
thompsongl e16f22d
TEMP: remove shard from collapsible
thompsongl a461586
focusTrapProps to match pattern in EuiPopover
thompsongl 4853603
initial docs
thompsongl 6ca7663
clean up
thompsongl fdfea7d
use focusTrapProps in EuiCollapsibleNav
thompsongl 8e1a91b
docs and tests
thompsongl 4df8b32
default to mousedown
thompsongl ab60381
consolidate spec children
thompsongl 3ed9263
Merge branch 'main' into flyout-shards
thompsongl 9dbc340
cypress tests
thompsongl 31d35df
update function names
thompsongl 4f349d4
remove flyout tests
thompsongl 41a02a3
update focus_trap cypress tests
thompsongl af136d2
Merge branch 'main' into flyout-shards
thompsongl a097159
remove docs
thompsongl 271606d
code comments
thompsongl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import React, { useState, useRef } from 'react'; | ||
thompsongl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import { | ||
| EuiFlyout, | ||
| EuiFlyoutBody, | ||
| EuiFlyoutHeader, | ||
| EuiButton, | ||
| EuiTitle, | ||
| EuiFlyoutFooter, | ||
| EuiSpacer, | ||
| EuiText, | ||
| EuiCode, | ||
| } from '../../../../src/components'; | ||
| import { useGeneratedHtmlId } from '../../../../src/services'; | ||
|
|
||
| export default () => { | ||
| const [isFlyoutVisible, setIsFlyoutVisible] = useState(false); | ||
| const [isFlyoutVisible2, setIsFlyoutVisible2] = useState(false); | ||
| const shardsFlyoutTitleId = useGeneratedHtmlId({ | ||
| prefix: 'shardsFlyoutTitle', | ||
| }); | ||
|
|
||
| const buttonRef = useRef(); | ||
|
|
||
| let flyout; | ||
|
|
||
| if (isFlyoutVisible) { | ||
| flyout = ( | ||
| <EuiFlyout | ||
| size="s" | ||
| onClose={() => setIsFlyoutVisible(false)} | ||
| aria-labelledby={shardsFlyoutTitleId} | ||
| ownFocus={false} | ||
| outsideClickCloses | ||
| focusTrapProps={{ shards: [buttonRef], closeOnMouseup: false }} | ||
| > | ||
| <EuiFlyoutHeader hasBorder> | ||
| <EuiTitle size="s"> | ||
| <h2 id={shardsFlyoutTitleId}> | ||
| <EuiCode>focusTrapProps.shards</EuiCode> | ||
| </h2> | ||
| </EuiTitle> | ||
| </EuiFlyoutHeader> | ||
| <EuiFlyoutBody> | ||
| <EuiText> | ||
| <p>The toggle button is considered part of this flyout.</p> | ||
| </EuiText> | ||
| </EuiFlyoutBody> | ||
| <EuiFlyoutFooter> | ||
| <EuiButton onClick={() => setIsFlyoutVisible(false)}>Close</EuiButton> | ||
| </EuiFlyoutFooter> | ||
| </EuiFlyout> | ||
| ); | ||
| } | ||
|
|
||
| let flyout2; | ||
|
|
||
| if (isFlyoutVisible2) { | ||
| flyout = ( | ||
| <EuiFlyout | ||
| size="s" | ||
| onClose={() => setIsFlyoutVisible2(false)} | ||
| aria-labelledby={shardsFlyoutTitleId} | ||
| ownFocus={false} | ||
| outsideClickCloses | ||
| focusTrapProps={{ closeOnMouseup: true }} | ||
| > | ||
| <EuiFlyoutHeader hasBorder> | ||
| <EuiTitle size="s"> | ||
| <h2 id={shardsFlyoutTitleId}> | ||
| <EuiCode>focusTrapProps.closeOnMouseup</EuiCode> | ||
| </h2> | ||
| </EuiTitle> | ||
| </EuiFlyoutHeader> | ||
| <EuiFlyoutBody> | ||
| <EuiText> | ||
| <p> | ||
| The <EuiCode>onClose</EuiCode> callback will occur on mouseup for | ||
| outside clicks. | ||
| </p> | ||
| </EuiText> | ||
| </EuiFlyoutBody> | ||
| <EuiFlyoutFooter> | ||
| <EuiButton onClick={() => setIsFlyoutVisible2(false)}> | ||
| Close | ||
| </EuiButton> | ||
| </EuiFlyoutFooter> | ||
| </EuiFlyout> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <EuiButton | ||
| buttonRef={buttonRef} | ||
| onClick={() => setIsFlyoutVisible(!isFlyoutVisible)} | ||
| > | ||
| Toggle flyout with shards | ||
| </EuiButton> | ||
| <EuiSpacer /> | ||
| {flyout} | ||
| <EuiButton onClick={() => setIsFlyoutVisible2(!isFlyoutVisible2)}> | ||
| Toggle flyout using closeOnMouseup | ||
| </EuiButton> | ||
| {flyout2} | ||
| </div> | ||
| ); | ||
| }; | ||
108 changes: 108 additions & 0 deletions
108
src/components/collapsible_nav/collapsible_nav.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
| */ | ||
|
|
||
| /// <reference types="../../../cypress/support"/> | ||
|
|
||
| import React, { useState } from 'react'; | ||
|
|
||
| import { EuiCollapsibleNav } from './collapsible_nav'; | ||
| import { EuiHeader, EuiHeaderSectionItemButton } from '../header'; | ||
| import { EuiIcon } from '../icon'; | ||
|
|
||
| const childrenDefault = ( | ||
cee-chen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <> | ||
| <button data-test-subj="itemA">Item A</button> | ||
| <button data-test-subj="itemB">Item B</button> | ||
| <button data-test-subj="itemC">Item C</button> | ||
| <input data-test-subj="itemD" /> | ||
| </> | ||
| ); | ||
|
|
||
| const Nav = ({ children = childrenDefault }) => { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
|
|
||
| return ( | ||
| <EuiHeader | ||
| style={{ zIndex: 1001 }} | ||
| position="fixed" | ||
| sections={[ | ||
| { | ||
| items: [ | ||
| <EuiCollapsibleNav | ||
| style={{ top: 48 }} | ||
| id="navSpec" | ||
| isOpen={isOpen} | ||
| button={ | ||
| <EuiHeaderSectionItemButton | ||
| data-test-subj="navSpecButton" | ||
| aria-label="Toggle main navigation" | ||
| onClick={() => setIsOpen(!isOpen)} | ||
| > | ||
| <EuiIcon type={'menu'} size="m" aria-hidden="true" /> | ||
| </EuiHeaderSectionItemButton> | ||
| } | ||
| onClose={() => setIsOpen(false)} | ||
| > | ||
| {children} | ||
| </EuiCollapsibleNav>, | ||
| ], | ||
| }, | ||
| ]} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| describe('EuiCollapsibleNav', () => { | ||
| describe('Elastic pattern', () => { | ||
| describe('Toggle button behavior', () => { | ||
| it('opens and closes nav when the main button is clicked', () => { | ||
| cy.mount(<Nav />); | ||
| cy.wait(400); | ||
| cy.get('[data-test-subj="navSpecButton"]') | ||
| .realClick() | ||
| .then(() => { | ||
| expect(cy.get('#navSpec').should('exist')); | ||
|
|
||
| cy.get('[data-test-subj="navSpecButton"]') | ||
| .realClick() | ||
| .then(() => { | ||
| expect(cy.get('#navSpec').should('not.exist')); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it('closes the nav when the overlay mask is clicked', () => { | ||
| cy.mount(<Nav />); | ||
| cy.wait(400); | ||
thompsongl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cy.get('[data-test-subj="navSpecButton"]') | ||
| .realClick() | ||
| .then(() => { | ||
| cy.get('.euiOverlayMask') | ||
| .realClick() | ||
| .then(() => { | ||
| expect(cy.get('#navSpec').should('not.exist')); | ||
| }); | ||
| }); | ||
thompsongl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| it('closes the nav when the close button is clicked', () => { | ||
| cy.mount(<Nav />); | ||
| cy.wait(400); | ||
| cy.get('[data-test-subj="navSpecButton"]') | ||
| .realClick() | ||
| .then(() => { | ||
| cy.get('[data-test-subj="euiFlyoutCloseButton"]') | ||
| .realClick() | ||
| .then(() => { | ||
| expect(cy.get('#navSpec').should('not.exist')); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.