@targetprocess/popover 12.19.5-alpha.4 → 12.19.5-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Popover.tsx CHANGED
@@ -84,6 +84,7 @@ export type PopoverProps = {
84
84
  className?: string
85
85
  trackScroll?: boolean
86
86
  role?: 'tooltip' | 'dialog'
87
+ trapFocus?: boolean
87
88
  }
88
89
 
89
90
  export type PopoverState = {
@@ -122,14 +123,16 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
122
123
  zIndex: PropTypes.number,
123
124
  trackScroll: PropTypes.bool,
124
125
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
125
- role: PropTypes.oneOf(['tooltip', 'dialog'])
126
+ role: PropTypes.oneOf(['tooltip', 'dialog']),
127
+ trapFocus: PropTypes.bool
126
128
  }
127
129
 
128
130
  static defaultProps = {
129
131
  zIndex: 19999,
130
132
  outerActionEvents: ['mousedown', 'touchstart'],
131
133
  getPopoverPosition: 'bottomLeft',
132
- role: 'dialog'
134
+ role: 'dialog',
135
+ trapFocus: 'true'
133
136
  }
134
137
 
135
138
  state = {
@@ -176,6 +179,7 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
176
179
  onEscapeAction={this.onEscapeAction}
177
180
  isOpen={isOpen}
178
181
  role={this.props.role}
182
+ trapFocus={this.props.trapFocus}
179
183
  >
180
184
  {childrenWithRef}
181
185
  </StatelessPopover>
@@ -7,7 +7,10 @@ import {PopoverPosition} from './PopoverPosition'
7
7
  import styles from './style/index.css'
8
8
  import {DimensionParams, GetPopoverPositionType, PositionParams} from './types'
9
9
  import {throttle} from '../../base/utils/throttle'
10
- import {focusFirstDescendant, trapFocus} from '../../base/utils/ariaUtils'
10
+ import FocusTrap from 'focus-trap-react'
11
+ import {generateId, focusFirstDescendant} from '../../base/utils/ariaUtils'
12
+
13
+ const popoverContainerPrefix = 'popover-container-'
11
14
 
12
15
  type PopoverContainerProps = {
13
16
  containerElement?: HTMLElement
@@ -20,6 +23,7 @@ type PopoverContainerProps = {
20
23
  showTip?: boolean
21
24
  zIndex: number
22
25
  role?: 'tooltip' | 'dialog'
26
+ trapFocus?: boolean
23
27
  onEscapeAction: (event: Event) => void
24
28
  }
25
29
 
@@ -91,6 +95,7 @@ export class PopoverContainer extends React.Component<
91
95
  className: PropTypes.string,
92
96
  trackScroll: PropTypes.bool,
93
97
  role: PropTypes.oneOf(['tooltip', 'dialog']),
98
+ trapFocus: PropTypes.bool,
94
99
  onEscapeAction: PropTypes.func
95
100
  }
96
101
 
@@ -107,6 +112,8 @@ export class PopoverContainer extends React.Component<
107
112
  positionY: 0
108
113
  }
109
114
 
115
+ popoverContainerId = generateId(popoverContainerPrefix)
116
+
110
117
  adjustPosition() {
111
118
  if (!this.mounted) {
112
119
  return
@@ -154,11 +161,6 @@ export class PopoverContainer extends React.Component<
154
161
  this.mounted = true
155
162
  this.adjustPosition()
156
163
 
157
- if (this.props.role === 'tooltip') {
158
- this.popoverContentRef.current.tabIndex = 0
159
- this.popoverContentRef.current.focus()
160
- }
161
-
162
164
  if (this.props.trackScroll) {
163
165
  document.addEventListener('scroll', this.onScroll)
164
166
  window.addEventListener('resize', this.onResize)
@@ -167,9 +169,9 @@ export class PopoverContainer extends React.Component<
167
169
  }
168
170
  }
169
171
 
170
- if (this.popoverContentRef.current && this.props.role === 'dialog') {
172
+ if (this.popoverContentRef.current && !this.props.trapFocus) {
171
173
  if (!focusFirstDescendant(this.popoverContentRef.current)) {
172
- this.popoverContentRef.current.tabIndex = 0
174
+ this.popoverContentRef.current.tabIndex = -1
173
175
  this.popoverContentRef.current.focus()
174
176
  }
175
177
  }
@@ -182,10 +184,6 @@ export class PopoverContainer extends React.Component<
182
184
  ) {
183
185
  this.adjustPosition()
184
186
  }
185
-
186
- if (this.popoverContentRef.current && this.props.role === 'dialog') {
187
- trapFocus(this.popoverContentRef.current)
188
- }
189
187
  }
190
188
 
191
189
  componentWillUnmount() {
@@ -274,20 +272,50 @@ export class PopoverContainer extends React.Component<
274
272
  }}
275
273
  />
276
274
  )}
277
- <div
278
- ref={this.popoverContentRef}
279
- style={{
280
- position: 'absolute',
281
- pointerEvents: 'all',
282
- ...position
283
- }}
284
- className={this.props.className}
285
- role={this.props.role}
286
- aria-modal={this.props.role === 'dialog' ? 'true' : 'false'}
287
- onKeyDown={this.handleKeyDown}
288
- >
289
- {this.props.children}
290
- </div>
275
+ {this.props.trapFocus && (
276
+ <FocusTrap
277
+ focusTrapOptions={{
278
+ fallbackFocus: `#${this.popoverContainerId}`,
279
+ clickOutsideDeactivates: true
280
+ }}
281
+ >
282
+ <div
283
+ id={this.popoverContainerId}
284
+ ref={this.popoverContentRef}
285
+ style={{
286
+ position: 'absolute',
287
+ pointerEvents: 'all',
288
+ ...position
289
+ }}
290
+ tabIndex={-1}
291
+ className={this.props.className}
292
+ role={this.props.role}
293
+ aria-modal={this.props.trapFocus ? 'true' : 'false'}
294
+ onKeyDown={this.handleKeyDown}
295
+ >
296
+ {this.props.children}
297
+ </div>
298
+ </FocusTrap>
299
+ )}
300
+
301
+ {!this.props.trapFocus && (
302
+ <div
303
+ id={this.popoverContainerId}
304
+ ref={this.popoverContentRef}
305
+ style={{
306
+ position: 'absolute',
307
+ pointerEvents: 'all',
308
+ ...position
309
+ }}
310
+ tabIndex={-1}
311
+ className={this.props.className}
312
+ role={this.props.role}
313
+ aria-modal={this.props.trapFocus ? 'true' : 'false'}
314
+ onKeyDown={this.handleKeyDown}
315
+ >
316
+ {this.props.children}
317
+ </div>
318
+ )}
291
319
  </div>
292
320
  )
293
321
  }
@@ -19,6 +19,7 @@ export type StatelessPopoverProps = {
19
19
  onEscapeAction: (evt: Event) => void
20
20
  trackScroll?: boolean
21
21
  role?: 'tooltip' | 'dialog'
22
+ trapFocus?: boolean
22
23
  }
23
24
 
24
25
  export class StatelessPopover extends React.Component<StatelessPopoverProps> {
@@ -43,6 +44,7 @@ export class StatelessPopover extends React.Component<StatelessPopoverProps> {
43
44
  zIndex={props.zIndex}
44
45
  trackScroll={props.trackScroll}
45
46
  role={this.props.role}
47
+ trapFocus={this.props.trapFocus}
46
48
  onEscapeAction={this.props.onEscapeAction}
47
49
  >
48
50
  {props.body}
@@ -5,6 +5,16 @@ import {Popover, PopoverProps, PopoverState} from '../Popover'
5
5
  import {PopoverBody} from '../PopoverBody'
6
6
  import {cleanDocumentBody} from '../../../testUtils/domUtils'
7
7
 
8
+ jest.mock('focus-trap', () => {
9
+ const trap = {
10
+ activate: () => trap,
11
+ deactivate: () => trap,
12
+ pause: () => {},
13
+ unpause: () => {}
14
+ }
15
+ return () => trap
16
+ })
17
+
8
18
  describe('Popover', () => {
9
19
  beforeEach(() => {
10
20
  cleanDocumentBody()
package/dist/Popover.d.ts CHANGED
@@ -80,6 +80,7 @@ export declare type PopoverProps = {
80
80
  className?: string;
81
81
  trackScroll?: boolean;
82
82
  role?: 'tooltip' | 'dialog';
83
+ trapFocus?: boolean;
83
84
  };
84
85
  export declare type PopoverState = {
85
86
  isOpen: boolean;
@@ -113,12 +114,14 @@ export declare class Popover extends React.Component<PopoverProps, PopoverState>
113
114
  trackScroll: PropTypes.Requireable<boolean>;
114
115
  children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
115
116
  role: PropTypes.Requireable<string>;
117
+ trapFocus: PropTypes.Requireable<boolean>;
116
118
  };
117
119
  static defaultProps: {
118
120
  zIndex: number;
119
121
  outerActionEvents: string[];
120
122
  getPopoverPosition: string;
121
123
  role: string;
124
+ trapFocus: string;
122
125
  };
123
126
  state: {
124
127
  isOpen: boolean;
@@ -12,6 +12,7 @@ declare type PopoverContainerProps = {
12
12
  showTip?: boolean;
13
13
  zIndex: number;
14
14
  role?: 'tooltip' | 'dialog';
15
+ trapFocus?: boolean;
15
16
  onEscapeAction: (event: Event) => void;
16
17
  };
17
18
  declare type PopoverContainerState = {
@@ -29,6 +30,7 @@ export declare class PopoverContainer extends React.Component<PopoverContainerPr
29
30
  className: PropTypes.Requireable<string>;
30
31
  trackScroll: PropTypes.Requireable<boolean>;
31
32
  role: PropTypes.Requireable<string>;
33
+ trapFocus: PropTypes.Requireable<boolean>;
32
34
  onEscapeAction: PropTypes.Requireable<(...args: any[]) => any>;
33
35
  };
34
36
  static defaultProps: {
@@ -37,6 +39,7 @@ export declare class PopoverContainer extends React.Component<PopoverContainerPr
37
39
  mounted: boolean;
38
40
  popoverContentRef: React.RefObject<HTMLDivElement>;
39
41
  state: PopoverContainerState;
42
+ popoverContainerId: string;
40
43
  adjustPosition(): void;
41
44
  onResize: () => void;
42
45
  onScroll: (...args: any[]) => void;
@@ -14,6 +14,7 @@ export declare type StatelessPopoverProps = {
14
14
  onEscapeAction: (evt: Event) => void;
15
15
  trackScroll?: boolean;
16
16
  role?: 'tooltip' | 'dialog';
17
+ trapFocus?: boolean;
17
18
  };
18
19
  export declare class StatelessPopover extends React.Component<StatelessPopoverProps> {
19
20
  renderPortalContent({ props, container, positioningTarget }: {
@@ -2,34 +2,8 @@ import React, { createRef } from 'react';
2
2
  import { SpaceXS } from '@targetprocess/global-constants';
3
3
  import classNames from 'classnames';
4
4
  import ReactDOM from 'react-dom';
5
+ import FocusTrap from 'focus-trap-react';
5
6
 
6
- function _iterableToArrayLimit(r, l) {
7
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
8
- if (null != t) {
9
- var e,
10
- n,
11
- i,
12
- u,
13
- a = [],
14
- f = !0,
15
- o = !1;
16
- try {
17
- if (i = (t = t.call(r)).next, 0 === l) {
18
- if (Object(t) !== t) return;
19
- f = !1;
20
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
21
- } catch (r) {
22
- o = !0, n = r;
23
- } finally {
24
- try {
25
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
26
- } finally {
27
- if (o) throw n;
28
- }
29
- }
30
- return a;
31
- }
32
- }
33
7
  function _classCallCheck(instance, Constructor) {
34
8
  if (!(instance instanceof Constructor)) {
35
9
  throw new TypeError("Cannot call a class as a function");
@@ -109,28 +83,6 @@ function _possibleConstructorReturn(self, call) {
109
83
  }
110
84
  return _assertThisInitialized(self);
111
85
  }
112
- function _slicedToArray(arr, i) {
113
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
114
- }
115
- function _arrayWithHoles(arr) {
116
- if (Array.isArray(arr)) return arr;
117
- }
118
- function _unsupportedIterableToArray(o, minLen) {
119
- if (!o) return;
120
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
121
- var n = Object.prototype.toString.call(o).slice(8, -1);
122
- if (n === "Object" && o.constructor) n = o.constructor.name;
123
- if (n === "Map" || n === "Set") return Array.from(o);
124
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
125
- }
126
- function _arrayLikeToArray(arr, len) {
127
- if (len == null || len > arr.length) len = arr.length;
128
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
129
- return arr2;
130
- }
131
- function _nonIterableRest() {
132
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
133
- }
134
86
  function _toPrimitive(input, hint) {
135
87
  if (typeof input !== "object" || input === null) return input;
136
88
  var prim = input[Symbol.toPrimitive];
@@ -254,8 +206,8 @@ function styleInject(css, ref) {
254
206
  }
255
207
  }
256
208
 
257
- var css = ".popover-body-container__popover__12-19-5-alpha-4 {\r\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n border-radius: var(--BorderRadiusL, 4px);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n background: var(--BackgroundDefault, #FFFFFF);\r\n z-index: var(--ZIndexModal, 10001);\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n}\r\n\r\n.popover-body__popover__12-19-5-alpha-4 {\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n padding: var(--SpaceSM, 12px);\r\n font-size: var(--FontSizeDefault, 13px);\r\n color: var(--FontColorDefault, #000000);\r\n}\r\n\r\n.popover-body--no-padding__popover__12-19-5-alpha-4 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-5-alpha-4 {\r\n position: absolute;\r\n pointer-events: none;\r\n z-index: calc(var(--ZIndexModal, 10001) + 1);\r\n overflow: hidden;\r\n display: -webkit-box;\r\n display: -ms-flexbox;\r\n display: flex;\r\n -webkit-box-align: center;\r\n -ms-flex-align: center;\r\n align-items: center;\r\n -webkit-box-pack: center;\r\n -ms-flex-pack: center;\r\n justify-content: center;\r\n}\r\n\r\n.popover-tip__popover__12-19-5-alpha-4:before {\r\n content: '';\r\n position: absolute;\r\n display: block;\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n background-color: var(--BackgroundDefault, #FFFFFF);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n /*\r\n geometry FTW\r\n\r\n 2*$popoverTipSize\r\n _______ _______\r\n | /|\\ |\r\n | / | \\ | $popoverTipSize\r\n | / | \\ |\r\n |/______|______\\|\r\n since tip is rotated 45 degrees, its width and height is a\r\n diagonal of a square with side=$popoverTipSize, thus diagonal\r\n is sqrt(2) * $popoverTipSize.\r\n sqrt(2) ~= 1.414, 1.4 used here to prevent too much rounding\r\n */\r\n width: 11.2px;\r\n height: 11.2px;\r\n -webkit-transform: rotate(45deg);\r\n transform: rotate(45deg);\r\n }\r\n\r\n.popover-tip--bottom__popover__12-19-5-alpha-4,\r\n .popover-tip--top__popover__12-19-5-alpha-4 {\r\n width: 100%;\r\n border-top: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-bottom: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 9px;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-5-alpha-4,\r\n .popover-tip--right__popover__12-19-5-alpha-4 {\r\n border-left: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-right: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 100%;\r\n width: 9px;\r\n }\r\n\r\n/*\r\n To determine tip position, we need to rotate it\r\n along the \"tip\" point, after that, the \"tip\" point\r\n can be placed with exactly 50% offset from the origin\r\n so that it is centered.\r\n */\r\n\r\n.popover-tip--bottom__popover__12-19-5-alpha-4:before {\r\n -webkit-transform-origin: left top;\r\n transform-origin: left top;\r\n left: 50%;\r\n top: 0;\r\n }\r\n\r\n.popover-tip--top__popover__12-19-5-alpha-4:before {\r\n -webkit-transform-origin: right bottom;\r\n transform-origin: right bottom;\r\n right: 50%;\r\n bottom: 0;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-5-alpha-4:before {\r\n -webkit-transform-origin: right top;\r\n transform-origin: right top;\r\n right: 0;\r\n top: 50%;\r\n }\r\n\r\n.popover-tip--right__popover__12-19-5-alpha-4:before {\r\n -webkit-transform-origin: left bottom;\r\n transform-origin: left bottom;\r\n left: 0;\r\n bottom: 50%;\r\n }\r\n";
258
- var styles = {"popover-body-container":"popover-body-container__popover__12-19-5-alpha-4","popover-body":"popover-body__popover__12-19-5-alpha-4","popover-body--no-padding":"popover-body--no-padding__popover__12-19-5-alpha-4","popover-tip":"popover-tip__popover__12-19-5-alpha-4","popover-tip--bottom":"popover-tip--bottom__popover__12-19-5-alpha-4","popover-tip--top":"popover-tip--top__popover__12-19-5-alpha-4","popover-tip--left":"popover-tip--left__popover__12-19-5-alpha-4","popover-tip--right":"popover-tip--right__popover__12-19-5-alpha-4"};
209
+ var css = ".popover-body-container__popover__12-19-5-alpha-6 {\r\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n border-radius: var(--BorderRadiusL, 4px);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n background: var(--BackgroundDefault, #FFFFFF);\r\n z-index: var(--ZIndexModal, 10001);\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n}\r\n\r\n.popover-body__popover__12-19-5-alpha-6 {\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n padding: var(--SpaceSM, 12px);\r\n font-size: var(--FontSizeDefault, 13px);\r\n color: var(--FontColorDefault, #000000);\r\n}\r\n\r\n.popover-body--no-padding__popover__12-19-5-alpha-6 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-5-alpha-6 {\r\n position: absolute;\r\n pointer-events: none;\r\n z-index: calc(var(--ZIndexModal, 10001) + 1);\r\n overflow: hidden;\r\n display: -webkit-box;\r\n display: -ms-flexbox;\r\n display: flex;\r\n -webkit-box-align: center;\r\n -ms-flex-align: center;\r\n align-items: center;\r\n -webkit-box-pack: center;\r\n -ms-flex-pack: center;\r\n justify-content: center;\r\n}\r\n\r\n.popover-tip__popover__12-19-5-alpha-6:before {\r\n content: '';\r\n position: absolute;\r\n display: block;\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n background-color: var(--BackgroundDefault, #FFFFFF);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n /*\r\n geometry FTW\r\n\r\n 2*$popoverTipSize\r\n _______ _______\r\n | /|\\ |\r\n | / | \\ | $popoverTipSize\r\n | / | \\ |\r\n |/______|______\\|\r\n since tip is rotated 45 degrees, its width and height is a\r\n diagonal of a square with side=$popoverTipSize, thus diagonal\r\n is sqrt(2) * $popoverTipSize.\r\n sqrt(2) ~= 1.414, 1.4 used here to prevent too much rounding\r\n */\r\n width: 11.2px;\r\n height: 11.2px;\r\n -webkit-transform: rotate(45deg);\r\n transform: rotate(45deg);\r\n }\r\n\r\n.popover-tip--bottom__popover__12-19-5-alpha-6,\r\n .popover-tip--top__popover__12-19-5-alpha-6 {\r\n width: 100%;\r\n border-top: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-bottom: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 9px;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-5-alpha-6,\r\n .popover-tip--right__popover__12-19-5-alpha-6 {\r\n border-left: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-right: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 100%;\r\n width: 9px;\r\n }\r\n\r\n/*\r\n To determine tip position, we need to rotate it\r\n along the \"tip\" point, after that, the \"tip\" point\r\n can be placed with exactly 50% offset from the origin\r\n so that it is centered.\r\n */\r\n\r\n.popover-tip--bottom__popover__12-19-5-alpha-6:before {\r\n -webkit-transform-origin: left top;\r\n transform-origin: left top;\r\n left: 50%;\r\n top: 0;\r\n }\r\n\r\n.popover-tip--top__popover__12-19-5-alpha-6:before {\r\n -webkit-transform-origin: right bottom;\r\n transform-origin: right bottom;\r\n right: 50%;\r\n bottom: 0;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-5-alpha-6:before {\r\n -webkit-transform-origin: right top;\r\n transform-origin: right top;\r\n right: 0;\r\n top: 50%;\r\n }\r\n\r\n.popover-tip--right__popover__12-19-5-alpha-6:before {\r\n -webkit-transform-origin: left bottom;\r\n transform-origin: left bottom;\r\n left: 0;\r\n bottom: 50%;\r\n }\r\n";
210
+ var styles = {"popover-body-container":"popover-body-container__popover__12-19-5-alpha-6","popover-body":"popover-body__popover__12-19-5-alpha-6","popover-body--no-padding":"popover-body--no-padding__popover__12-19-5-alpha-6","popover-tip":"popover-tip__popover__12-19-5-alpha-6","popover-tip--bottom":"popover-tip--bottom__popover__12-19-5-alpha-6","popover-tip--top":"popover-tip--top__popover__12-19-5-alpha-6","popover-tip--left":"popover-tip--left__popover__12-19-5-alpha-6","popover-tip--right":"popover-tip--right__popover__12-19-5-alpha-6"};
259
211
  styleInject(css);
260
212
 
261
213
  var PopoverBody = function PopoverBody(_ref) {
@@ -292,6 +244,9 @@ var throttle = function throttle(func, limit) {
292
244
  };
293
245
  };
294
246
 
247
+ var generateId = function generateId(prefix) {
248
+ return "".concat(prefix).concat(Math.random().toString(36).substring(7));
249
+ };
295
250
  var isFocusable = function isFocusable(element) {
296
251
  if (element.tabIndex < 0) {
297
252
  return false;
@@ -332,41 +287,8 @@ var focusFirstDescendant = function focusFirstDescendant(element) {
332
287
  }
333
288
  return false;
334
289
  };
335
- var findAllFocusableElementsInside = function findAllFocusableElementsInside(containerElement) {
336
- var focusableElements = [];
337
- var traverseDOM = function traverseDOM(element) {
338
- if (isFocusable(element)) {
339
- focusableElements.push(element);
340
- }
341
- var _arr2 = Array.from(element.childNodes);
342
- for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
343
- var child = _arr2[_i2];
344
- traverseDOM(child);
345
- }
346
- };
347
- traverseDOM(containerElement);
348
- return focusableElements;
349
- };
350
- var trapFocus = function trapFocus(element) {
351
- var focusableEls = findAllFocusableElementsInside(element);
352
- var _focusableEls = _slicedToArray(focusableEls, 1),
353
- firstFocusableEl = _focusableEls[0];
354
- var lastFocusableEl = focusableEls.pop();
355
- element.addEventListener('keydown', function (event) {
356
- var isTabPressed = event.key === 'Tab';
357
- if (!isTabPressed) {
358
- return;
359
- }
360
- if (event.shiftKey && document.activeElement === firstFocusableEl) {
361
- lastFocusableEl.focus();
362
- event.preventDefault();
363
- } else if (document.activeElement === lastFocusableEl) {
364
- firstFocusableEl.focus();
365
- event.preventDefault();
366
- }
367
- });
368
- };
369
290
 
291
+ var popoverContainerPrefix = 'popover-container-';
370
292
  var isScrollParent = function isScrollParent(element) {
371
293
  // Firefox wants us to check `-x` and `-y` variations as well
372
294
  var _getComputedStyle = getComputedStyle(element),
@@ -426,6 +348,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
426
348
  positionX: 0,
427
349
  positionY: 0
428
350
  };
351
+ _this.popoverContainerId = generateId(popoverContainerPrefix);
429
352
  _this.onResize = function () {
430
353
  return _this.adjustPosition();
431
354
  };
@@ -495,10 +418,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
495
418
  value: function componentDidMount() {
496
419
  this.mounted = true;
497
420
  this.adjustPosition();
498
- if (this.props.role === 'tooltip') {
499
- this.popoverContentRef.current.tabIndex = 0;
500
- this.popoverContentRef.current.focus();
501
- }
502
421
  if (this.props.trackScroll) {
503
422
  document.addEventListener('scroll', this.onScroll);
504
423
  window.addEventListener('resize', this.onResize);
@@ -506,9 +425,9 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
506
425
  this.props.containerElement.addEventListener('scroll', this.onScroll);
507
426
  }
508
427
  }
509
- if (this.popoverContentRef.current && this.props.role === 'dialog') {
428
+ if (this.popoverContentRef.current && !this.props.trapFocus) {
510
429
  if (!focusFirstDescendant(this.popoverContentRef.current)) {
511
- this.popoverContentRef.current.tabIndex = 0;
430
+ this.popoverContentRef.current.tabIndex = -1;
512
431
  this.popoverContentRef.current.focus();
513
432
  }
514
433
  }
@@ -519,9 +438,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
519
438
  if (this.props.containerElement !== previousProps.containerElement || this.props.getPopoverPosition !== previousProps.getPopoverPosition) {
520
439
  this.adjustPosition();
521
440
  }
522
- if (this.popoverContentRef.current && this.props.role === 'dialog') {
523
- trapFocus(this.popoverContentRef.current);
524
- }
525
441
  }
526
442
  }, {
527
443
  key: "componentWillUnmount",
@@ -566,15 +482,34 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
566
482
  left: tipPosition === 'right' && position.left - 8,
567
483
  right: tipPosition === 'left' && position.right - 8
568
484
  }
569
- }), React.createElement("div", {
485
+ }), this.props.trapFocus && React.createElement(FocusTrap, {
486
+ focusTrapOptions: {
487
+ fallbackFocus: "#".concat(this.popoverContainerId),
488
+ clickOutsideDeactivates: true
489
+ }
490
+ }, React.createElement("div", {
491
+ id: this.popoverContainerId,
570
492
  ref: this.popoverContentRef,
571
493
  style: _extends({
572
494
  position: 'absolute',
573
495
  pointerEvents: 'all'
574
496
  }, position),
497
+ tabIndex: -1,
575
498
  className: this.props.className,
576
499
  role: this.props.role,
577
- "aria-modal": this.props.role === 'dialog' ? 'true' : 'false',
500
+ "aria-modal": this.props.trapFocus ? 'true' : 'false',
501
+ onKeyDown: this.handleKeyDown
502
+ }, this.props.children)), !this.props.trapFocus && React.createElement("div", {
503
+ id: this.popoverContainerId,
504
+ ref: this.popoverContentRef,
505
+ style: _extends({
506
+ position: 'absolute',
507
+ pointerEvents: 'all'
508
+ }, position),
509
+ tabIndex: -1,
510
+ className: this.props.className,
511
+ role: this.props.role,
512
+ "aria-modal": this.props.trapFocus ? 'true' : 'false',
578
513
  onKeyDown: this.handleKeyDown
579
514
  }, this.props.children));
580
515
  }
@@ -711,6 +646,7 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
711
646
  zIndex: props.zIndex,
712
647
  trackScroll: props.trackScroll,
713
648
  role: this.props.role,
649
+ trapFocus: this.props.trapFocus,
714
650
  onEscapeAction: this.props.onEscapeAction
715
651
  }, props.body);
716
652
  if (!props.inline) {
@@ -805,7 +741,8 @@ var Popover = /*#__PURE__*/function (_React$Component) {
805
741
  onOuterAction: this.onOuterAction,
806
742
  onEscapeAction: this.onEscapeAction,
807
743
  isOpen: isOpen,
808
- role: this.props.role
744
+ role: this.props.role,
745
+ trapFocus: this.props.trapFocus
809
746
  }), childrenWithRef);
810
747
  }
811
748
  }]);
@@ -817,7 +754,8 @@ Popover.defaultProps = {
817
754
  zIndex: 19999,
818
755
  outerActionEvents: ['mousedown', 'touchstart'],
819
756
  getPopoverPosition: 'bottomLeft',
820
- role: 'dialog'
757
+ role: 'dialog',
758
+ trapFocus: 'true'
821
759
  };
822
760
 
823
761
  export default Popover;
package/dist/popover.js CHANGED
@@ -9,34 +9,8 @@ var React__default = _interopDefault(React);
9
9
  var globalConstants = require('@targetprocess/global-constants');
10
10
  var classNames = _interopDefault(require('classnames'));
11
11
  var ReactDOM = _interopDefault(require('react-dom'));
12
+ var FocusTrap = _interopDefault(require('focus-trap-react'));
12
13
 
13
- function _iterableToArrayLimit(r, l) {
14
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
15
- if (null != t) {
16
- var e,
17
- n,
18
- i,
19
- u,
20
- a = [],
21
- f = !0,
22
- o = !1;
23
- try {
24
- if (i = (t = t.call(r)).next, 0 === l) {
25
- if (Object(t) !== t) return;
26
- f = !1;
27
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
28
- } catch (r) {
29
- o = !0, n = r;
30
- } finally {
31
- try {
32
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
33
- } finally {
34
- if (o) throw n;
35
- }
36
- }
37
- return a;
38
- }
39
- }
40
14
  function _classCallCheck(instance, Constructor) {
41
15
  if (!(instance instanceof Constructor)) {
42
16
  throw new TypeError("Cannot call a class as a function");
@@ -116,28 +90,6 @@ function _possibleConstructorReturn(self, call) {
116
90
  }
117
91
  return _assertThisInitialized(self);
118
92
  }
119
- function _slicedToArray(arr, i) {
120
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
121
- }
122
- function _arrayWithHoles(arr) {
123
- if (Array.isArray(arr)) return arr;
124
- }
125
- function _unsupportedIterableToArray(o, minLen) {
126
- if (!o) return;
127
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
128
- var n = Object.prototype.toString.call(o).slice(8, -1);
129
- if (n === "Object" && o.constructor) n = o.constructor.name;
130
- if (n === "Map" || n === "Set") return Array.from(o);
131
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
132
- }
133
- function _arrayLikeToArray(arr, len) {
134
- if (len == null || len > arr.length) len = arr.length;
135
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
136
- return arr2;
137
- }
138
- function _nonIterableRest() {
139
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
140
- }
141
93
  function _toPrimitive(input, hint) {
142
94
  if (typeof input !== "object" || input === null) return input;
143
95
  var prim = input[Symbol.toPrimitive];
@@ -261,8 +213,8 @@ function styleInject(css, ref) {
261
213
  }
262
214
  }
263
215
 
264
- var css = ".popover-body-container__popover__12-19-5-alpha-4 {\r\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n border-radius: var(--BorderRadiusL, 4px);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n background: var(--BackgroundDefault, #FFFFFF);\r\n z-index: var(--ZIndexModal, 10001);\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n}\r\n\r\n.popover-body__popover__12-19-5-alpha-4 {\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n padding: var(--SpaceSM, 12px);\r\n font-size: var(--FontSizeDefault, 13px);\r\n color: var(--FontColorDefault, #000000);\r\n}\r\n\r\n.popover-body--no-padding__popover__12-19-5-alpha-4 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-5-alpha-4 {\r\n position: absolute;\r\n pointer-events: none;\r\n z-index: calc(var(--ZIndexModal, 10001) + 1);\r\n overflow: hidden;\r\n display: -webkit-box;\r\n display: -ms-flexbox;\r\n display: flex;\r\n -webkit-box-align: center;\r\n -ms-flex-align: center;\r\n align-items: center;\r\n -webkit-box-pack: center;\r\n -ms-flex-pack: center;\r\n justify-content: center;\r\n}\r\n\r\n.popover-tip__popover__12-19-5-alpha-4:before {\r\n content: '';\r\n position: absolute;\r\n display: block;\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n background-color: var(--BackgroundDefault, #FFFFFF);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n /*\r\n geometry FTW\r\n\r\n 2*$popoverTipSize\r\n _______ _______\r\n | /|\\ |\r\n | / | \\ | $popoverTipSize\r\n | / | \\ |\r\n |/______|______\\|\r\n since tip is rotated 45 degrees, its width and height is a\r\n diagonal of a square with side=$popoverTipSize, thus diagonal\r\n is sqrt(2) * $popoverTipSize.\r\n sqrt(2) ~= 1.414, 1.4 used here to prevent too much rounding\r\n */\r\n width: 11.2px;\r\n height: 11.2px;\r\n -webkit-transform: rotate(45deg);\r\n transform: rotate(45deg);\r\n }\r\n\r\n.popover-tip--bottom__popover__12-19-5-alpha-4,\r\n .popover-tip--top__popover__12-19-5-alpha-4 {\r\n width: 100%;\r\n border-top: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-bottom: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 9px;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-5-alpha-4,\r\n .popover-tip--right__popover__12-19-5-alpha-4 {\r\n border-left: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-right: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 100%;\r\n width: 9px;\r\n }\r\n\r\n/*\r\n To determine tip position, we need to rotate it\r\n along the \"tip\" point, after that, the \"tip\" point\r\n can be placed with exactly 50% offset from the origin\r\n so that it is centered.\r\n */\r\n\r\n.popover-tip--bottom__popover__12-19-5-alpha-4:before {\r\n -webkit-transform-origin: left top;\r\n transform-origin: left top;\r\n left: 50%;\r\n top: 0;\r\n }\r\n\r\n.popover-tip--top__popover__12-19-5-alpha-4:before {\r\n -webkit-transform-origin: right bottom;\r\n transform-origin: right bottom;\r\n right: 50%;\r\n bottom: 0;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-5-alpha-4:before {\r\n -webkit-transform-origin: right top;\r\n transform-origin: right top;\r\n right: 0;\r\n top: 50%;\r\n }\r\n\r\n.popover-tip--right__popover__12-19-5-alpha-4:before {\r\n -webkit-transform-origin: left bottom;\r\n transform-origin: left bottom;\r\n left: 0;\r\n bottom: 50%;\r\n }\r\n";
265
- var styles = {"popover-body-container":"popover-body-container__popover__12-19-5-alpha-4","popover-body":"popover-body__popover__12-19-5-alpha-4","popover-body--no-padding":"popover-body--no-padding__popover__12-19-5-alpha-4","popover-tip":"popover-tip__popover__12-19-5-alpha-4","popover-tip--bottom":"popover-tip--bottom__popover__12-19-5-alpha-4","popover-tip--top":"popover-tip--top__popover__12-19-5-alpha-4","popover-tip--left":"popover-tip--left__popover__12-19-5-alpha-4","popover-tip--right":"popover-tip--right__popover__12-19-5-alpha-4"};
216
+ var css = ".popover-body-container__popover__12-19-5-alpha-6 {\r\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n border-radius: var(--BorderRadiusL, 4px);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n background: var(--BackgroundDefault, #FFFFFF);\r\n z-index: var(--ZIndexModal, 10001);\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n}\r\n\r\n.popover-body__popover__12-19-5-alpha-6 {\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n padding: var(--SpaceSM, 12px);\r\n font-size: var(--FontSizeDefault, 13px);\r\n color: var(--FontColorDefault, #000000);\r\n}\r\n\r\n.popover-body--no-padding__popover__12-19-5-alpha-6 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-5-alpha-6 {\r\n position: absolute;\r\n pointer-events: none;\r\n z-index: calc(var(--ZIndexModal, 10001) + 1);\r\n overflow: hidden;\r\n display: -webkit-box;\r\n display: -ms-flexbox;\r\n display: flex;\r\n -webkit-box-align: center;\r\n -ms-flex-align: center;\r\n align-items: center;\r\n -webkit-box-pack: center;\r\n -ms-flex-pack: center;\r\n justify-content: center;\r\n}\r\n\r\n.popover-tip__popover__12-19-5-alpha-6:before {\r\n content: '';\r\n position: absolute;\r\n display: block;\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n background-color: var(--BackgroundDefault, #FFFFFF);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n /*\r\n geometry FTW\r\n\r\n 2*$popoverTipSize\r\n _______ _______\r\n | /|\\ |\r\n | / | \\ | $popoverTipSize\r\n | / | \\ |\r\n |/______|______\\|\r\n since tip is rotated 45 degrees, its width and height is a\r\n diagonal of a square with side=$popoverTipSize, thus diagonal\r\n is sqrt(2) * $popoverTipSize.\r\n sqrt(2) ~= 1.414, 1.4 used here to prevent too much rounding\r\n */\r\n width: 11.2px;\r\n height: 11.2px;\r\n -webkit-transform: rotate(45deg);\r\n transform: rotate(45deg);\r\n }\r\n\r\n.popover-tip--bottom__popover__12-19-5-alpha-6,\r\n .popover-tip--top__popover__12-19-5-alpha-6 {\r\n width: 100%;\r\n border-top: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-bottom: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 9px;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-5-alpha-6,\r\n .popover-tip--right__popover__12-19-5-alpha-6 {\r\n border-left: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-right: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 100%;\r\n width: 9px;\r\n }\r\n\r\n/*\r\n To determine tip position, we need to rotate it\r\n along the \"tip\" point, after that, the \"tip\" point\r\n can be placed with exactly 50% offset from the origin\r\n so that it is centered.\r\n */\r\n\r\n.popover-tip--bottom__popover__12-19-5-alpha-6:before {\r\n -webkit-transform-origin: left top;\r\n transform-origin: left top;\r\n left: 50%;\r\n top: 0;\r\n }\r\n\r\n.popover-tip--top__popover__12-19-5-alpha-6:before {\r\n -webkit-transform-origin: right bottom;\r\n transform-origin: right bottom;\r\n right: 50%;\r\n bottom: 0;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-5-alpha-6:before {\r\n -webkit-transform-origin: right top;\r\n transform-origin: right top;\r\n right: 0;\r\n top: 50%;\r\n }\r\n\r\n.popover-tip--right__popover__12-19-5-alpha-6:before {\r\n -webkit-transform-origin: left bottom;\r\n transform-origin: left bottom;\r\n left: 0;\r\n bottom: 50%;\r\n }\r\n";
217
+ var styles = {"popover-body-container":"popover-body-container__popover__12-19-5-alpha-6","popover-body":"popover-body__popover__12-19-5-alpha-6","popover-body--no-padding":"popover-body--no-padding__popover__12-19-5-alpha-6","popover-tip":"popover-tip__popover__12-19-5-alpha-6","popover-tip--bottom":"popover-tip--bottom__popover__12-19-5-alpha-6","popover-tip--top":"popover-tip--top__popover__12-19-5-alpha-6","popover-tip--left":"popover-tip--left__popover__12-19-5-alpha-6","popover-tip--right":"popover-tip--right__popover__12-19-5-alpha-6"};
266
218
  styleInject(css);
267
219
 
268
220
  var PopoverBody = function PopoverBody(_ref) {
@@ -299,6 +251,9 @@ var throttle = function throttle(func, limit) {
299
251
  };
300
252
  };
301
253
 
254
+ var generateId = function generateId(prefix) {
255
+ return "".concat(prefix).concat(Math.random().toString(36).substring(7));
256
+ };
302
257
  var isFocusable = function isFocusable(element) {
303
258
  if (element.tabIndex < 0) {
304
259
  return false;
@@ -339,41 +294,8 @@ var focusFirstDescendant = function focusFirstDescendant(element) {
339
294
  }
340
295
  return false;
341
296
  };
342
- var findAllFocusableElementsInside = function findAllFocusableElementsInside(containerElement) {
343
- var focusableElements = [];
344
- var traverseDOM = function traverseDOM(element) {
345
- if (isFocusable(element)) {
346
- focusableElements.push(element);
347
- }
348
- var _arr2 = Array.from(element.childNodes);
349
- for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
350
- var child = _arr2[_i2];
351
- traverseDOM(child);
352
- }
353
- };
354
- traverseDOM(containerElement);
355
- return focusableElements;
356
- };
357
- var trapFocus = function trapFocus(element) {
358
- var focusableEls = findAllFocusableElementsInside(element);
359
- var _focusableEls = _slicedToArray(focusableEls, 1),
360
- firstFocusableEl = _focusableEls[0];
361
- var lastFocusableEl = focusableEls.pop();
362
- element.addEventListener('keydown', function (event) {
363
- var isTabPressed = event.key === 'Tab';
364
- if (!isTabPressed) {
365
- return;
366
- }
367
- if (event.shiftKey && document.activeElement === firstFocusableEl) {
368
- lastFocusableEl.focus();
369
- event.preventDefault();
370
- } else if (document.activeElement === lastFocusableEl) {
371
- firstFocusableEl.focus();
372
- event.preventDefault();
373
- }
374
- });
375
- };
376
297
 
298
+ var popoverContainerPrefix = 'popover-container-';
377
299
  var isScrollParent = function isScrollParent(element) {
378
300
  // Firefox wants us to check `-x` and `-y` variations as well
379
301
  var _getComputedStyle = getComputedStyle(element),
@@ -433,6 +355,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
433
355
  positionX: 0,
434
356
  positionY: 0
435
357
  };
358
+ _this.popoverContainerId = generateId(popoverContainerPrefix);
436
359
  _this.onResize = function () {
437
360
  return _this.adjustPosition();
438
361
  };
@@ -502,10 +425,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
502
425
  value: function componentDidMount() {
503
426
  this.mounted = true;
504
427
  this.adjustPosition();
505
- if (this.props.role === 'tooltip') {
506
- this.popoverContentRef.current.tabIndex = 0;
507
- this.popoverContentRef.current.focus();
508
- }
509
428
  if (this.props.trackScroll) {
510
429
  document.addEventListener('scroll', this.onScroll);
511
430
  window.addEventListener('resize', this.onResize);
@@ -513,9 +432,9 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
513
432
  this.props.containerElement.addEventListener('scroll', this.onScroll);
514
433
  }
515
434
  }
516
- if (this.popoverContentRef.current && this.props.role === 'dialog') {
435
+ if (this.popoverContentRef.current && !this.props.trapFocus) {
517
436
  if (!focusFirstDescendant(this.popoverContentRef.current)) {
518
- this.popoverContentRef.current.tabIndex = 0;
437
+ this.popoverContentRef.current.tabIndex = -1;
519
438
  this.popoverContentRef.current.focus();
520
439
  }
521
440
  }
@@ -526,9 +445,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
526
445
  if (this.props.containerElement !== previousProps.containerElement || this.props.getPopoverPosition !== previousProps.getPopoverPosition) {
527
446
  this.adjustPosition();
528
447
  }
529
- if (this.popoverContentRef.current && this.props.role === 'dialog') {
530
- trapFocus(this.popoverContentRef.current);
531
- }
532
448
  }
533
449
  }, {
534
450
  key: "componentWillUnmount",
@@ -573,15 +489,34 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
573
489
  left: tipPosition === 'right' && position.left - 8,
574
490
  right: tipPosition === 'left' && position.right - 8
575
491
  }
576
- }), React__default.createElement("div", {
492
+ }), this.props.trapFocus && React__default.createElement(FocusTrap, {
493
+ focusTrapOptions: {
494
+ fallbackFocus: "#".concat(this.popoverContainerId),
495
+ clickOutsideDeactivates: true
496
+ }
497
+ }, React__default.createElement("div", {
498
+ id: this.popoverContainerId,
577
499
  ref: this.popoverContentRef,
578
500
  style: _extends({
579
501
  position: 'absolute',
580
502
  pointerEvents: 'all'
581
503
  }, position),
504
+ tabIndex: -1,
582
505
  className: this.props.className,
583
506
  role: this.props.role,
584
- "aria-modal": this.props.role === 'dialog' ? 'true' : 'false',
507
+ "aria-modal": this.props.trapFocus ? 'true' : 'false',
508
+ onKeyDown: this.handleKeyDown
509
+ }, this.props.children)), !this.props.trapFocus && React__default.createElement("div", {
510
+ id: this.popoverContainerId,
511
+ ref: this.popoverContentRef,
512
+ style: _extends({
513
+ position: 'absolute',
514
+ pointerEvents: 'all'
515
+ }, position),
516
+ tabIndex: -1,
517
+ className: this.props.className,
518
+ role: this.props.role,
519
+ "aria-modal": this.props.trapFocus ? 'true' : 'false',
585
520
  onKeyDown: this.handleKeyDown
586
521
  }, this.props.children));
587
522
  }
@@ -718,6 +653,7 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
718
653
  zIndex: props.zIndex,
719
654
  trackScroll: props.trackScroll,
720
655
  role: this.props.role,
656
+ trapFocus: this.props.trapFocus,
721
657
  onEscapeAction: this.props.onEscapeAction
722
658
  }, props.body);
723
659
  if (!props.inline) {
@@ -812,7 +748,8 @@ var Popover = /*#__PURE__*/function (_React$Component) {
812
748
  onOuterAction: this.onOuterAction,
813
749
  onEscapeAction: this.onEscapeAction,
814
750
  isOpen: isOpen,
815
- role: this.props.role
751
+ role: this.props.role,
752
+ trapFocus: this.props.trapFocus
816
753
  }), childrenWithRef);
817
754
  }
818
755
  }]);
@@ -824,7 +761,8 @@ Popover.defaultProps = {
824
761
  zIndex: 19999,
825
762
  outerActionEvents: ['mousedown', 'touchstart'],
826
763
  getPopoverPosition: 'bottomLeft',
827
- role: 'dialog'
764
+ role: 'dialog',
765
+ trapFocus: 'true'
828
766
  };
829
767
 
830
768
  exports.Popover = Popover;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@targetprocess/popover",
3
- "version": "12.19.5-alpha.4",
3
+ "version": "12.19.5-alpha.6",
4
4
  "description": "",
5
5
  "main": "dist/popover.js",
6
6
  "module": "dist/popover.es.js",
@@ -14,6 +14,7 @@
14
14
  "dependencies": {
15
15
  "@targetprocess/global-constants": "^12.7.3",
16
16
  "classnames": "^2.2.5",
17
+ "focus-trap-react": "^7.0.0",
17
18
  "prop-types": "^15.6.0",
18
19
  "react": "^16.7.0",
19
20
  "react-dom": "^16.7.0"
@@ -21,5 +22,5 @@
21
22
  "publishConfig": {
22
23
  "access": "public"
23
24
  },
24
- "gitHead": "72a67af985f910913188a875ae2c94f190213bd2"
25
+ "gitHead": "063e28b5e29833360d4d3da0c9092cc2a5911f78"
25
26
  }