diff --git a/packages/patternfly-4/react-core/package.json b/packages/patternfly-4/react-core/package.json index 59dd510bc3c..ee87cf52c26 100644 --- a/packages/patternfly-4/react-core/package.json +++ b/packages/patternfly-4/react-core/package.json @@ -27,7 +27,8 @@ "dependencies": { "@patternfly/react-icons": "^2.5.2", "@patternfly/react-styles": "^2.3.0", - "exenv": "^1.2.2" + "exenv": "^1.2.2", + "focus-trap-react": "^4.0.1" }, "peerDependencies": { "prop-types": "^15.6.1", diff --git a/packages/patternfly-4/react-core/src/components/Dropdown/Dropdown.js b/packages/patternfly-4/react-core/src/components/Dropdown/Dropdown.js index 9bfebad9426..db2bd591259 100644 --- a/packages/patternfly-4/react-core/src/components/Dropdown/Dropdown.js +++ b/packages/patternfly-4/react-core/src/components/Dropdown/Dropdown.js @@ -2,6 +2,7 @@ import React, { Children, cloneElement } from 'react'; import styles from '@patternfly/patternfly-next/components/Dropdown/dropdown.css'; import { css } from '@patternfly/react-styles'; import PropTypes from 'prop-types'; +import FocusTrap from 'focus-trap-react'; import DropdownMenu from './DropdownMenu'; export const DropdownPosition = { @@ -71,9 +72,13 @@ class Dropdown extends React.Component { }} > {toggle && Children.map(toggle, oneToggle => cloneElement(oneToggle, { parentRef: this.parentRef, isOpen }))} - onSelect && onSelect(event)}> - {children} - + {isOpen && ( + + onSelect && onSelect(event)}> + {children} + + + )} ); } diff --git a/packages/patternfly-4/react-core/src/components/Dropdown/Toggle.js b/packages/patternfly-4/react-core/src/components/Dropdown/Toggle.js index 47f56da1984..8ee662c7d90 100644 --- a/packages/patternfly-4/react-core/src/components/Dropdown/Toggle.js +++ b/packages/patternfly-4/react-core/src/components/Dropdown/Toggle.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import styles from '@patternfly/patternfly-next/components/Dropdown/dropdown.css'; import { css } from '@patternfly/react-styles'; import PropTypes from 'prop-types'; +import { KEY_CODES } from '../../internal/constants'; const propTypes = { /** Anything which can be rendered as dropdown toggle */ @@ -51,8 +52,9 @@ class DropdownToggle extends Component { }; onEscPress = event => { + const { parentRef } = this.props; const keyCode = event.keyCode || event.which; - if (keyCode === 27) { + if (keyCode === KEY_CODES.ESCAPE_KEY && parentRef && parentRef.contains(event.target)) { this.props.onToggle && this.props.onToggle(false); this.toggle.focus(); } diff --git a/packages/patternfly-4/react-core/src/components/Dropdown/__snapshots__/Dropdown.test.js.snap b/packages/patternfly-4/react-core/src/components/Dropdown/__snapshots__/Dropdown.test.js.snap index 18414f78194..8e5897bbc80 100644 --- a/packages/patternfly-4/react-core/src/components/Dropdown/__snapshots__/Dropdown.test.js.snap +++ b/packages/patternfly-4/react-core/src/components/Dropdown/__snapshots__/Dropdown.test.js.snap @@ -13,34 +13,6 @@ exports[`KebabToggle dropup + right aligned 1`] = ` color: #282d33; background-color: transparent; } -.pf-m-disabled { - display: block; -} -.pf-m-disabled { - display: block; -} -.pf-c-dropdown__separator { - display: block; - height: 1px; - background-color: #ededed; -} -.pf-c-dropdown__separator { - display: block; - height: 1px; - background-color: #ededed; -} -.pf-c-dropdown__menu { - display: block; - position: absolute; - z-index: 100; - min-width: 100%; - padding-top: 0.5rem; - padding-bottom: 0.5rem; - background: #ffffff; - background-clip: padding-box; - border: 1px solid transparent; - box-shadow: 0 0.0625rem 0.0625rem 0rem rgba(3, 3, 3, 0.05), 0 0.25rem 0.5rem 0.25rem rgba(3, 3, 3, 0.06); -} .pf-c-dropdown.pf-m-top.pf-m-align-right { display: inline-block; position: relative; @@ -122,149 +94,6 @@ exports[`KebabToggle dropup + right aligned 1`] = ` - - `; @@ -282,34 +111,6 @@ exports[`KebabToggle dropup 1`] = ` color: #282d33; background-color: transparent; } -.pf-m-disabled { - display: block; -} -.pf-m-disabled { - display: block; -} -.pf-c-dropdown__separator { - display: block; - height: 1px; - background-color: #ededed; -} -.pf-c-dropdown__separator { - display: block; - height: 1px; - background-color: #ededed; -} -.pf-c-dropdown__menu { - display: block; - position: absolute; - z-index: 100; - min-width: 100%; - padding-top: 0.5rem; - padding-bottom: 0.5rem; - background: #ffffff; - background-clip: padding-box; - border: 1px solid transparent; - box-shadow: 0 0.0625rem 0.0625rem 0rem rgba(3, 3, 3, 0.05), 0 0.25rem 0.5rem 0.25rem rgba(3, 3, 3, 0.06); -} .pf-c-dropdown.pf-m-top { display: inline-block; position: relative; @@ -391,149 +192,6 @@ exports[`KebabToggle dropup 1`] = ` - - `; @@ -660,149 +318,159 @@ exports[`KebabToggle expanded 1`] = ` - -