Skip to content

Commit

Permalink
[EuiFocusTrap] Use react-focus-on (#3631)
Browse files Browse the repository at this point in the history
* WIP: react-focus-on

* WIP: fix GuideFullScreen

* noIsolation; onClickOutside

* euiflyout snapshot updates

* euiflyout snapshot updates

* euimodal snapshot updates

* euidatagrid snapshot updates

* euicolorpalettepicker snapshot updates

* euisuperselect snapshot updates

* euicollapsible snapshot updates

* euifocustrap snapshot updates

* allow for array snapshots with takeMountedSnapshot

* docs improvements

* default to noIsolation=true and scrollLock=false

* CL
  • Loading branch information
thompsongl authored Jul 16, 2020
1 parent ed0ef9a commit a7d7348
Show file tree
Hide file tree
Showing 23 changed files with 338 additions and 2,336 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `27.1.0`.
- Replaced `react-focus-lock` with `react-focus-on` ([#3631](https://github.com/elastic/eui/pull/3631))

## [`27.1.0`](https://github.com/elastic/eui/tree/v27.1.0)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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-view": "^2.3.2",
Expand Down
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
4 changes: 4 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,10 @@ export const FocusTrapExample = {
Use <EuiCode>clickOutsideDisables</EuiCode> to disable the focus
trap when the user clicks outside the trap.
</p>
<p>
Use <EuiCode>noIsolation=false</EuiCode> when pointer events on
outside elements should be disallowed.
</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 @@ -75,7 +75,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 @@ -90,12 +90,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 @@ -129,7 +129,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 @@ -148,12 +148,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 @@ -185,7 +185,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 @@ -198,12 +198,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 @@ -235,7 +235,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 @@ -248,12 +248,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 @@ -285,7 +285,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 @@ -345,12 +345,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 @@ -382,7 +382,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 @@ -400,12 +400,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 @@ -437,7 +437,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
Loading

0 comments on commit a7d7348

Please sign in to comment.