@targetprocess/popover 12.19.5-alpha.8 → 12.19.7-alpha.3

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,7 +84,6 @@ export type PopoverProps = {
84
84
  className?: string
85
85
  trackScroll?: boolean
86
86
  role?: 'tooltip' | 'dialog'
87
- trapFocus?: boolean
88
87
  }
89
88
 
90
89
  export type PopoverState = {
@@ -123,16 +122,13 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
123
122
  zIndex: PropTypes.number,
124
123
  trackScroll: PropTypes.bool,
125
124
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
126
- role: PropTypes.oneOf(['tooltip', 'dialog']),
127
- trapFocus: PropTypes.bool
125
+ role: PropTypes.oneOf(['tooltip', 'dialog'])
128
126
  }
129
127
 
130
128
  static defaultProps = {
131
129
  zIndex: 19999,
132
130
  outerActionEvents: ['mousedown', 'touchstart'],
133
- getPopoverPosition: 'bottomLeft',
134
- role: 'dialog',
135
- trapFocus: 'true'
131
+ getPopoverPosition: 'bottomLeft'
136
132
  }
137
133
 
138
134
  state = {
@@ -179,7 +175,6 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
179
175
  onEscapeAction={this.onEscapeAction}
180
176
  isOpen={isOpen}
181
177
  role={this.props.role}
182
- trapFocus={this.props.trapFocus}
183
178
  >
184
179
  {childrenWithRef}
185
180
  </StatelessPopover>
@@ -7,10 +7,7 @@ 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 FocusTrap from 'focus-trap-react'
11
- import {generateId, focusFirstDescendant} from '../../base/utils/ariaUtils'
12
-
13
- const popoverContainerPrefix = 'popover-container-'
10
+ import {focusFirstDescendant} from '../../base/utils/ariaUtils'
14
11
 
15
12
  type PopoverContainerProps = {
16
13
  containerElement?: HTMLElement
@@ -23,7 +20,6 @@ type PopoverContainerProps = {
23
20
  showTip?: boolean
24
21
  zIndex: number
25
22
  role?: 'tooltip' | 'dialog'
26
- trapFocus?: boolean
27
23
  onEscapeAction: (event: Event) => void
28
24
  }
29
25
 
@@ -95,7 +91,6 @@ export class PopoverContainer extends React.Component<
95
91
  className: PropTypes.string,
96
92
  trackScroll: PropTypes.bool,
97
93
  role: PropTypes.oneOf(['tooltip', 'dialog']),
98
- trapFocus: PropTypes.bool,
99
94
  onEscapeAction: PropTypes.func
100
95
  }
101
96
 
@@ -112,8 +107,6 @@ export class PopoverContainer extends React.Component<
112
107
  positionY: 0
113
108
  }
114
109
 
115
- popoverContainerId = generateId(popoverContainerPrefix)
116
-
117
110
  adjustPosition() {
118
111
  if (!this.mounted) {
119
112
  return
@@ -161,6 +154,13 @@ export class PopoverContainer extends React.Component<
161
154
  this.mounted = true
162
155
  this.adjustPosition()
163
156
 
157
+ if (this.popoverContentRef.current) {
158
+ if (!focusFirstDescendant(this.popoverContentRef.current)) {
159
+ this.popoverContentRef.current.tabIndex = 0
160
+ this.popoverContentRef.current.focus()
161
+ }
162
+ }
163
+
164
164
  if (this.props.trackScroll) {
165
165
  document.addEventListener('scroll', this.onScroll)
166
166
  window.addEventListener('resize', this.onResize)
@@ -168,13 +168,6 @@ export class PopoverContainer extends React.Component<
168
168
  this.props.containerElement.addEventListener('scroll', this.onScroll)
169
169
  }
170
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
- }
178
171
  }
179
172
 
180
173
  componentDidUpdate(previousProps) {
@@ -216,7 +209,6 @@ export class PopoverContainer extends React.Component<
216
209
 
217
210
  handleKeyDown = event => {
218
211
  if (event.key === 'Escape') {
219
- event.stopPropagation()
220
212
  this.props.onEscapeAction(event)
221
213
  }
222
214
  }
@@ -272,50 +264,20 @@ export class PopoverContainer extends React.Component<
272
264
  }}
273
265
  />
274
266
  )}
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
- )}
267
+ <div
268
+ ref={this.popoverContentRef}
269
+ aria-modal="true"
270
+ style={{
271
+ position: 'absolute',
272
+ pointerEvents: 'all',
273
+ ...position
274
+ }}
275
+ className={this.props.className}
276
+ role={this.props.role}
277
+ onKeyDown={this.handleKeyDown}
278
+ >
279
+ {this.props.children}
280
+ </div>
319
281
  </div>
320
282
  )
321
283
  }
@@ -19,7 +19,6 @@ export type StatelessPopoverProps = {
19
19
  onEscapeAction: (evt: Event) => void
20
20
  trackScroll?: boolean
21
21
  role?: 'tooltip' | 'dialog'
22
- trapFocus?: boolean
23
22
  }
24
23
 
25
24
  export class StatelessPopover extends React.Component<StatelessPopoverProps> {
@@ -44,7 +43,6 @@ export class StatelessPopover extends React.Component<StatelessPopoverProps> {
44
43
  zIndex={props.zIndex}
45
44
  trackScroll={props.trackScroll}
46
45
  role={this.props.role}
47
- trapFocus={this.props.trapFocus}
48
46
  onEscapeAction={this.props.onEscapeAction}
49
47
  >
50
48
  {props.body}
@@ -5,16 +5,6 @@ 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
-
18
8
  describe('Popover', () => {
19
9
  beforeEach(() => {
20
10
  cleanDocumentBody()
package/dist/Popover.d.ts CHANGED
@@ -80,7 +80,6 @@ export declare type PopoverProps = {
80
80
  className?: string;
81
81
  trackScroll?: boolean;
82
82
  role?: 'tooltip' | 'dialog';
83
- trapFocus?: boolean;
84
83
  };
85
84
  export declare type PopoverState = {
86
85
  isOpen: boolean;
@@ -114,14 +113,11 @@ export declare class Popover extends React.Component<PopoverProps, PopoverState>
114
113
  trackScroll: PropTypes.Requireable<boolean>;
115
114
  children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
116
115
  role: PropTypes.Requireable<string>;
117
- trapFocus: PropTypes.Requireable<boolean>;
118
116
  };
119
117
  static defaultProps: {
120
118
  zIndex: number;
121
119
  outerActionEvents: string[];
122
120
  getPopoverPosition: string;
123
- role: string;
124
- trapFocus: string;
125
121
  };
126
122
  state: {
127
123
  isOpen: boolean;
@@ -12,7 +12,6 @@ declare type PopoverContainerProps = {
12
12
  showTip?: boolean;
13
13
  zIndex: number;
14
14
  role?: 'tooltip' | 'dialog';
15
- trapFocus?: boolean;
16
15
  onEscapeAction: (event: Event) => void;
17
16
  };
18
17
  declare type PopoverContainerState = {
@@ -30,7 +29,6 @@ export declare class PopoverContainer extends React.Component<PopoverContainerPr
30
29
  className: PropTypes.Requireable<string>;
31
30
  trackScroll: PropTypes.Requireable<boolean>;
32
31
  role: PropTypes.Requireable<string>;
33
- trapFocus: PropTypes.Requireable<boolean>;
34
32
  onEscapeAction: PropTypes.Requireable<(...args: any[]) => any>;
35
33
  };
36
34
  static defaultProps: {
@@ -39,7 +37,6 @@ export declare class PopoverContainer extends React.Component<PopoverContainerPr
39
37
  mounted: boolean;
40
38
  popoverContentRef: React.RefObject<HTMLDivElement>;
41
39
  state: PopoverContainerState;
42
- popoverContainerId: string;
43
40
  adjustPosition(): void;
44
41
  onResize: () => void;
45
42
  onScroll: (...args: any[]) => void;
@@ -14,7 +14,6 @@ export declare type StatelessPopoverProps = {
14
14
  onEscapeAction: (evt: Event) => void;
15
15
  trackScroll?: boolean;
16
16
  role?: 'tooltip' | 'dialog';
17
- trapFocus?: boolean;
18
17
  };
19
18
  export declare class StatelessPopover extends React.Component<StatelessPopoverProps> {
20
19
  renderPortalContent({ props, container, positioningTarget }: {
@@ -2,7 +2,6 @@ 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';
6
5
 
7
6
  function _classCallCheck(instance, Constructor) {
8
7
  if (!(instance instanceof Constructor)) {
@@ -206,8 +205,8 @@ function styleInject(css, ref) {
206
205
  }
207
206
  }
208
207
 
209
- var css = ".popover-body-container__popover__12-19-5-alpha-8 {\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-8 {\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-8 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-5-alpha-8 {\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-8: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-8,\r\n .popover-tip--top__popover__12-19-5-alpha-8 {\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-8,\r\n .popover-tip--right__popover__12-19-5-alpha-8 {\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-8: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-8: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-8: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-8: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-8","popover-body":"popover-body__popover__12-19-5-alpha-8","popover-body--no-padding":"popover-body--no-padding__popover__12-19-5-alpha-8","popover-tip":"popover-tip__popover__12-19-5-alpha-8","popover-tip--bottom":"popover-tip--bottom__popover__12-19-5-alpha-8","popover-tip--top":"popover-tip--top__popover__12-19-5-alpha-8","popover-tip--left":"popover-tip--left__popover__12-19-5-alpha-8","popover-tip--right":"popover-tip--right__popover__12-19-5-alpha-8"};
208
+ var css = ".popover-body-container__popover__12-19-7-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-7-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-7-alpha-3 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-7-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-7-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-7-alpha-3,\r\n .popover-tip--top__popover__12-19-7-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-7-alpha-3,\r\n .popover-tip--right__popover__12-19-7-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-7-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-7-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-7-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-7-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";
209
+ var styles = {"popover-body-container":"popover-body-container__popover__12-19-7-alpha-3","popover-body":"popover-body__popover__12-19-7-alpha-3","popover-body--no-padding":"popover-body--no-padding__popover__12-19-7-alpha-3","popover-tip":"popover-tip__popover__12-19-7-alpha-3","popover-tip--bottom":"popover-tip--bottom__popover__12-19-7-alpha-3","popover-tip--top":"popover-tip--top__popover__12-19-7-alpha-3","popover-tip--left":"popover-tip--left__popover__12-19-7-alpha-3","popover-tip--right":"popover-tip--right__popover__12-19-7-alpha-3"};
211
210
  styleInject(css);
212
211
 
213
212
  var PopoverBody = function PopoverBody(_ref) {
@@ -244,9 +243,6 @@ var throttle = function throttle(func, limit) {
244
243
  };
245
244
  };
246
245
 
247
- var generateId = function generateId(prefix) {
248
- return "".concat(prefix).concat(Math.random().toString(36).substring(7));
249
- };
250
246
  var isFocusable = function isFocusable(element) {
251
247
  if (element.tabIndex < 0) {
252
248
  return false;
@@ -254,9 +250,6 @@ var isFocusable = function isFocusable(element) {
254
250
  if ('disabled' in element && element.disabled) {
255
251
  return false;
256
252
  }
257
- if (element.tabIndex === 0) {
258
- return true;
259
- }
260
253
  switch (element.nodeName) {
261
254
  case 'A':
262
255
  return element.href;
@@ -288,7 +281,6 @@ var focusFirstDescendant = function focusFirstDescendant(element) {
288
281
  return false;
289
282
  };
290
283
 
291
- var popoverContainerPrefix = 'popover-container-';
292
284
  var isScrollParent = function isScrollParent(element) {
293
285
  // Firefox wants us to check `-x` and `-y` variations as well
294
286
  var _getComputedStyle = getComputedStyle(element),
@@ -348,7 +340,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
348
340
  positionX: 0,
349
341
  positionY: 0
350
342
  };
351
- _this.popoverContainerId = generateId(popoverContainerPrefix);
352
343
  _this.onResize = function () {
353
344
  return _this.adjustPosition();
354
345
  };
@@ -372,7 +363,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
372
363
  };
373
364
  _this.handleKeyDown = function (event) {
374
365
  if (event.key === 'Escape') {
375
- event.stopPropagation();
376
366
  _this.props.onEscapeAction(event);
377
367
  }
378
368
  };
@@ -418,6 +408,12 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
418
408
  value: function componentDidMount() {
419
409
  this.mounted = true;
420
410
  this.adjustPosition();
411
+ if (this.popoverContentRef.current) {
412
+ if (!focusFirstDescendant(this.popoverContentRef.current)) {
413
+ this.popoverContentRef.current.tabIndex = 0;
414
+ this.popoverContentRef.current.focus();
415
+ }
416
+ }
421
417
  if (this.props.trackScroll) {
422
418
  document.addEventListener('scroll', this.onScroll);
423
419
  window.addEventListener('resize', this.onResize);
@@ -425,12 +421,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
425
421
  this.props.containerElement.addEventListener('scroll', this.onScroll);
426
422
  }
427
423
  }
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
- }
434
424
  }
435
425
  }, {
436
426
  key: "componentDidUpdate",
@@ -482,34 +472,15 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
482
472
  left: tipPosition === 'right' && position.left - 8,
483
473
  right: tipPosition === 'left' && position.right - 8
484
474
  }
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,
492
- ref: this.popoverContentRef,
493
- style: _extends({
494
- position: 'absolute',
495
- pointerEvents: 'all'
496
- }, position),
497
- tabIndex: -1,
498
- className: this.props.className,
499
- role: this.props.role,
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,
475
+ }), React.createElement("div", {
504
476
  ref: this.popoverContentRef,
477
+ "aria-modal": "true",
505
478
  style: _extends({
506
479
  position: 'absolute',
507
480
  pointerEvents: 'all'
508
481
  }, position),
509
- tabIndex: -1,
510
482
  className: this.props.className,
511
483
  role: this.props.role,
512
- "aria-modal": this.props.trapFocus ? 'true' : 'false',
513
484
  onKeyDown: this.handleKeyDown
514
485
  }, this.props.children));
515
486
  }
@@ -646,7 +617,6 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
646
617
  zIndex: props.zIndex,
647
618
  trackScroll: props.trackScroll,
648
619
  role: this.props.role,
649
- trapFocus: this.props.trapFocus,
650
620
  onEscapeAction: this.props.onEscapeAction
651
621
  }, props.body);
652
622
  if (!props.inline) {
@@ -741,8 +711,7 @@ var Popover = /*#__PURE__*/function (_React$Component) {
741
711
  onOuterAction: this.onOuterAction,
742
712
  onEscapeAction: this.onEscapeAction,
743
713
  isOpen: isOpen,
744
- role: this.props.role,
745
- trapFocus: this.props.trapFocus
714
+ role: this.props.role
746
715
  }), childrenWithRef);
747
716
  }
748
717
  }]);
@@ -753,9 +722,7 @@ Popover.Position = PopoverPosition;
753
722
  Popover.defaultProps = {
754
723
  zIndex: 19999,
755
724
  outerActionEvents: ['mousedown', 'touchstart'],
756
- getPopoverPosition: 'bottomLeft',
757
- role: 'dialog',
758
- trapFocus: 'true'
725
+ getPopoverPosition: 'bottomLeft'
759
726
  };
760
727
 
761
728
  export default Popover;
package/dist/popover.js CHANGED
@@ -9,7 +9,6 @@ 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'));
13
12
 
14
13
  function _classCallCheck(instance, Constructor) {
15
14
  if (!(instance instanceof Constructor)) {
@@ -213,8 +212,8 @@ function styleInject(css, ref) {
213
212
  }
214
213
  }
215
214
 
216
- var css = ".popover-body-container__popover__12-19-5-alpha-8 {\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-8 {\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-8 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-5-alpha-8 {\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-8: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-8,\r\n .popover-tip--top__popover__12-19-5-alpha-8 {\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-8,\r\n .popover-tip--right__popover__12-19-5-alpha-8 {\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-8: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-8: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-8: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-8: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-8","popover-body":"popover-body__popover__12-19-5-alpha-8","popover-body--no-padding":"popover-body--no-padding__popover__12-19-5-alpha-8","popover-tip":"popover-tip__popover__12-19-5-alpha-8","popover-tip--bottom":"popover-tip--bottom__popover__12-19-5-alpha-8","popover-tip--top":"popover-tip--top__popover__12-19-5-alpha-8","popover-tip--left":"popover-tip--left__popover__12-19-5-alpha-8","popover-tip--right":"popover-tip--right__popover__12-19-5-alpha-8"};
215
+ var css = ".popover-body-container__popover__12-19-7-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-7-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-7-alpha-3 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-7-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-7-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-7-alpha-3,\r\n .popover-tip--top__popover__12-19-7-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-7-alpha-3,\r\n .popover-tip--right__popover__12-19-7-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-7-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-7-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-7-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-7-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";
216
+ var styles = {"popover-body-container":"popover-body-container__popover__12-19-7-alpha-3","popover-body":"popover-body__popover__12-19-7-alpha-3","popover-body--no-padding":"popover-body--no-padding__popover__12-19-7-alpha-3","popover-tip":"popover-tip__popover__12-19-7-alpha-3","popover-tip--bottom":"popover-tip--bottom__popover__12-19-7-alpha-3","popover-tip--top":"popover-tip--top__popover__12-19-7-alpha-3","popover-tip--left":"popover-tip--left__popover__12-19-7-alpha-3","popover-tip--right":"popover-tip--right__popover__12-19-7-alpha-3"};
218
217
  styleInject(css);
219
218
 
220
219
  var PopoverBody = function PopoverBody(_ref) {
@@ -251,9 +250,6 @@ var throttle = function throttle(func, limit) {
251
250
  };
252
251
  };
253
252
 
254
- var generateId = function generateId(prefix) {
255
- return "".concat(prefix).concat(Math.random().toString(36).substring(7));
256
- };
257
253
  var isFocusable = function isFocusable(element) {
258
254
  if (element.tabIndex < 0) {
259
255
  return false;
@@ -261,9 +257,6 @@ var isFocusable = function isFocusable(element) {
261
257
  if ('disabled' in element && element.disabled) {
262
258
  return false;
263
259
  }
264
- if (element.tabIndex === 0) {
265
- return true;
266
- }
267
260
  switch (element.nodeName) {
268
261
  case 'A':
269
262
  return element.href;
@@ -295,7 +288,6 @@ var focusFirstDescendant = function focusFirstDescendant(element) {
295
288
  return false;
296
289
  };
297
290
 
298
- var popoverContainerPrefix = 'popover-container-';
299
291
  var isScrollParent = function isScrollParent(element) {
300
292
  // Firefox wants us to check `-x` and `-y` variations as well
301
293
  var _getComputedStyle = getComputedStyle(element),
@@ -355,7 +347,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
355
347
  positionX: 0,
356
348
  positionY: 0
357
349
  };
358
- _this.popoverContainerId = generateId(popoverContainerPrefix);
359
350
  _this.onResize = function () {
360
351
  return _this.adjustPosition();
361
352
  };
@@ -379,7 +370,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
379
370
  };
380
371
  _this.handleKeyDown = function (event) {
381
372
  if (event.key === 'Escape') {
382
- event.stopPropagation();
383
373
  _this.props.onEscapeAction(event);
384
374
  }
385
375
  };
@@ -425,6 +415,12 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
425
415
  value: function componentDidMount() {
426
416
  this.mounted = true;
427
417
  this.adjustPosition();
418
+ if (this.popoverContentRef.current) {
419
+ if (!focusFirstDescendant(this.popoverContentRef.current)) {
420
+ this.popoverContentRef.current.tabIndex = 0;
421
+ this.popoverContentRef.current.focus();
422
+ }
423
+ }
428
424
  if (this.props.trackScroll) {
429
425
  document.addEventListener('scroll', this.onScroll);
430
426
  window.addEventListener('resize', this.onResize);
@@ -432,12 +428,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
432
428
  this.props.containerElement.addEventListener('scroll', this.onScroll);
433
429
  }
434
430
  }
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
- }
441
431
  }
442
432
  }, {
443
433
  key: "componentDidUpdate",
@@ -489,34 +479,15 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
489
479
  left: tipPosition === 'right' && position.left - 8,
490
480
  right: tipPosition === 'left' && position.right - 8
491
481
  }
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,
499
- ref: this.popoverContentRef,
500
- style: _extends({
501
- position: 'absolute',
502
- pointerEvents: 'all'
503
- }, position),
504
- tabIndex: -1,
505
- className: this.props.className,
506
- role: this.props.role,
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,
482
+ }), React__default.createElement("div", {
511
483
  ref: this.popoverContentRef,
484
+ "aria-modal": "true",
512
485
  style: _extends({
513
486
  position: 'absolute',
514
487
  pointerEvents: 'all'
515
488
  }, position),
516
- tabIndex: -1,
517
489
  className: this.props.className,
518
490
  role: this.props.role,
519
- "aria-modal": this.props.trapFocus ? 'true' : 'false',
520
491
  onKeyDown: this.handleKeyDown
521
492
  }, this.props.children));
522
493
  }
@@ -653,7 +624,6 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
653
624
  zIndex: props.zIndex,
654
625
  trackScroll: props.trackScroll,
655
626
  role: this.props.role,
656
- trapFocus: this.props.trapFocus,
657
627
  onEscapeAction: this.props.onEscapeAction
658
628
  }, props.body);
659
629
  if (!props.inline) {
@@ -748,8 +718,7 @@ var Popover = /*#__PURE__*/function (_React$Component) {
748
718
  onOuterAction: this.onOuterAction,
749
719
  onEscapeAction: this.onEscapeAction,
750
720
  isOpen: isOpen,
751
- role: this.props.role,
752
- trapFocus: this.props.trapFocus
721
+ role: this.props.role
753
722
  }), childrenWithRef);
754
723
  }
755
724
  }]);
@@ -760,9 +729,7 @@ Popover.Position = PopoverPosition;
760
729
  Popover.defaultProps = {
761
730
  zIndex: 19999,
762
731
  outerActionEvents: ['mousedown', 'touchstart'],
763
- getPopoverPosition: 'bottomLeft',
764
- role: 'dialog',
765
- trapFocus: 'true'
732
+ getPopoverPosition: 'bottomLeft'
766
733
  };
767
734
 
768
735
  exports.Popover = Popover;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@targetprocess/popover",
3
- "version": "12.19.5-alpha.8",
3
+ "version": "12.19.7-alpha.3",
4
4
  "description": "",
5
5
  "main": "dist/popover.js",
6
6
  "module": "dist/popover.es.js",
@@ -12,9 +12,8 @@
12
12
  "prepack": "node -r ../../.ts-node.js ../../config/rollup.config.js ."
13
13
  },
14
14
  "dependencies": {
15
- "@targetprocess/global-constants": "^12.7.3",
15
+ "@targetprocess/global-constants": "^12.19.7-alpha.3",
16
16
  "classnames": "^2.2.5",
17
- "focus-trap-react": "^7.0.0",
18
17
  "prop-types": "^15.6.0",
19
18
  "react": "^16.7.0",
20
19
  "react-dom": "^16.7.0"
@@ -22,5 +21,5 @@
22
21
  "publishConfig": {
23
22
  "access": "public"
24
23
  },
25
- "gitHead": "9331d29ceac1b6ba7c3182d43f76bd91ca0754f0"
24
+ "gitHead": "a695fbda2e93ae0bf506d0460be9caa26e944602"
26
25
  }