From 361934df43fce40c0afdf9b38546e0f925c9c58d Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Wed, 17 Jun 2020 15:34:27 -0600
Subject: [PATCH 01/15] WIP: react-focus-on
---
package.json | 2 +-
src/components/focus_trap/focus_trap.tsx | 28 +++---
src/components/popover/popover.tsx | 4 +-
yarn.lock | 106 ++++++++++++++++++-----
4 files changed, 104 insertions(+), 36 deletions(-)
diff --git a/package.json b/package.json
index 64495011c554..95a72c9a8f4f 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/components/focus_trap/focus_trap.tsx b/src/components/focus_trap/focus_trap.tsx
index 2ac49c293b12..918504e6a09b 100644
--- a/src/components/focus_trap/focus_trap.tsx
+++ b/src/components/focus_trap/focus_trap.tsx
@@ -24,7 +24,8 @@ import React, {
EventHandler,
CSSProperties,
} from 'react';
-import FocusLock, { Props as ReactFocusLockProps } from 'react-focus-lock'; // eslint-disable-line import/named
+import { FocusOn } from 'react-focus-on';
+import { ReactFocusOnProps } from 'react-focus-on/dist/es5/types';
import { CommonProps } from '../common';
import { EuiOutsideClickDetector } from '../outside_click_detector';
@@ -52,19 +53,23 @@ const OutsideEventDetector: FunctionComponent = ({
*/
export type FocusTarget = HTMLElement | string | (() => HTMLElement);
-interface EuiFocusTrapProps {
+interface EuiFocusTrapInterface {
clickOutsideDisables?: boolean;
initialFocus?: FocusTarget;
style?: CSSProperties;
+ disabled?: boolean;
}
-type Props = CommonProps & ReactFocusLockProps & EuiFocusTrapProps;
+export interface EuiFocusTrapProps
+ extends CommonProps,
+ Omit, // Inverted `disabled` prop used instead
+ EuiFocusTrapInterface {}
interface State {
hasBeenDisabledByClick: boolean;
}
-export class EuiFocusTrap extends Component {
+export class EuiFocusTrap extends Component {
state: State = {
hasBeenDisabledByClick: false,
};
@@ -76,7 +81,7 @@ export class EuiFocusTrap extends Component {
this.setInitialFocus(this.props.initialFocus);
}
- componentDidUpdate(prevProps: Props) {
+ componentDidUpdate(prevProps: EuiFocusTrapProps) {
if (prevProps.disabled === true && this.props.disabled === false) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({ hasBeenDisabledByClick: false });
@@ -92,7 +97,7 @@ export class EuiFocusTrap extends Component {
node = (initialFocus as () => HTMLElement)();
}
if (!node) return;
- // `data-autofocus` is part of the 'react-focus-lock' API
+ // `data-autofocus` is part of the 'react-focus-on' API
node.setAttribute('data-autofocus', 'true');
};
@@ -137,13 +142,12 @@ export class EuiFocusTrap extends Component {
clickOutsideDisables = false,
disabled = false,
returnFocus = true,
- style,
...rest
} = this.props;
const isDisabled = disabled || this.state.hasBeenDisabledByClick;
const lockProps = {
- disabled: isDisabled,
returnFocus,
+ enabled: !isDisabled,
...rest,
};
return clickOutsideDisables ? (
@@ -151,15 +155,13 @@ export class EuiFocusTrap extends Component {
isDisabled={isDisabled}
onOutsideClick={this.handleOutsideClick}>
-
+
{children}
-
+
) : (
-
- {children}
-
+ {children}
);
}
}
diff --git a/src/components/popover/popover.tsx b/src/components/popover/popover.tsx
index d67f8982af05..e96f718ddbf5 100644
--- a/src/components/popover/popover.tsx
+++ b/src/components/popover/popover.tsx
@@ -30,7 +30,7 @@ import tabbable from 'tabbable';
import { CommonProps, NoArgCallback } from '../common';
import { FocusTarget, EuiFocusTrap } from '../focus_trap';
-import { Props as ReactFocusLockProps } from 'react-focus-lock'; // eslint-disable-line import/named
+import { ReactFocusOnProps } from 'react-focus-on/dist/es5/types';
import {
cascadingMenuKeys,
@@ -140,7 +140,7 @@ export interface EuiPopoverProps {
/**
* Function callback for when the focus trap is deactivated
*/
- onTrapDeactivation?: ReactFocusLockProps['onDeactivation'];
+ onTrapDeactivation?: ReactFocusOnProps['onDeactivation'];
/**
* Distance away from the anchor that the popover will render.
diff --git a/yarn.lock b/yarn.lock
index 53f2187a1503..ba18b9fd54d9 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1921,6 +1921,13 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"
+aria-hidden@^1.1.1:
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/aria-hidden/-/aria-hidden-1.1.1.tgz#0c356026d3f65e2bd487a3adb73f0c586be2c37e"
+ integrity sha512-M7zYxCcOQPOaxGHoMTKUFD2UNcVFTp9ycrdStLcTPLf8zgTXC3+YcGe+UuzSh5X1BX/0/PtS8xTNy4xyH/6xtw==
+ dependencies:
+ tslib "^1.0.0"
+
aria-query@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-3.0.0.tgz#65b3fcc1ca1155a8c9ae64d6eee297f15d5133cc"
@@ -6447,10 +6454,10 @@ flush-write-stream@^1.0.0:
inherits "^2.0.1"
readable-stream "^2.0.4"
-focus-lock@^0.5.2:
- version "0.5.4"
- resolved "https://registry.yarnpkg.com/focus-lock/-/focus-lock-0.5.4.tgz#537644d61b9e90fd97075aa680b8add1de24e819"
- integrity sha512-A9ngdb0NyI6UygBQ0eD+p8SpLWTkdEDn67I3EGUUcDUfxH694mLA/xBWwhWhoj/2YLtsv2EoQdAx9UOKs8d/ZQ==
+focus-lock@^0.6.7:
+ version "0.6.8"
+ resolved "https://registry.yarnpkg.com/focus-lock/-/focus-lock-0.6.8.tgz#61985fadfa92f02f2ee1d90bc738efaf7f3c9f46"
+ integrity sha512-vkHTluRCoq9FcsrldC0ulQHiyBYgVJB2CX53I8r0nTC6KnEij7Of0jpBspjt3/CuNb6fyoj3aOh9J2HgQUM0og==
follow-redirects@1.5.10:
version "1.5.10"
@@ -6796,6 +6803,11 @@ get-func-name@^2.0.0:
resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"
integrity sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=
+get-nonce@^1.0.0:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/get-nonce/-/get-nonce-1.0.1.tgz#fdf3f0278073820d2ce9426c18f07481b1e0cdf3"
+ integrity sha512-FJhYRoDaiatfEkUK8HKlicmu/3SGFD51q3itKDGoSTysQJBnfOcxU5GxnhE1E6soB76MbT0MBtnKJuXyAx+96Q==
+
get-port@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-5.1.1.tgz#0469ed07563479de6efb986baf053dcd7d4e3193"
@@ -12962,13 +12974,12 @@ react-beautiful-dnd@^13.0.0:
redux "^4.0.4"
use-memo-one "^1.1.1"
-react-clientside-effect@^1.2.0:
- version "1.2.0"
- resolved "https://registry.yarnpkg.com/react-clientside-effect/-/react-clientside-effect-1.2.0.tgz#db823695f75e9616a5e4dd6d908e5ea627fb2516"
- integrity sha512-cVIsGG7SNHsQsCP4+fw7KFUB0HiYiU8hbvL640XaLCbZ31aK8/lj0qOKJ2K+xRjuQz/IM4Q4qclI0aEqTtcXtA==
+react-clientside-effect@^1.2.2:
+ version "1.2.2"
+ resolved "https://registry.yarnpkg.com/react-clientside-effect/-/react-clientside-effect-1.2.2.tgz#6212fb0e07b204e714581dd51992603d1accc837"
+ integrity sha512-nRmoyxeok5PBO6ytPvSjKp9xwXg9xagoTK1mMjwnQxqM9Hd7MNPl+LS1bOSOe+CV2+4fnEquc7H/S8QD3q697A==
dependencies:
"@babel/runtime" "^7.0.0"
- shallowequal "^1.1.0"
react-docgen@^4.1.0:
version "4.1.1"
@@ -12993,15 +13004,29 @@ react-dom@^16.12.0:
prop-types "^15.6.2"
scheduler "^0.18.0"
-react-focus-lock@^1.17.7:
- version "1.17.7"
- resolved "https://registry.yarnpkg.com/react-focus-lock/-/react-focus-lock-1.17.7.tgz#ea7fd05d88d0e32833cad241f9333c124c35ba9a"
- integrity sha512-zDCqkIhuuHCCmWzJghAz6EM6ROx8/sHhQJWjmO6oteQRHX+xTCE5FWIu3zLB5UiUa5eLd66tTh4Fs8YDp0G+6Q==
+react-focus-lock@^2.3.1:
+ version "2.3.1"
+ resolved "https://registry.yarnpkg.com/react-focus-lock/-/react-focus-lock-2.3.1.tgz#9d5d85899773609c7eefa4fc54fff6a0f5f2fc47"
+ integrity sha512-j15cWLPzH0gOmRrUg01C09Peu8qbcdVqr6Bjyfxj80cNZmH+idk/bNBYEDSmkAtwkXI+xEYWSmHYqtaQhZ8iUQ==
dependencies:
"@babel/runtime" "^7.0.0"
- focus-lock "^0.5.2"
+ focus-lock "^0.6.7"
prop-types "^15.6.2"
- react-clientside-effect "^1.2.0"
+ react-clientside-effect "^1.2.2"
+ use-callback-ref "^1.2.1"
+ use-sidecar "^1.0.1"
+
+react-focus-on@^3.4.1:
+ version "3.4.1"
+ resolved "https://registry.yarnpkg.com/react-focus-on/-/react-focus-on-3.4.1.tgz#e184f3c44185e341598c5d9d44b2987ad459b240"
+ integrity sha512-KGRIl0iAu+1k1dcX7eQCXF5ZR/nl+XyXN5Ukw/OY80vLaK2b6vDzNqnX0HdYbY5xSUhIRUvMWEzSsdEyPjvk/Q==
+ dependencies:
+ aria-hidden "^1.1.1"
+ react-focus-lock "^2.3.1"
+ react-remove-scroll "^2.3.0"
+ react-style-singleton "^2.1.0"
+ use-callback-ref "^1.2.3"
+ use-sidecar "^1.0.1"
react-input-autosize@^2.2.2:
version "2.2.2"
@@ -13066,6 +13091,25 @@ react-redux@^7.1.1:
prop-types "^15.7.2"
react-is "^16.9.0"
+react-remove-scroll-bar@^2.1.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/react-remove-scroll-bar/-/react-remove-scroll-bar-2.1.0.tgz#edafe9b42a42c0dad9bdd10712772a1f9a39d7b9"
+ integrity sha512-5X5Y5YIPjIPrAoMJxf6Pfa7RLNGCgwZ95TdnVPgPuMftRfO8DaC7F4KP1b5eiO8hHbe7u+wZNDbYN5WUTpv7+g==
+ dependencies:
+ react-style-singleton "^2.1.0"
+ tslib "^1.0.0"
+
+react-remove-scroll@^2.3.0:
+ version "2.3.0"
+ resolved "https://registry.yarnpkg.com/react-remove-scroll/-/react-remove-scroll-2.3.0.tgz#3af06fe2f7130500704b676cdef94452c08fe593"
+ integrity sha512-UqVimLeAe+5EHXKfsca081hAkzg3WuDmoT9cayjBegd6UZVhlTEchleNp9J4TMGkb/ftLve7ARB5Wph+HJ7A5g==
+ dependencies:
+ react-remove-scroll-bar "^2.1.0"
+ react-style-singleton "^2.1.0"
+ tslib "^1.0.0"
+ use-callback-ref "^1.2.3"
+ use-sidecar "^1.0.1"
+
react-router-dom@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-5.2.0.tgz#9e65a4d0c45e13289e66c7b17c7e175d0ea15662"
@@ -13100,6 +13144,15 @@ react-router@5.2.0, react-router@^5.2.0:
tiny-invariant "^1.0.2"
tiny-warning "^1.0.0"
+react-style-singleton@^2.1.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/react-style-singleton/-/react-style-singleton-2.1.0.tgz#7396885332e9729957f9df51f08cadbfc164e1c4"
+ integrity sha512-DH4ED+YABC1dhvSDYGGreAHmfuTXj6+ezT3CmHoqIEfxNgEYfIMoOtmbRp42JsUst3IPqBTDL+8r4TF7EWhIHw==
+ dependencies:
+ get-nonce "^1.0.0"
+ invariant "^2.2.4"
+ tslib "^1.0.0"
+
react-test-renderer@^16.0.0-0:
version "16.8.2"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.8.2.tgz#3ce0bf12aa211116612fda01a886d6163c9c459b"
@@ -14381,11 +14434,6 @@ shallow-clone@^1.0.0:
kind-of "^5.0.0"
mixin-object "^2.0.1"
-shallowequal@^1.1.0:
- version "1.1.0"
- resolved "https://registry.yarnpkg.com/shallowequal/-/shallowequal-1.1.0.tgz#188d521de95b9087404fd4dcb68b13df0ae4e7f8"
- integrity sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==
-
shebang-command@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"
@@ -15610,6 +15658,11 @@ ts-debounce@^1.0.0:
resolved "https://registry.yarnpkg.com/ts-debounce/-/ts-debounce-1.0.0.tgz#e433301744ba75fe25466f7f23e1382c646aae6a"
integrity sha512-V+IzWj418IoqqxVJD6I0zjPtgIyvAJ8VyViqzcxZ0JRiJXsi5mCmy1yUKkWd2gUygT28a8JsVFCgqdrf2pLUHQ==
+tslib@^1.0.0:
+ version "1.13.0"
+ resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043"
+ integrity sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==
+
tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
@@ -15961,11 +16014,24 @@ url@^0.11.0, url@~0.11.0:
punycode "1.3.2"
querystring "0.2.0"
+use-callback-ref@^1.2.1, use-callback-ref@^1.2.3:
+ version "1.2.4"
+ resolved "https://registry.yarnpkg.com/use-callback-ref/-/use-callback-ref-1.2.4.tgz#d86d1577bfd0b955b6e04aaf5971025f406bea3c"
+ integrity sha512-rXpsyvOnqdScyied4Uglsp14qzag1JIemLeTWGKbwpotWht57hbP78aNT+Q4wdFKQfQibbUX4fb6Qb4y11aVOQ==
+
use-memo-one@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/use-memo-one/-/use-memo-one-1.1.1.tgz#39e6f08fe27e422a7d7b234b5f9056af313bd22c"
integrity sha512-oFfsyun+bP7RX8X2AskHNTxu+R3QdE/RC5IefMbqptmACAA/gfol1KDD5KRzPsGMa62sWxGZw+Ui43u6x4ddoQ==
+use-sidecar@^1.0.1:
+ version "1.0.2"
+ resolved "https://registry.yarnpkg.com/use-sidecar/-/use-sidecar-1.0.2.tgz#e72f582a75842f7de4ef8becd6235a4720ad8af6"
+ integrity sha512-287RZny6m5KNMTb/Kq9gmjafi7lQL0YHO1lYolU6+tY1h9+Z3uCtkJJ3OSOq3INwYf2hBryCcDh4520AhJibMA==
+ dependencies:
+ detect-node "^2.0.4"
+ tslib "^1.9.3"
+
use@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/use/-/use-2.0.2.tgz#ae28a0d72f93bf22422a18a2e379993112dec8e8"
From 319ac9c9523f5de2262844620b4d24644e0d4c97 Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Wed, 17 Jun 2020 15:34:58 -0600
Subject: [PATCH 02/15] WIP: fix GuideFullScreen
---
src-docs/src/services/full_screen/full_screen.tsx | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src-docs/src/services/full_screen/full_screen.tsx b/src-docs/src/services/full_screen/full_screen.tsx
index 67895ead2ef5..3356ff59f7e7 100644
--- a/src-docs/src/services/full_screen/full_screen.tsx
+++ b/src-docs/src/services/full_screen/full_screen.tsx
@@ -46,7 +46,11 @@ export const GuideFullScreen: FunctionComponent<{
{buttonText}
- {fullScreen && {children(setFullScreen)} }
+ {fullScreen && (
+
+ {children(setFullScreen)}
+
+ )}
);
};
From 72af3a476889c5f05ef1f00dbe6148cb91943f17 Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Mon, 6 Jul 2020 12:24:55 -0700
Subject: [PATCH 03/15] noIsolation; onClickOutside
---
.../src/views/focus_trap/focus_trap_example.js | 6 ++++++
.../collapsible_nav/collapsible_nav.tsx | 5 ++++-
src/components/focus_trap/focus_trap.tsx | 15 +++++++++------
3 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/src-docs/src/views/focus_trap/focus_trap_example.js b/src-docs/src/views/focus_trap/focus_trap_example.js
index 89de1fad48f5..e11a382be51d 100644
--- a/src-docs/src/views/focus_trap/focus_trap_example.js
+++ b/src-docs/src/views/focus_trap/focus_trap_example.js
@@ -47,6 +47,12 @@ export const FocusTrapExample = {
Use clickOutsideDisables to disable the focus
trap when the user clicks outside the trap.
+
+ Use noIsolation when allowing pointer events on
+ outside elements is needed. For instance, when used with an{' '}
+ EuiOverlayMask that has a click handler, set{' '}
+ noIsolation=true .
+
),
props: { EuiFocusTrap },
diff --git a/src/components/collapsible_nav/collapsible_nav.tsx b/src/components/collapsible_nav/collapsible_nav.tsx
index c9b5f745d0e5..8fbf30f1f745 100644
--- a/src/components/collapsible_nav/collapsible_nav.tsx
+++ b/src/components/collapsible_nav/collapsible_nav.tsx
@@ -193,7 +193,10 @@ export const EuiCollapsibleNav: FunctionComponent = ({
{optionalOverlay}
{/* Trap focus only when docked={false} */}
-
+
{children}
{closeButton}
diff --git a/src/components/focus_trap/focus_trap.tsx b/src/components/focus_trap/focus_trap.tsx
index 918504e6a09b..c75518902f59 100644
--- a/src/components/focus_trap/focus_trap.tsx
+++ b/src/components/focus_trap/focus_trap.tsx
@@ -123,9 +123,13 @@ export class EuiFocusTrap extends Component {
this.preventFocusExit &&
this.lastInterceptedEvent &&
event.target === this.lastInterceptedEvent.target
- )
+ ) {
return;
+ }
this.toggleDisabled(true);
+ if (this.props.onClickOutside) {
+ this.props.onClickOutside(event as MouseEvent);
+ }
};
// Event handler to capture events from within the focus trap subtree and
@@ -142,10 +146,11 @@ export class EuiFocusTrap extends Component {
clickOutsideDisables = false,
disabled = false,
returnFocus = true,
+ onClickOutside,
...rest
} = this.props;
const isDisabled = disabled || this.state.hasBeenDisabledByClick;
- const lockProps = {
+ const focusOnProps = {
returnFocus,
enabled: !isDisabled,
...rest,
@@ -155,13 +160,11 @@ export class EuiFocusTrap extends Component {
isDisabled={isDisabled}
onOutsideClick={this.handleOutsideClick}>
-
- {children}
-
+ {children}
) : (
- {children}
+ {children}
);
}
}
From d6f538b8c125eb0a06c24c7f017d57324258f4fb Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Mon, 6 Jul 2020 13:43:42 -0700
Subject: [PATCH 04/15] euiflyout snapshot updates
---
.../flyout/__snapshots__/flyout.test.tsx.snap | 86 +++++++++----------
src/components/flyout/flyout.test.tsx | 64 +++++++-------
src/components/flyout/flyout.tsx | 4 +-
3 files changed, 81 insertions(+), 73 deletions(-)
diff --git a/src/components/flyout/__snapshots__/flyout.test.tsx.snap b/src/components/flyout/__snapshots__/flyout.test.tsx.snap
index f19ba8d840b3..a616361edebb 100644
--- a/src/components/flyout/__snapshots__/flyout.test.tsx.snap
+++ b/src/components/flyout/__snapshots__/flyout.test.tsx.snap
@@ -4,12 +4,12 @@ exports[`EuiFlyout is rendered 1`] = `
@@ -48,12 +48,12 @@ exports[`EuiFlyout props accepts div props 1`] = `
@@ -91,12 +91,12 @@ exports[`EuiFlyout props close button is not rendered 1`] = `
@@ -120,12 +120,12 @@ exports[`EuiFlyout props max width can be set to a custom number 1`] = `
@@ -163,12 +163,12 @@ exports[`EuiFlyout props max width can be set to a custom value and measurement
@@ -206,12 +206,12 @@ exports[`EuiFlyout props max width can be set to a default 1`] = `
`;
exports[`EuiFlyout props ownFocus can alter mask props with maskProps without throwing error 1`] = `
-Array [
-
,
+
+
+
`;
exports[`EuiFlyout props ownFocus is rendered 1`] = `
-Array [
-
,
+
+
+
`;
exports[`EuiFlyout props size l is rendered 1`] = `
@@ -380,12 +380,12 @@ exports[`EuiFlyout props size m is rendered 1`] = `
@@ -422,12 +422,12 @@ exports[`EuiFlyout props size s is rendered 1`] = `
diff --git a/src/components/flyout/flyout.test.tsx b/src/components/flyout/flyout.test.tsx
index 67fab8103a5a..0463cf1d5a2c 100644
--- a/src/components/flyout/flyout.test.tsx
+++ b/src/components/flyout/flyout.test.tsx
@@ -18,8 +18,8 @@
*/
import React from 'react';
-import { render } from 'enzyme';
-import { requiredProps } from '../../test';
+import { render, mount } from 'enzyme';
+import { requiredProps, takeMountedSnapshot } from '../../test';
import { EuiFlyout, EuiFlyoutSize } from './flyout';
@@ -33,20 +33,18 @@ const SIZES: EuiFlyoutSize[] = ['s', 'm', 'l'];
describe('EuiFlyout', () => {
test('is rendered', () => {
- const component = render(
+ const component = mount(
{}} />
);
- expect(component).toMatchSnapshot();
+ expect(takeMountedSnapshot(component)).toMatchSnapshot();
});
describe('props', () => {
test('close button is not rendered', () => {
- const component = render(
- {}} hideCloseButton />
- );
+ const component = mount( {}} hideCloseButton />);
- expect(component).toMatchSnapshot();
+ expect(takeMountedSnapshot(component)).toMatchSnapshot();
});
describe('closeButtonLabel', () => {
@@ -73,66 +71,74 @@ describe('EuiFlyout', () => {
});
test('accepts div props', () => {
- const component = render( {}} id="imaflyout" />);
+ const component = mount( {}} id="imaflyout" />);
- expect(component).toMatchSnapshot();
+ expect(takeMountedSnapshot(component)).toMatchSnapshot();
});
describe('size', () => {
SIZES.forEach(size => {
it(`${size} is rendered`, () => {
- const component = render(
- {}} size={size} />
- );
+ const component = mount( {}} size={size} />);
- expect(component).toMatchSnapshot();
+ expect(takeMountedSnapshot(component)).toMatchSnapshot();
});
});
});
describe('max width', () => {
test('can be set to a default', () => {
- const component = render(
+ const component = mount(
{}} maxWidth={true} />
);
- expect(component).toMatchSnapshot();
+ expect(takeMountedSnapshot(component)).toMatchSnapshot();
});
test('can be set to a custom number', () => {
- const component = render(
+ const component = mount(
{}} maxWidth={1024} />
);
- expect(component).toMatchSnapshot();
+ expect(takeMountedSnapshot(component)).toMatchSnapshot();
});
test('can be set to a custom value and measurement', () => {
- const component = render(
+ const component = mount(
{}} maxWidth="24rem" />
);
- expect(component).toMatchSnapshot();
+ expect(takeMountedSnapshot(component)).toMatchSnapshot();
});
});
describe('ownFocus', () => {
test('is rendered', () => {
- const component = render( {}} ownFocus />);
+ const component = mount(
+ // Workaround for `takeMountedSnapshot` only returning the first element.
+ // Output is an array, which is here replaced in the snapshot with `main`
+
+ {}} ownFocus={true} />
+
+ );
- expect(component).toMatchSnapshot();
+ expect(takeMountedSnapshot(component)).toMatchSnapshot();
});
test('can alter mask props with maskProps without throwing error', () => {
- const component = render(
- {}}
- ownFocus
- maskProps={{ headerZindexLocation: 'above' }}
- />
+ const component = mount(
+ // Workaround for `takeMountedSnapshot` only returning the first element.
+ // Output is an array, which is here replaced in the snapshot with `main`
+
+ {}}
+ ownFocus={true}
+ maskProps={{ headerZindexLocation: 'above' }}
+ />
+
);
- expect(component).toMatchSnapshot();
+ expect(takeMountedSnapshot(component)).toMatchSnapshot();
});
});
});
diff --git a/src/components/flyout/flyout.tsx b/src/components/flyout/flyout.tsx
index 1077bd16a170..95b47d0bd09c 100644
--- a/src/components/flyout/flyout.tsx
+++ b/src/components/flyout/flyout.tsx
@@ -174,7 +174,9 @@ export const EuiFlyout: FunctionComponent = ({
{optionalOverlay}
{/* Trap focus even when ownFocus={false}, otherwise closing the flyout won't return focus
to the originating button */}
- {flyoutContent}
+
+ {flyoutContent}
+
);
};
From ea484547eb3652485b8d7548f11316e3d6c28618 Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Mon, 6 Jul 2020 14:28:35 -0700
Subject: [PATCH 05/15] euiflyout snapshot updates
---
.../flyout/__snapshots__/flyout.test.tsx.snap | 16 +++++------
src/components/flyout/flyout.test.tsx | 28 ++++++++-----------
2 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/src/components/flyout/__snapshots__/flyout.test.tsx.snap b/src/components/flyout/__snapshots__/flyout.test.tsx.snap
index a616361edebb..959e4f1f3045 100644
--- a/src/components/flyout/__snapshots__/flyout.test.tsx.snap
+++ b/src/components/flyout/__snapshots__/flyout.test.tsx.snap
@@ -245,8 +245,8 @@ exports[`EuiFlyout props max width can be set to a default 1`] = `
`;
exports[`EuiFlyout props ownFocus can alter mask props with maskProps without throwing error 1`] = `
-
-
+Array [
+
,
-
+ ,
+]
`;
exports[`EuiFlyout props ownFocus is rendered 1`] = `
-
-
+Array [
+
,
-
+
,
+]
`;
exports[`EuiFlyout props size l is rendered 1`] = `
diff --git a/src/components/flyout/flyout.test.tsx b/src/components/flyout/flyout.test.tsx
index 0463cf1d5a2c..c6aecffdfc88 100644
--- a/src/components/flyout/flyout.test.tsx
+++ b/src/components/flyout/flyout.test.tsx
@@ -115,30 +115,26 @@ describe('EuiFlyout', () => {
describe('ownFocus', () => {
test('is rendered', () => {
const component = mount(
- // Workaround for `takeMountedSnapshot` only returning the first element.
- // Output is an array, which is here replaced in the snapshot with `main`
-
- {}} ownFocus={true} />
-
+
{}} ownFocus={true} />
);
- expect(takeMountedSnapshot(component)).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(component, { hasArrayOutput: true })
+ ).toMatchSnapshot();
});
test('can alter mask props with maskProps without throwing error', () => {
const component = mount(
- // Workaround for `takeMountedSnapshot` only returning the first element.
- // Output is an array, which is here replaced in the snapshot with `main`
-
- {}}
- ownFocus={true}
- maskProps={{ headerZindexLocation: 'above' }}
- />
-
+ {}}
+ ownFocus={true}
+ maskProps={{ headerZindexLocation: 'above' }}
+ />
);
- expect(takeMountedSnapshot(component)).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(component, { hasArrayOutput: true })
+ ).toMatchSnapshot();
});
});
});
From d6e02ea1455d7560711936d5e43e90e3af584296 Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Mon, 6 Jul 2020 14:29:15 -0700
Subject: [PATCH 06/15] euimodal snapshot updates
---
.../__snapshots__/confirm_modal.test.tsx.snap | 12 +++++------
.../modal/__snapshots__/modal.test.tsx.snap | 6 +++---
src/components/modal/confirm_modal.test.tsx | 20 +++++++++++++------
src/components/modal/modal.test.tsx | 8 +++++---
4 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/src/components/modal/__snapshots__/confirm_modal.test.tsx.snap b/src/components/modal/__snapshots__/confirm_modal.test.tsx.snap
index 1f40a73883a1..0116ce17d1f6 100644
--- a/src/components/modal/__snapshots__/confirm_modal.test.tsx.snap
+++ b/src/components/modal/__snapshots__/confirm_modal.test.tsx.snap
@@ -4,12 +4,12 @@ exports[`EuiConfirmModal renders EuiConfirmModal 1`] = `
Array [
,
,
,
,
]
@@ -110,12 +110,12 @@ exports[`EuiConfirmModal renders EuiConfirmModal without EuiModalBody, if empty
Array [
,
,
,
,
]
diff --git a/src/components/modal/__snapshots__/modal.test.tsx.snap b/src/components/modal/__snapshots__/modal.test.tsx.snap
index f6a48707fd4a..81b29c3435b6 100644
--- a/src/components/modal/__snapshots__/modal.test.tsx.snap
+++ b/src/components/modal/__snapshots__/modal.test.tsx.snap
@@ -4,12 +4,12 @@ exports[`renders EuiModal 1`] = `
Array [
,
,
,
,
]
diff --git a/src/components/modal/confirm_modal.test.tsx b/src/components/modal/confirm_modal.test.tsx
index 84bad6a0013a..ec643169249c 100644
--- a/src/components/modal/confirm_modal.test.tsx
+++ b/src/components/modal/confirm_modal.test.tsx
@@ -18,9 +18,13 @@
*/
import React from 'react';
-import { mount, render } from 'enzyme';
+import { mount } from 'enzyme';
-import { findTestSubject, requiredProps } from '../../test';
+import {
+ findTestSubject,
+ requiredProps,
+ takeMountedSnapshot,
+} from '../../test';
import { keys } from '../../services';
import {
@@ -39,7 +43,7 @@ beforeEach(() => {
describe('EuiConfirmModal', () => {
test('renders EuiConfirmModal', () => {
- const component = render(
+ const component = mount(
{}}
@@ -50,11 +54,13 @@ describe('EuiConfirmModal', () => {
This is a confirmation modal example
);
- expect(component).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(component, { hasArrayOutput: true })
+ ).toMatchSnapshot();
});
test('renders EuiConfirmModal without EuiModalBody, if empty', () => {
- const component = render(
+ const component = mount(
{}}
@@ -64,7 +70,9 @@ describe('EuiConfirmModal', () => {
{...requiredProps}
/>
);
- expect(component).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(component, { hasArrayOutput: true })
+ ).toMatchSnapshot();
});
test('onConfirm', () => {
diff --git a/src/components/modal/modal.test.tsx b/src/components/modal/modal.test.tsx
index ba4fc0fa4d4c..18680529aeed 100644
--- a/src/components/modal/modal.test.tsx
+++ b/src/components/modal/modal.test.tsx
@@ -18,8 +18,8 @@
*/
import React from 'react';
-import { render } from 'enzyme';
-import { requiredProps } from '../../test/required_props';
+import { mount } from 'enzyme';
+import { requiredProps, takeMountedSnapshot } from '../../test';
import { EuiModal } from './modal';
@@ -30,5 +30,7 @@ test('renders EuiModal', () => {
);
- expect(render(component)).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(mount(component), { hasArrayOutput: true })
+ ).toMatchSnapshot();
});
From 3aef4fd4098dc51620cf008c9dd3706f13de1e06 Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Mon, 6 Jul 2020 14:32:19 -0700
Subject: [PATCH 07/15] euidatagrid snapshot updates
---
src/components/datagrid/__snapshots__/data_grid.test.tsx.snap | 4 ----
1 file changed, 4 deletions(-)
diff --git a/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap b/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap
index 2e43c1c11e92..e6e34f9d24df 100644
--- a/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap
+++ b/src/components/datagrid/__snapshots__/data_grid.test.tsx.snap
@@ -179,7 +179,6 @@ Array [
/>,
,
,
,
`;
-
-exports[`EuiColorPalettePicker more props are propagated to each option 2`] = `
-
-
-
- Palette 1
-
-
- ,
- "inputDisplay":
,
- "value": "paletteFixed",
- },
- Object {
- "className": "paletteLinearClass",
- "data-test-subj": "gradient-data-test-subj",
- "dropdownDisplay":
-
- Linear Gradient
-
-
-
,
- "inputDisplay":
,
- "value": "paletteLinear",
- },
- Object {
- "data-test-subj": "gradient-with-stops-data-test-subj",
- "dropdownDisplay":
-
- Linear Gradient with stops
-
-
-
,
- "inputDisplay":
,
- "value": "paletteLinearStops",
- },
- Object {
- "data-test-subj": "text-data-test-subj",
- "dropdownDisplay":
- Plain text as a custom option
-
,
- "inputDisplay": "Plain text as a custom option",
- "value": "custom",
- },
- ]
- }
- readOnly={false}
- valueOfSelected="paletteFixed"
- >
-
-
- Palette 1
-
-
- ,
- "inputDisplay":
,
- "value": "paletteFixed",
- },
- Object {
- "className": "paletteLinearClass",
- "data-test-subj": "gradient-data-test-subj",
- "dropdownDisplay":
-
- Linear Gradient
-
-
-
,
- "inputDisplay":
,
- "value": "paletteLinear",
- },
- Object {
- "data-test-subj": "gradient-with-stops-data-test-subj",
- "dropdownDisplay":
-
- Linear Gradient with stops
-
-
-
,
- "inputDisplay":
,
- "value": "paletteLinearStops",
- },
- Object {
- "data-test-subj": "text-data-test-subj",
- "dropdownDisplay":
- Plain text as a custom option
-
,
- "inputDisplay": "Plain text as a custom option",
- "value": "custom",
- },
- ]
- }
- readOnly={false}
- value="paletteFixed"
- />
- }
- className="euiSuperSelect"
- closePopover={[Function]}
- display="block"
- hasArrow={false}
- isOpen={true}
- ownFocus={false}
- panelClassName="euiSuperSelect__popoverPanel"
- panelPaddingSize="none"
- popoverRef={[Function]}
- >
-
-
-
,
- "inputDisplay":
,
- "value": "paletteFixed",
- },
- Object {
- "className": "paletteLinearClass",
- "data-test-subj": "gradient-data-test-subj",
- "dropdownDisplay":
-
- Linear Gradient
-
-
-
,
- "inputDisplay":
,
- "value": "paletteLinear",
- },
- Object {
- "data-test-subj": "gradient-with-stops-data-test-subj",
- "dropdownDisplay":
-
- Linear Gradient with stops
-
-
-
,
- "inputDisplay":
,
- "value": "paletteLinearStops",
- },
- Object {
- "data-test-subj": "text-data-test-subj",
- "dropdownDisplay":
- Plain text as a custom option
-
,
- "inputDisplay": "Plain text as a custom option",
- "value": "custom",
- },
- ]
- }
- readOnly={false}
- value="paletteFixed"
- >
-
-
-
-
-
-
- ,
- }
- }
- >
-
- }
- >
- Select an option:
-
- , is selected
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- You are in a form selector of 4 items and must select a single option. Use the up and down keys to navigate or escape to close.
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- >
-
-
-
-
-
-
-
-
-
-
-
-
-
- You are in a form selector of 4 items and must select a single option. Use the up and down keys to navigate or escape to close.
-
-
-
-
-
-
-
-
-
-
- }
- onActivation={[Function]}
- onDeactivation={[Function]}
- persistentFocus={false}
- >
-
-
-
-
-
- You are in a form selector of 4 items and must select a single option. Use the up and down keys to navigate or escape to close.
-
-
-
-
-
-
-
-
-
-
- }
- onActivation={[Function]}
- onDeactivation={[Function]}
- persistentFocus={false}
- />
-
-
-
-
-
-
-
-
-
- You are in a form selector of 4 items and must select a single option. Use the up and down keys to navigate or escape to close.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Linear Gradient
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Linear Gradient with stops
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Plain text as a custom option
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-`;
diff --git a/src/components/color_picker/color_palette_picker/color_palette_picker.test.tsx b/src/components/color_picker/color_palette_picker/color_palette_picker.test.tsx
index 1d0fcc2a1893..e1f9a288678a 100644
--- a/src/components/color_picker/color_palette_picker/color_palette_picker.test.tsx
+++ b/src/components/color_picker/color_palette_picker/color_palette_picker.test.tsx
@@ -174,7 +174,5 @@ describe('EuiColorPalettePicker', () => {
.simulate('click');
expect(takeMountedSnapshot(component)).toMatchSnapshot();
-
- expect(component).toMatchSnapshot();
});
});
From c55dcea9155b3c63331ec0387a2068183e9dc956 Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Mon, 6 Jul 2020 14:40:03 -0700
Subject: [PATCH 09/15] euisuperselect snapshot updates
---
.../__snapshots__/super_select.test.tsx.snap | 632 ------------------
.../form/super_select/super_select.test.tsx | 2 -
2 files changed, 634 deletions(-)
diff --git a/src/components/form/super_select/__snapshots__/super_select.test.tsx.snap b/src/components/form/super_select/__snapshots__/super_select.test.tsx.snap
index f0958f150b89..c197f702cc0f 100644
--- a/src/components/form/super_select/__snapshots__/super_select.test.tsx.snap
+++ b/src/components/form/super_select/__snapshots__/super_select.test.tsx.snap
@@ -503,638 +503,6 @@ exports[`EuiSuperSelect props more props are propogated to each option 1`] = `
`;
-exports[`EuiSuperSelect props more props are propogated to each option 2`] = `
-
-
- }
- className="euiSuperSelect"
- closePopover={[Function]}
- display="block"
- hasArrow={false}
- isOpen={true}
- ownFocus={false}
- panelClassName="euiSuperSelect__popoverPanel"
- panelPaddingSize="none"
- popoverRef={[Function]}
- >
-
-
-
-
-
-
-
-
-
-
-
- Select an option: Option #1, is selected
-
-
-
-
- Option #1
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- You are in a form selector of 2 items and must select a single option. Use the up and down keys to navigate or escape to close.
-
-
-
-
-
-
-
-
- }
- onActivation={[Function]}
- onDeactivation={[Function]}
- persistentFocus={false}
- >
-
-
-
-
-
- You are in a form selector of 2 items and must select a single option. Use the up and down keys to navigate or escape to close.
-
-
-
-
-
-
-
-
- }
- onActivation={[Function]}
- onDeactivation={[Function]}
- persistentFocus={false}
- />
-
-
-
-
-
-
-
-
-
- You are in a form selector of 2 items and must select a single option. Use the up and down keys to navigate or escape to close.
-
-
-
-
-
-
-
-
-
-
-
- Option #1
-
-
-
-
-
-
-
-
-
-
-
- Option #2
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-`;
-
exports[`EuiSuperSelect props options are rendered when select is open 1`] = `
{
component.find('button[data-test-subj="superSelect"]').simulate('click');
expect(takeMountedSnapshot(component)).toMatchSnapshot();
-
- expect(component).toMatchSnapshot();
});
});
});
From b20c79d81377342065900b602b4d7e0285c83f82 Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Mon, 6 Jul 2020 14:47:18 -0700
Subject: [PATCH 10/15] euicollapsible snapshot updates
---
.../collapsible_nav.test.tsx.snap | 48 ++++++-------
.../collapsible_nav/collapsible_nav.test.tsx | 68 ++++++++++++++-----
2 files changed, 74 insertions(+), 42 deletions(-)
diff --git a/src/components/collapsible_nav/__snapshots__/collapsible_nav.test.tsx.snap b/src/components/collapsible_nav/__snapshots__/collapsible_nav.test.tsx.snap
index 43fabc7dfea0..795c6060a97d 100644
--- a/src/components/collapsible_nav/__snapshots__/collapsible_nav.test.tsx.snap
+++ b/src/components/collapsible_nav/__snapshots__/collapsible_nav.test.tsx.snap
@@ -6,12 +6,12 @@ Array [
,
@@ -37,12 +37,12 @@ Array [
,
@@ -91,12 +91,12 @@ Array [
,
@@ -150,12 +150,12 @@ Array [
,
@@ -201,12 +201,12 @@ Array [
,
@@ -252,12 +252,12 @@ Array [
,
@@ -351,12 +351,12 @@ Array [
,
@@ -407,12 +407,12 @@ Array [
,
diff --git a/src/components/collapsible_nav/collapsible_nav.test.tsx b/src/components/collapsible_nav/collapsible_nav.test.tsx
index 32f0c401bfa2..980559a55625 100644
--- a/src/components/collapsible_nav/collapsible_nav.test.tsx
+++ b/src/components/collapsible_nav/collapsible_nav.test.tsx
@@ -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';
@@ -33,20 +33,28 @@ const propsNeededToRender = { id: 'id', isOpen: true };
describe('EuiCollapsibleNav', () => {
test('is rendered', () => {
- const component = render(
+ const component = mount(
);
- expect(component).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(component, {
+ hasArrayOutput: true,
+ })
+ ).toMatchSnapshot();
});
describe('props', () => {
test('onClose', () => {
- const component = render(
+ const component = mount(
{}} />
);
- expect(component).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(component, {
+ hasArrayOutput: true,
+ })
+ ).toMatchSnapshot();
});
test('isDocked', () => {
@@ -58,23 +66,31 @@ describe('EuiCollapsibleNav', () => {
});
test('dockedBreakpoint', () => {
- const component = render(
+ const component = mount(
);
- expect(component).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(component, {
+ hasArrayOutput: true,
+ })
+ ).toMatchSnapshot();
});
test('button', () => {
- const component = render(
+ const component = mount(
} />
);
- expect(component).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(component, {
+ hasArrayOutput: true,
+ })
+ ).toMatchSnapshot();
});
test('showButtonIfDocked', () => {
- const component = render(
+ const component = mount(
}
@@ -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(
);
- expect(component).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(component, {
+ hasArrayOutput: true,
+ })
+ ).toMatchSnapshot();
});
});
describe('close button', () => {
test('can be hidden', () => {
- const component = render(
+ const component = mount(
);
- expect(component).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(component, {
+ hasArrayOutput: true,
+ })
+ ).toMatchSnapshot();
});
test('extends EuiButtonEmpty', () => {
- const component = render(
+ const component = mount(
);
- expect(component).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(component, {
+ hasArrayOutput: true,
+ })
+ ).toMatchSnapshot();
});
});
From c750d0e32be77dae305dd941ce4d2029eb32426c Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Mon, 6 Jul 2020 15:00:13 -0700
Subject: [PATCH 11/15] euifocustrap snapshot updates
---
.../__snapshots__/focus_trap.test.tsx.snap | 6 +--
src/components/focus_trap/focus_trap.test.tsx | 50 ++++++++++---------
2 files changed, 29 insertions(+), 27 deletions(-)
diff --git a/src/components/focus_trap/__snapshots__/focus_trap.test.tsx.snap b/src/components/focus_trap/__snapshots__/focus_trap.test.tsx.snap
index 6e027fb5a04e..a7d8850f901d 100644
--- a/src/components/focus_trap/__snapshots__/focus_trap.test.tsx.snap
+++ b/src/components/focus_trap/__snapshots__/focus_trap.test.tsx.snap
@@ -29,12 +29,12 @@ exports[`EuiFocusTrap is rendered 1`] = `
Array [
,
,
,
,
]
diff --git a/src/components/focus_trap/focus_trap.test.tsx b/src/components/focus_trap/focus_trap.test.tsx
index 6d7179dc8172..2c6ec8398fdb 100644
--- a/src/components/focus_trap/focus_trap.test.tsx
+++ b/src/components/focus_trap/focus_trap.test.tsx
@@ -20,7 +20,7 @@
import React, { EventHandler } from 'react';
import { render, mount } from 'enzyme';
-import { findTestSubject } from '../../test';
+import { findTestSubject, takeMountedSnapshot } from '../../test';
import { EuiEvent } from '../outside_click_detector/outside_click_detector';
import { EuiFocusTrap } from './focus_trap';
@@ -28,13 +28,15 @@ import { EuiPortal } from '../portal';
describe('EuiFocusTrap', () => {
test('is rendered', () => {
- const component = render(
+ const component = mount(
);
- expect(component).toMatchSnapshot();
+ expect(
+ takeMountedSnapshot(component, { hasArrayOutput: true })
+ ).toMatchSnapshot();
});
test('can be disabled', () => {
@@ -138,18 +140,18 @@ describe('EuiFocusTrap', () => {
);
// The existence of `data-focus-lock-disabled=false` indicates that the trap is enabled.
- expect(component.find('[data-focus-lock-disabled=false]').length).toBe(
- 1
- );
+ expect(
+ component.find('[data-focus-lock-disabled=false]').length
+ ).not.toBeLessThan(1);
findTestSubject(component, 'outside').simulate('mousedown');
findTestSubject(component, 'outside').simulate('mouseup');
// `react-focus-lock` relies on real DOM events to move focus about.
// Exposed attributes are the most consistent way to attain its state.
// See https://github.com/theKashey/react-focus-lock/blob/master/_tests/FocusLock.spec.js for the lib in use
// Trap remains enabled
- expect(component.find('[data-focus-lock-disabled=false]').length).toBe(
- 1
- );
+ expect(
+ component.find('[data-focus-lock-disabled=false]').length
+ ).not.toBeLessThan(1);
});
test('trap remains enabled after internal clicks', () => {
@@ -167,15 +169,15 @@ describe('EuiFocusTrap', () => {
);
- expect(component.find('[data-focus-lock-disabled=false]').length).toBe(
- 1
- );
+ expect(
+ component.find('[data-focus-lock-disabled=false]').length
+ ).not.toBeLessThan(1);
findTestSubject(component, 'input2').simulate('mousedown');
findTestSubject(component, 'input2').simulate('mouseup');
// Trap remains enabled
- expect(component.find('[data-focus-lock-disabled=false]').length).toBe(
- 1
- );
+ expect(
+ component.find('[data-focus-lock-disabled=false]').length
+ ).not.toBeLessThan(1);
});
test('trap remains enabled after internal portal clicks', () => {
@@ -196,15 +198,15 @@ describe('EuiFocusTrap', () => {
);
- expect(component.find('[data-focus-lock-disabled=false]').length).toBe(
- 1
- );
+ expect(
+ component.find('[data-focus-lock-disabled=false]').length
+ ).not.toBeLessThan(1);
findTestSubject(component, 'input3').simulate('mousedown');
findTestSubject(component, 'input3').simulate('mouseup');
// Trap remains enabled
- expect(component.find('[data-focus-lock-disabled=false]').length).toBe(
- 1
- );
+ expect(
+ component.find('[data-focus-lock-disabled=false]').length
+ ).not.toBeLessThan(1);
});
test('trap becomes disabled on outside clicks', () => {
@@ -222,9 +224,9 @@ describe('EuiFocusTrap', () => {
);
- expect(component.find('[data-focus-lock-disabled=false]').length).toBe(
- 1
- );
+ expect(
+ component.find('[data-focus-lock-disabled=false]').length
+ ).not.toBeLessThan(1);
findTestSubject(component, 'outside').simulate('mousedown');
findTestSubject(component, 'outside').simulate('mouseup');
// Trap becomes disabled
From 98a2fad62d3a8724c0b4f565f8bb88c2e7b36add Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Mon, 6 Jul 2020 15:00:34 -0700
Subject: [PATCH 12/15] allow for array snapshots with takeMountedSnapshot
---
src/test/take_mounted_snapshot.ts | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/src/test/take_mounted_snapshot.ts b/src/test/take_mounted_snapshot.ts
index 6a319cb7711b..a845b81b4e82 100644
--- a/src/test/take_mounted_snapshot.ts
+++ b/src/test/take_mounted_snapshot.ts
@@ -20,6 +20,10 @@
import { ReactWrapper } from 'enzyme';
import { Component } from 'react';
+interface TakeMountedSnapshotOptions {
+ hasArrayOutput?: boolean;
+}
+
/**
* Use this function to generate a Jest snapshot of components that have been fully rendered
* using Enzyme's `mount` method. Typically, a mounted component will result in a snapshot
@@ -27,10 +31,23 @@ import { Component } from 'react';
* leaving only HTML elements in the snapshot.
*/
export const takeMountedSnapshot = (
- mountedComponent: ReactWrapper<{}, {}, Component>
+ mountedComponent: ReactWrapper<{}, {}, Component>,
+ options: TakeMountedSnapshotOptions = {}
) => {
+ const opts: TakeMountedSnapshotOptions = {
+ hasArrayOutput: false,
+ ...options,
+ };
const html = mountedComponent.html();
const template = document.createElement('template');
template.innerHTML = html;
- return template.content.firstChild;
+ const snapshot = template.content.firstChild;
+ if (opts.hasArrayOutput) {
+ const snapshotArray: ChildNode[] = [];
+ template.content.childNodes.forEach(el => {
+ snapshotArray.push(el);
+ });
+ return snapshotArray;
+ }
+ return snapshot;
};
From 29fbba9a9cb3f65451c6424d18301ad3eea52e75 Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Tue, 7 Jul 2020 08:57:39 -0700
Subject: [PATCH 13/15] docs improvements
---
src-docs/src/views/focus_trap/focus_trap.js | 2 +-
src/components/focus_trap/focus_trap.tsx | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src-docs/src/views/focus_trap/focus_trap.js b/src-docs/src/views/focus_trap/focus_trap.js
index 3d77dae22816..6272c0a441e1 100644
--- a/src-docs/src/views/focus_trap/focus_trap.js
+++ b/src-docs/src/views/focus_trap/focus_trap.js
@@ -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);
diff --git a/src/components/focus_trap/focus_trap.tsx b/src/components/focus_trap/focus_trap.tsx
index c75518902f59..b5a61583384b 100644
--- a/src/components/focus_trap/focus_trap.tsx
+++ b/src/components/focus_trap/focus_trap.tsx
@@ -54,7 +54,13 @@ const OutsideEventDetector: FunctionComponent = ({
export type FocusTarget = HTMLElement | string | (() => HTMLElement);
interface EuiFocusTrapInterface {
+ /**
+ * Clicking outside the trap area will disable the trap
+ */
clickOutsideDisables?: boolean;
+ /**
+ * Reference to element that will get focus when the trap is initiated
+ */
initialFocus?: FocusTarget;
style?: CSSProperties;
disabled?: boolean;
From 26bc04c2af0da8aad447735af0cb12a0b518bd02 Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Tue, 14 Jul 2020 12:36:07 -0700
Subject: [PATCH 14/15] default to noIsolation=true and scrollLock=false
---
src-docs/src/services/full_screen/full_screen.tsx | 6 +-----
src-docs/src/views/focus_trap/focus_trap_example.js | 6 ++----
src/components/collapsible_nav/collapsible_nav.tsx | 5 +----
src/components/flyout/flyout.tsx | 4 +---
src/components/focus_trap/focus_trap.tsx | 4 ++++
5 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/src-docs/src/services/full_screen/full_screen.tsx b/src-docs/src/services/full_screen/full_screen.tsx
index 3356ff59f7e7..67895ead2ef5 100644
--- a/src-docs/src/services/full_screen/full_screen.tsx
+++ b/src-docs/src/services/full_screen/full_screen.tsx
@@ -46,11 +46,7 @@ export const GuideFullScreen: FunctionComponent<{
{buttonText}
- {fullScreen && (
-
- {children(setFullScreen)}
-
- )}
+ {fullScreen && {children(setFullScreen)} }
);
};
diff --git a/src-docs/src/views/focus_trap/focus_trap_example.js b/src-docs/src/views/focus_trap/focus_trap_example.js
index e11a382be51d..844ec9b175ab 100644
--- a/src-docs/src/views/focus_trap/focus_trap_example.js
+++ b/src-docs/src/views/focus_trap/focus_trap_example.js
@@ -48,10 +48,8 @@ export const FocusTrapExample = {
trap when the user clicks outside the trap.
- Use noIsolation when allowing pointer events on
- outside elements is needed. For instance, when used with an{' '}
- EuiOverlayMask that has a click handler, set{' '}
- noIsolation=true .
+ Use noIsolation=false when pointer events on
+ outside elements should be disallowed.
),
diff --git a/src/components/collapsible_nav/collapsible_nav.tsx b/src/components/collapsible_nav/collapsible_nav.tsx
index 8fbf30f1f745..c9b5f745d0e5 100644
--- a/src/components/collapsible_nav/collapsible_nav.tsx
+++ b/src/components/collapsible_nav/collapsible_nav.tsx
@@ -193,10 +193,7 @@ export const EuiCollapsibleNav: FunctionComponent = ({
{optionalOverlay}
{/* Trap focus only when docked={false} */}
-
+
{children}
{closeButton}
diff --git a/src/components/flyout/flyout.tsx b/src/components/flyout/flyout.tsx
index 95b47d0bd09c..1077bd16a170 100644
--- a/src/components/flyout/flyout.tsx
+++ b/src/components/flyout/flyout.tsx
@@ -174,9 +174,7 @@ export const EuiFlyout: FunctionComponent = ({
{optionalOverlay}
{/* Trap focus even when ownFocus={false}, otherwise closing the flyout won't return focus
to the originating button */}
-
- {flyoutContent}
-
+ {flyoutContent}
);
};
diff --git a/src/components/focus_trap/focus_trap.tsx b/src/components/focus_trap/focus_trap.tsx
index b5a61583384b..34b92006cd2a 100644
--- a/src/components/focus_trap/focus_trap.tsx
+++ b/src/components/focus_trap/focus_trap.tsx
@@ -152,12 +152,16 @@ export class EuiFocusTrap extends Component {
clickOutsideDisables = false,
disabled = false,
returnFocus = true,
+ noIsolation = true,
+ scrollLock = false,
onClickOutside,
...rest
} = this.props;
const isDisabled = disabled || this.state.hasBeenDisabledByClick;
const focusOnProps = {
returnFocus,
+ noIsolation,
+ scrollLock,
enabled: !isDisabled,
...rest,
};
From 6b83b202d4a7041b85e0f1055661437d9f988192 Mon Sep 17 00:00:00 2001
From: Greg Thompson
Date: Wed, 15 Jul 2020 16:24:28 -0700
Subject: [PATCH 15/15] CL
---
CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 28e9b4178af4..01ebc3d44a29 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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)