@targetprocess/popover 12.19.5-alpha.3 → 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,18 +161,6 @@ export class PopoverContainer extends React.Component<
154
161
  this.mounted = true
155
162
  this.adjustPosition()
156
163
 
157
- if (this.popoverContentRef.current && this.props.role === 'dialog') {
158
- if (!focusFirstDescendant(this.popoverContentRef.current)) {
159
- this.popoverContentRef.current.tabIndex = 0
160
- this.popoverContentRef.current.focus()
161
- }
162
- trapFocus(this.popoverContentRef.current)
163
- }
164
- if (this.props.role === 'tooltip') {
165
- this.popoverContentRef.current.tabIndex = 0
166
- this.popoverContentRef.current.focus()
167
- }
168
-
169
164
  if (this.props.trackScroll) {
170
165
  document.addEventListener('scroll', this.onScroll)
171
166
  window.addEventListener('resize', this.onResize)
@@ -173,6 +168,13 @@ export class PopoverContainer extends React.Component<
173
168
  this.props.containerElement.addEventListener('scroll', this.onScroll)
174
169
  }
175
170
  }
171
+
172
+ if (this.popoverContentRef.current && !this.props.trapFocus) {
173
+ if (!focusFirstDescendant(this.popoverContentRef.current)) {
174
+ this.popoverContentRef.current.tabIndex = -1
175
+ this.popoverContentRef.current.focus()
176
+ }
177
+ }
176
178
  }
177
179
 
178
180
  componentDidUpdate(previousProps) {
@@ -270,20 +272,50 @@ export class PopoverContainer extends React.Component<
270
272
  }}
271
273
  />
272
274
  )}
273
- <div
274
- ref={this.popoverContentRef}
275
- style={{
276
- position: 'absolute',
277
- pointerEvents: 'all',
278
- ...position
279
- }}
280
- className={this.props.className}
281
- role={this.props.role}
282
- aria-modal={this.props.role === 'dialog' ? 'true' : 'false'}
283
- onKeyDown={this.handleKeyDown}
284
- >
285
- {this.props.children}
286
- </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
+ )}
287
319
  </div>
288
320
  )
289
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-3 {\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-3 {\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-3 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-5-alpha-3 {\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-3: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-3,\r\n .popover-tip--top__popover__12-19-5-alpha-3 {\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-3,\r\n .popover-tip--right__popover__12-19-5-alpha-3 {\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-3: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-3: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-3: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-3: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-3","popover-body":"popover-body__popover__12-19-5-alpha-3","popover-body--no-padding":"popover-body--no-padding__popover__12-19-5-alpha-3","popover-tip":"popover-tip__popover__12-19-5-alpha-3","popover-tip--bottom":"popover-tip--bottom__popover__12-19-5-alpha-3","popover-tip--top":"popover-tip--top__popover__12-19-5-alpha-3","popover-tip--left":"popover-tip--left__popover__12-19-5-alpha-3","popover-tip--right":"popover-tip--right__popover__12-19-5-alpha-3"};
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;
@@ -299,6 +254,9 @@ var isFocusable = function isFocusable(element) {
299
254
  if ('disabled' in element && element.disabled) {
300
255
  return false;
301
256
  }
257
+ if (element.tabIndex === 0) {
258
+ return true;
259
+ }
302
260
  switch (element.nodeName) {
303
261
  case 'A':
304
262
  return element.href;
@@ -329,41 +287,8 @@ var focusFirstDescendant = function focusFirstDescendant(element) {
329
287
  }
330
288
  return false;
331
289
  };
332
- var findAllFocusableElementsInside = function findAllFocusableElementsInside(containerElement) {
333
- var focusableElements = [];
334
- var traverseDOM = function traverseDOM(element) {
335
- if (isFocusable(element)) {
336
- focusableElements.push(element);
337
- }
338
- var _arr2 = Array.from(element.childNodes);
339
- for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
340
- var child = _arr2[_i2];
341
- traverseDOM(child);
342
- }
343
- };
344
- traverseDOM(containerElement);
345
- return focusableElements;
346
- };
347
- var trapFocus = function trapFocus(element) {
348
- var focusableEls = findAllFocusableElementsInside(element);
349
- var _focusableEls = _slicedToArray(focusableEls, 1),
350
- firstFocusableEl = _focusableEls[0];
351
- var lastFocusableEl = focusableEls.pop();
352
- element.addEventListener('keydown', function (event) {
353
- var isTabPressed = event.key === 'Tab';
354
- if (!isTabPressed) {
355
- return;
356
- }
357
- if (event.shiftKey && document.activeElement === firstFocusableEl) {
358
- lastFocusableEl.focus();
359
- event.preventDefault();
360
- } else if (document.activeElement === lastFocusableEl) {
361
- firstFocusableEl.focus();
362
- event.preventDefault();
363
- }
364
- });
365
- };
366
290
 
291
+ var popoverContainerPrefix = 'popover-container-';
367
292
  var isScrollParent = function isScrollParent(element) {
368
293
  // Firefox wants us to check `-x` and `-y` variations as well
369
294
  var _getComputedStyle = getComputedStyle(element),
@@ -423,6 +348,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
423
348
  positionX: 0,
424
349
  positionY: 0
425
350
  };
351
+ _this.popoverContainerId = generateId(popoverContainerPrefix);
426
352
  _this.onResize = function () {
427
353
  return _this.adjustPosition();
428
354
  };
@@ -492,17 +418,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
492
418
  value: function componentDidMount() {
493
419
  this.mounted = true;
494
420
  this.adjustPosition();
495
- if (this.popoverContentRef.current && this.props.role === 'dialog') {
496
- if (!focusFirstDescendant(this.popoverContentRef.current)) {
497
- this.popoverContentRef.current.tabIndex = 0;
498
- this.popoverContentRef.current.focus();
499
- }
500
- trapFocus(this.popoverContentRef.current);
501
- }
502
- if (this.props.role === 'tooltip') {
503
- this.popoverContentRef.current.tabIndex = 0;
504
- this.popoverContentRef.current.focus();
505
- }
506
421
  if (this.props.trackScroll) {
507
422
  document.addEventListener('scroll', this.onScroll);
508
423
  window.addEventListener('resize', this.onResize);
@@ -510,6 +425,12 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
510
425
  this.props.containerElement.addEventListener('scroll', this.onScroll);
511
426
  }
512
427
  }
428
+ if (this.popoverContentRef.current && !this.props.trapFocus) {
429
+ if (!focusFirstDescendant(this.popoverContentRef.current)) {
430
+ this.popoverContentRef.current.tabIndex = -1;
431
+ this.popoverContentRef.current.focus();
432
+ }
433
+ }
513
434
  }
514
435
  }, {
515
436
  key: "componentDidUpdate",
@@ -561,15 +482,34 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
561
482
  left: tipPosition === 'right' && position.left - 8,
562
483
  right: tipPosition === 'left' && position.right - 8
563
484
  }
564
- }), 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,
565
492
  ref: this.popoverContentRef,
566
493
  style: _extends({
567
494
  position: 'absolute',
568
495
  pointerEvents: 'all'
569
496
  }, position),
497
+ tabIndex: -1,
570
498
  className: this.props.className,
571
499
  role: this.props.role,
572
- "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',
573
513
  onKeyDown: this.handleKeyDown
574
514
  }, this.props.children));
575
515
  }
@@ -706,6 +646,7 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
706
646
  zIndex: props.zIndex,
707
647
  trackScroll: props.trackScroll,
708
648
  role: this.props.role,
649
+ trapFocus: this.props.trapFocus,
709
650
  onEscapeAction: this.props.onEscapeAction
710
651
  }, props.body);
711
652
  if (!props.inline) {
@@ -800,7 +741,8 @@ var Popover = /*#__PURE__*/function (_React$Component) {
800
741
  onOuterAction: this.onOuterAction,
801
742
  onEscapeAction: this.onEscapeAction,
802
743
  isOpen: isOpen,
803
- role: this.props.role
744
+ role: this.props.role,
745
+ trapFocus: this.props.trapFocus
804
746
  }), childrenWithRef);
805
747
  }
806
748
  }]);
@@ -812,7 +754,8 @@ Popover.defaultProps = {
812
754
  zIndex: 19999,
813
755
  outerActionEvents: ['mousedown', 'touchstart'],
814
756
  getPopoverPosition: 'bottomLeft',
815
- role: 'dialog'
757
+ role: 'dialog',
758
+ trapFocus: 'true'
816
759
  };
817
760
 
818
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-3 {\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-3 {\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-3 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-5-alpha-3 {\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-3: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-3,\r\n .popover-tip--top__popover__12-19-5-alpha-3 {\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-3,\r\n .popover-tip--right__popover__12-19-5-alpha-3 {\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-3: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-3: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-3: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-3: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-3","popover-body":"popover-body__popover__12-19-5-alpha-3","popover-body--no-padding":"popover-body--no-padding__popover__12-19-5-alpha-3","popover-tip":"popover-tip__popover__12-19-5-alpha-3","popover-tip--bottom":"popover-tip--bottom__popover__12-19-5-alpha-3","popover-tip--top":"popover-tip--top__popover__12-19-5-alpha-3","popover-tip--left":"popover-tip--left__popover__12-19-5-alpha-3","popover-tip--right":"popover-tip--right__popover__12-19-5-alpha-3"};
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;
@@ -306,6 +261,9 @@ var isFocusable = function isFocusable(element) {
306
261
  if ('disabled' in element && element.disabled) {
307
262
  return false;
308
263
  }
264
+ if (element.tabIndex === 0) {
265
+ return true;
266
+ }
309
267
  switch (element.nodeName) {
310
268
  case 'A':
311
269
  return element.href;
@@ -336,41 +294,8 @@ var focusFirstDescendant = function focusFirstDescendant(element) {
336
294
  }
337
295
  return false;
338
296
  };
339
- var findAllFocusableElementsInside = function findAllFocusableElementsInside(containerElement) {
340
- var focusableElements = [];
341
- var traverseDOM = function traverseDOM(element) {
342
- if (isFocusable(element)) {
343
- focusableElements.push(element);
344
- }
345
- var _arr2 = Array.from(element.childNodes);
346
- for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
347
- var child = _arr2[_i2];
348
- traverseDOM(child);
349
- }
350
- };
351
- traverseDOM(containerElement);
352
- return focusableElements;
353
- };
354
- var trapFocus = function trapFocus(element) {
355
- var focusableEls = findAllFocusableElementsInside(element);
356
- var _focusableEls = _slicedToArray(focusableEls, 1),
357
- firstFocusableEl = _focusableEls[0];
358
- var lastFocusableEl = focusableEls.pop();
359
- element.addEventListener('keydown', function (event) {
360
- var isTabPressed = event.key === 'Tab';
361
- if (!isTabPressed) {
362
- return;
363
- }
364
- if (event.shiftKey && document.activeElement === firstFocusableEl) {
365
- lastFocusableEl.focus();
366
- event.preventDefault();
367
- } else if (document.activeElement === lastFocusableEl) {
368
- firstFocusableEl.focus();
369
- event.preventDefault();
370
- }
371
- });
372
- };
373
297
 
298
+ var popoverContainerPrefix = 'popover-container-';
374
299
  var isScrollParent = function isScrollParent(element) {
375
300
  // Firefox wants us to check `-x` and `-y` variations as well
376
301
  var _getComputedStyle = getComputedStyle(element),
@@ -430,6 +355,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
430
355
  positionX: 0,
431
356
  positionY: 0
432
357
  };
358
+ _this.popoverContainerId = generateId(popoverContainerPrefix);
433
359
  _this.onResize = function () {
434
360
  return _this.adjustPosition();
435
361
  };
@@ -499,17 +425,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
499
425
  value: function componentDidMount() {
500
426
  this.mounted = true;
501
427
  this.adjustPosition();
502
- if (this.popoverContentRef.current && this.props.role === 'dialog') {
503
- if (!focusFirstDescendant(this.popoverContentRef.current)) {
504
- this.popoverContentRef.current.tabIndex = 0;
505
- this.popoverContentRef.current.focus();
506
- }
507
- trapFocus(this.popoverContentRef.current);
508
- }
509
- if (this.props.role === 'tooltip') {
510
- this.popoverContentRef.current.tabIndex = 0;
511
- this.popoverContentRef.current.focus();
512
- }
513
428
  if (this.props.trackScroll) {
514
429
  document.addEventListener('scroll', this.onScroll);
515
430
  window.addEventListener('resize', this.onResize);
@@ -517,6 +432,12 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
517
432
  this.props.containerElement.addEventListener('scroll', this.onScroll);
518
433
  }
519
434
  }
435
+ if (this.popoverContentRef.current && !this.props.trapFocus) {
436
+ if (!focusFirstDescendant(this.popoverContentRef.current)) {
437
+ this.popoverContentRef.current.tabIndex = -1;
438
+ this.popoverContentRef.current.focus();
439
+ }
440
+ }
520
441
  }
521
442
  }, {
522
443
  key: "componentDidUpdate",
@@ -568,15 +489,34 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
568
489
  left: tipPosition === 'right' && position.left - 8,
569
490
  right: tipPosition === 'left' && position.right - 8
570
491
  }
571
- }), 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,
572
499
  ref: this.popoverContentRef,
573
500
  style: _extends({
574
501
  position: 'absolute',
575
502
  pointerEvents: 'all'
576
503
  }, position),
504
+ tabIndex: -1,
577
505
  className: this.props.className,
578
506
  role: this.props.role,
579
- "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',
580
520
  onKeyDown: this.handleKeyDown
581
521
  }, this.props.children));
582
522
  }
@@ -713,6 +653,7 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
713
653
  zIndex: props.zIndex,
714
654
  trackScroll: props.trackScroll,
715
655
  role: this.props.role,
656
+ trapFocus: this.props.trapFocus,
716
657
  onEscapeAction: this.props.onEscapeAction
717
658
  }, props.body);
718
659
  if (!props.inline) {
@@ -807,7 +748,8 @@ var Popover = /*#__PURE__*/function (_React$Component) {
807
748
  onOuterAction: this.onOuterAction,
808
749
  onEscapeAction: this.onEscapeAction,
809
750
  isOpen: isOpen,
810
- role: this.props.role
751
+ role: this.props.role,
752
+ trapFocus: this.props.trapFocus
811
753
  }), childrenWithRef);
812
754
  }
813
755
  }]);
@@ -819,7 +761,8 @@ Popover.defaultProps = {
819
761
  zIndex: 19999,
820
762
  outerActionEvents: ['mousedown', 'touchstart'],
821
763
  getPopoverPosition: 'bottomLeft',
822
- role: 'dialog'
764
+ role: 'dialog',
765
+ trapFocus: 'true'
823
766
  };
824
767
 
825
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.3",
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": "6acc350de401d2739358a5a64f0a5e923e9a7c08"
25
+ "gitHead": "063e28b5e29833360d4d3da0c9092cc2a5911f78"
25
26
  }