Skip to content
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

[EuiFocusTrap] Use react-focus-on #3631

Merged
merged 20 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"prop-types": "^15.6.0",
"react-ace": "^7.0.5",
"react-beautiful-dnd": "^13.0.0",
"react-focus-lock": "^1.17.7",
"react-focus-on": "^3.4.1",
"react-input-autosize": "^2.2.2",
"react-is": "~16.3.0",
"react-virtualized": "^9.21.2",
Expand Down
6 changes: 5 additions & 1 deletion src-docs/src/services/full_screen/full_screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export const GuideFullScreen: FunctionComponent<{
{buttonText}
</EuiButton>

{fullScreen && <EuiFocusTrap>{children(setFullScreen)}</EuiFocusTrap>}
{fullScreen && (
<EuiFocusTrap noIsolation={true}>
{children(setFullScreen)}
</EuiFocusTrap>
)}
</Fragment>
);
};
2 changes: 1 addition & 1 deletion src-docs/src/views/focus_trap/focus_trap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import FormExample from '../form_compressed/form_compressed';

export default () => {
const [isDisabled, changeDisabled] = useState(false);
const [isDisabled, changeDisabled] = useState(true);

const toggleDisabled = () => changeDisabled(!isDisabled);

Expand Down
6 changes: 6 additions & 0 deletions src-docs/src/views/focus_trap/focus_trap_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export const FocusTrapExample = {
Use <EuiCode>clickOutsideDisables</EuiCode> to disable the focus
trap when the user clicks outside the trap.
</p>
<p>
Use <EuiCode>noIsolation</EuiCode> when allowing pointer events on
Copy link
Contributor

@myasonik myasonik Jul 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noIsolation isn't showing up in the props table for some reason

outside elements is needed. For instance, when used with an{' '}
<strong>EuiOverlayMask</strong> that has a click handler, set{' '}
<EuiCode>noIsolation=true</EuiCode>.
</p>
</React.Fragment>
),
props: { EuiFocusTrap },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Array [
<div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="1"
/>
<div
Expand All @@ -24,7 +24,7 @@ Array [
</div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
</div>,
Expand All @@ -37,12 +37,12 @@ Array [
<div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="1"
/>
<div
Expand Down Expand Up @@ -76,7 +76,7 @@ Array [
</div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
</div>,
Expand All @@ -91,12 +91,12 @@ Array [
<div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="1"
/>
<div
Expand Down Expand Up @@ -131,7 +131,7 @@ Array [
</div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
</div>,
Expand All @@ -150,12 +150,12 @@ Array [
<div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="1"
/>
<div
Expand Down Expand Up @@ -188,7 +188,7 @@ Array [
</div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
</div>,
Expand All @@ -201,12 +201,12 @@ Array [
<div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="1"
/>
<div
Expand Down Expand Up @@ -239,7 +239,7 @@ Array [
</div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
</div>,
Expand All @@ -252,12 +252,12 @@ Array [
<div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="1"
/>
<div
Expand Down Expand Up @@ -290,7 +290,7 @@ Array [
</div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
</div>,
Expand Down Expand Up @@ -351,12 +351,12 @@ Array [
<div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="1"
/>
<div
Expand Down Expand Up @@ -389,7 +389,7 @@ Array [
</div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
</div>,
Expand All @@ -407,12 +407,12 @@ Array [
<div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="-1"
/>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="-1"
/>
<div
Expand Down Expand Up @@ -445,7 +445,7 @@ Array [
</div>
<div
data-focus-guard="true"
style="width:1px;height:0px;padding:0;overflow:hidden;position:fixed;top:1px;left:1px"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="-1"
/>
</div>,
Expand Down
68 changes: 50 additions & 18 deletions src/components/collapsible_nav/collapsible_nav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';
import { render, mount } from 'enzyme';
import { requiredProps, takeMountedSnapshot } from '../../test';

import { EuiCollapsibleNav } from './collapsible_nav';

Expand All @@ -33,20 +33,28 @@ const propsNeededToRender = { id: 'id', isOpen: true };

describe('EuiCollapsibleNav', () => {
test('is rendered', () => {
const component = render(
const component = mount(
<EuiCollapsibleNav {...propsNeededToRender} {...requiredProps} />
);

expect(component).toMatchSnapshot();
expect(
takeMountedSnapshot(component, {
hasArrayOutput: true,
})
).toMatchSnapshot();
});

describe('props', () => {
test('onClose', () => {
const component = render(
const component = mount(
<EuiCollapsibleNav {...propsNeededToRender} onClose={() => {}} />
);

expect(component).toMatchSnapshot();
expect(
takeMountedSnapshot(component, {
hasArrayOutput: true,
})
).toMatchSnapshot();
});

test('isDocked', () => {
Expand All @@ -58,23 +66,31 @@ describe('EuiCollapsibleNav', () => {
});

test('dockedBreakpoint', () => {
const component = render(
const component = mount(
<EuiCollapsibleNav {...propsNeededToRender} dockedBreakpoint={500} />
);

expect(component).toMatchSnapshot();
expect(
takeMountedSnapshot(component, {
hasArrayOutput: true,
})
).toMatchSnapshot();
});

test('button', () => {
const component = render(
const component = mount(
<EuiCollapsibleNav {...propsNeededToRender} button={<button />} />
);

expect(component).toMatchSnapshot();
expect(
takeMountedSnapshot(component, {
hasArrayOutput: true,
})
).toMatchSnapshot();
});

test('showButtonIfDocked', () => {
const component = render(
const component = mount(
<EuiCollapsibleNav
{...propsNeededToRender}
button={<button />}
Expand All @@ -83,39 +99,55 @@ describe('EuiCollapsibleNav', () => {
/>
);

expect(component).toMatchSnapshot();
expect(
takeMountedSnapshot(component, {
hasArrayOutput: true,
})
).toMatchSnapshot();
});

test('can alter mask props with maskProps without throwing error', () => {
const component = render(
const component = mount(
<EuiCollapsibleNav
{...propsNeededToRender}
maskProps={{ headerZindexLocation: 'above' }}
/>
);

expect(component).toMatchSnapshot();
expect(
takeMountedSnapshot(component, {
hasArrayOutput: true,
})
).toMatchSnapshot();
});
});

describe('close button', () => {
test('can be hidden', () => {
const component = render(
const component = mount(
<EuiCollapsibleNav {...propsNeededToRender} showCloseButton={false} />
);

expect(component).toMatchSnapshot();
expect(
takeMountedSnapshot(component, {
hasArrayOutput: true,
})
).toMatchSnapshot();
});

test('extends EuiButtonEmpty', () => {
const component = render(
const component = mount(
<EuiCollapsibleNav
{...propsNeededToRender}
closeButtonProps={{ className: 'class', 'data-test-subj': 'test' }}
/>
);

expect(component).toMatchSnapshot();
expect(
takeMountedSnapshot(component, {
hasArrayOutput: true,
})
).toMatchSnapshot();
});
});

Expand Down
5 changes: 4 additions & 1 deletion src/components/collapsible_nav/collapsible_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ export const EuiCollapsibleNav: FunctionComponent<EuiCollapsibleNavProps> = ({
<EuiWindowEvent event="keydown" handler={onKeyDown} />
{optionalOverlay}
{/* Trap focus only when docked={false} */}
<EuiFocusTrap disabled={navIsDocked} clickOutsideDisables={true}>
<EuiFocusTrap
disabled={navIsDocked}
clickOutsideDisables={true}
noIsolation={true}>
<nav id={flyoutID} className={classes} {...rest}>
{children}
{closeButton}
Expand Down
Loading