@targetprocess/popover 12.19.4-alpha.2 → 12.19.5-alpha.1

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
@@ -128,7 +128,8 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
128
128
  static defaultProps = {
129
129
  zIndex: 19999,
130
130
  outerActionEvents: ['mousedown', 'touchstart'],
131
- getPopoverPosition: 'bottomLeft'
131
+ getPopoverPosition: 'bottomLeft',
132
+ role: 'dialog'
132
133
  }
133
134
 
134
135
  state = {
@@ -7,7 +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 {focusFirstDescendant} from '../../base/utils/ariaUtils'
10
+ import {focusFirstDescendant, trapFocus} from '../../base/utils/ariaUtils'
11
11
 
12
12
  type PopoverContainerProps = {
13
13
  containerElement?: HTMLElement
@@ -154,11 +154,16 @@ export class PopoverContainer extends React.Component<
154
154
  this.mounted = true
155
155
  this.adjustPosition()
156
156
 
157
- if (this.popoverContentRef.current) {
157
+ if (this.popoverContentRef.current && this.props.role === 'dialog') {
158
158
  if (!focusFirstDescendant(this.popoverContentRef.current)) {
159
159
  this.popoverContentRef.current.tabIndex = 0
160
160
  this.popoverContentRef.current.focus()
161
161
  }
162
+ trapFocus(this.popoverContentRef.current)
163
+ }
164
+ if (this.props.role === 'tooltip') {
165
+ this.popoverContentRef.current.tabIndex = 0
166
+ this.popoverContentRef.current.focus()
162
167
  }
163
168
 
164
169
  if (this.props.trackScroll) {
@@ -266,7 +271,6 @@ export class PopoverContainer extends React.Component<
266
271
  )}
267
272
  <div
268
273
  ref={this.popoverContentRef}
269
- aria-modal="true"
270
274
  style={{
271
275
  position: 'absolute',
272
276
  pointerEvents: 'all',
@@ -274,6 +278,7 @@ export class PopoverContainer extends React.Component<
274
278
  }}
275
279
  className={this.props.className}
276
280
  role={this.props.role}
281
+ aria-modal={this.props.role === 'dialog' ? 'true' : 'false'}
277
282
  onKeyDown={this.handleKeyDown}
278
283
  >
279
284
  {this.props.children}
package/dist/Popover.d.ts CHANGED
@@ -118,6 +118,7 @@ export declare class Popover extends React.Component<PopoverProps, PopoverState>
118
118
  zIndex: number;
119
119
  outerActionEvents: string[];
120
120
  getPopoverPosition: string;
121
+ role: string;
121
122
  };
122
123
  state: {
123
124
  isOpen: boolean;
@@ -3,6 +3,33 @@ import { SpaceXS } from '@targetprocess/global-constants';
3
3
  import classNames from 'classnames';
4
4
  import ReactDOM from 'react-dom';
5
5
 
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
+ }
6
33
  function _classCallCheck(instance, Constructor) {
7
34
  if (!(instance instanceof Constructor)) {
8
35
  throw new TypeError("Cannot call a class as a function");
@@ -82,6 +109,28 @@ function _possibleConstructorReturn(self, call) {
82
109
  }
83
110
  return _assertThisInitialized(self);
84
111
  }
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
+ }
85
134
  function _toPrimitive(input, hint) {
86
135
  if (typeof input !== "object" || input === null) return input;
87
136
  var prim = input[Symbol.toPrimitive];
@@ -205,8 +254,8 @@ function styleInject(css, ref) {
205
254
  }
206
255
  }
207
256
 
208
- var css = ".popover-body-container__popover__12-19-4-alpha-2 {\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-4-alpha-2 {\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-4-alpha-2 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-4-alpha-2 {\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-4-alpha-2: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-4-alpha-2,\r\n .popover-tip--top__popover__12-19-4-alpha-2 {\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-4-alpha-2,\r\n .popover-tip--right__popover__12-19-4-alpha-2 {\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-4-alpha-2: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-4-alpha-2: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-4-alpha-2: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-4-alpha-2: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-4-alpha-2","popover-body":"popover-body__popover__12-19-4-alpha-2","popover-body--no-padding":"popover-body--no-padding__popover__12-19-4-alpha-2","popover-tip":"popover-tip__popover__12-19-4-alpha-2","popover-tip--bottom":"popover-tip--bottom__popover__12-19-4-alpha-2","popover-tip--top":"popover-tip--top__popover__12-19-4-alpha-2","popover-tip--left":"popover-tip--left__popover__12-19-4-alpha-2","popover-tip--right":"popover-tip--right__popover__12-19-4-alpha-2"};
257
+ var css = ".popover-body-container__popover__12-19-5-alpha-1 {\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-1 {\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-1 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-5-alpha-1 {\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-1: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-1,\r\n .popover-tip--top__popover__12-19-5-alpha-1 {\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-1,\r\n .popover-tip--right__popover__12-19-5-alpha-1 {\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-1: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-1: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-1: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-1: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-1","popover-body":"popover-body__popover__12-19-5-alpha-1","popover-body--no-padding":"popover-body--no-padding__popover__12-19-5-alpha-1","popover-tip":"popover-tip__popover__12-19-5-alpha-1","popover-tip--bottom":"popover-tip--bottom__popover__12-19-5-alpha-1","popover-tip--top":"popover-tip--top__popover__12-19-5-alpha-1","popover-tip--left":"popover-tip--left__popover__12-19-5-alpha-1","popover-tip--right":"popover-tip--right__popover__12-19-5-alpha-1"};
210
259
  styleInject(css);
211
260
 
212
261
  var PopoverBody = function PopoverBody(_ref) {
@@ -247,12 +296,12 @@ var isFocusable = function isFocusable(element) {
247
296
  if (element.tabIndex < 0) {
248
297
  return false;
249
298
  }
250
- if (element.disabled) {
299
+ if ('disabled' in element && element.disabled) {
251
300
  return false;
252
301
  }
253
302
  switch (element.nodeName) {
254
303
  case 'A':
255
- return !!element.href && element.rel !== 'ignore';
304
+ return element.href;
256
305
  case 'INPUT':
257
306
  return element.type !== 'hidden';
258
307
  case 'BUTTON':
@@ -267,38 +316,53 @@ var attemptFocus = function attemptFocus(element) {
267
316
  if (!isFocusable(element)) {
268
317
  return false;
269
318
  }
270
- try {
271
- element.focus();
272
- } catch (err) {}
319
+ element.focus();
273
320
  return document.activeElement === element;
274
321
  };
275
322
  var focusFirstDescendant = function focusFirstDescendant(element) {
276
- var _iteratorNormalCompletion = true;
277
- var _didIteratorError = false;
278
- var _iteratorError = undefined;
279
- try {
280
- for (var _iterator = element.childNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
281
- var child = _step.value;
282
- if (attemptFocus(child) || focusFirstDescendant(child)) {
283
- return true;
284
- }
285
- }
286
- } catch (err) {
287
- _didIteratorError = true;
288
- _iteratorError = err;
289
- } finally {
290
- try {
291
- if (!_iteratorNormalCompletion && _iterator["return"] != null) {
292
- _iterator["return"]();
293
- }
294
- } finally {
295
- if (_didIteratorError) {
296
- throw _iteratorError;
297
- }
323
+ var _arr = Array.from(element.childNodes);
324
+ for (var _i = 0; _i < _arr.length; _i++) {
325
+ var child = _arr[_i];
326
+ if (attemptFocus(child) || focusFirstDescendant(child)) {
327
+ return true;
298
328
  }
299
329
  }
300
330
  return false;
301
331
  };
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
+ };
302
366
 
303
367
  var isScrollParent = function isScrollParent(element) {
304
368
  // Firefox wants us to check `-x` and `-y` variations as well
@@ -427,11 +491,16 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
427
491
  value: function componentDidMount() {
428
492
  this.mounted = true;
429
493
  this.adjustPosition();
430
- if (this.popoverContentRef.current) {
494
+ if (this.popoverContentRef.current && this.props.role === 'dialog') {
431
495
  if (!focusFirstDescendant(this.popoverContentRef.current)) {
432
496
  this.popoverContentRef.current.tabIndex = 0;
433
497
  this.popoverContentRef.current.focus();
434
498
  }
499
+ trapFocus(this.popoverContentRef.current);
500
+ }
501
+ if (this.props.role === 'tooltip') {
502
+ this.popoverContentRef.current.tabIndex = 0;
503
+ this.popoverContentRef.current.focus();
435
504
  }
436
505
  if (this.props.trackScroll) {
437
506
  document.addEventListener('scroll', this.onScroll);
@@ -493,13 +562,13 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
493
562
  }
494
563
  }), React.createElement("div", {
495
564
  ref: this.popoverContentRef,
496
- "aria-modal": "true",
497
565
  style: _extends({
498
566
  position: 'absolute',
499
567
  pointerEvents: 'all'
500
568
  }, position),
501
569
  className: this.props.className,
502
570
  role: this.props.role,
571
+ "aria-modal": this.props.role === 'dialog' ? 'true' : 'false',
503
572
  onKeyDown: this.handleKeyDown
504
573
  }, this.props.children));
505
574
  }
@@ -741,7 +810,8 @@ Popover.Position = PopoverPosition;
741
810
  Popover.defaultProps = {
742
811
  zIndex: 19999,
743
812
  outerActionEvents: ['mousedown', 'touchstart'],
744
- getPopoverPosition: 'bottomLeft'
813
+ getPopoverPosition: 'bottomLeft',
814
+ role: 'dialog'
745
815
  };
746
816
 
747
817
  export default Popover;
package/dist/popover.js CHANGED
@@ -10,6 +10,33 @@ var globalConstants = require('@targetprocess/global-constants');
10
10
  var classNames = _interopDefault(require('classnames'));
11
11
  var ReactDOM = _interopDefault(require('react-dom'));
12
12
 
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
+ }
13
40
  function _classCallCheck(instance, Constructor) {
14
41
  if (!(instance instanceof Constructor)) {
15
42
  throw new TypeError("Cannot call a class as a function");
@@ -89,6 +116,28 @@ function _possibleConstructorReturn(self, call) {
89
116
  }
90
117
  return _assertThisInitialized(self);
91
118
  }
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
+ }
92
141
  function _toPrimitive(input, hint) {
93
142
  if (typeof input !== "object" || input === null) return input;
94
143
  var prim = input[Symbol.toPrimitive];
@@ -212,8 +261,8 @@ function styleInject(css, ref) {
212
261
  }
213
262
  }
214
263
 
215
- var css = ".popover-body-container__popover__12-19-4-alpha-2 {\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-4-alpha-2 {\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-4-alpha-2 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-4-alpha-2 {\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-4-alpha-2: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-4-alpha-2,\r\n .popover-tip--top__popover__12-19-4-alpha-2 {\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-4-alpha-2,\r\n .popover-tip--right__popover__12-19-4-alpha-2 {\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-4-alpha-2: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-4-alpha-2: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-4-alpha-2: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-4-alpha-2: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-4-alpha-2","popover-body":"popover-body__popover__12-19-4-alpha-2","popover-body--no-padding":"popover-body--no-padding__popover__12-19-4-alpha-2","popover-tip":"popover-tip__popover__12-19-4-alpha-2","popover-tip--bottom":"popover-tip--bottom__popover__12-19-4-alpha-2","popover-tip--top":"popover-tip--top__popover__12-19-4-alpha-2","popover-tip--left":"popover-tip--left__popover__12-19-4-alpha-2","popover-tip--right":"popover-tip--right__popover__12-19-4-alpha-2"};
264
+ var css = ".popover-body-container__popover__12-19-5-alpha-1 {\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-1 {\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-1 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-5-alpha-1 {\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-1: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-1,\r\n .popover-tip--top__popover__12-19-5-alpha-1 {\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-1,\r\n .popover-tip--right__popover__12-19-5-alpha-1 {\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-1: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-1: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-1: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-1: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-1","popover-body":"popover-body__popover__12-19-5-alpha-1","popover-body--no-padding":"popover-body--no-padding__popover__12-19-5-alpha-1","popover-tip":"popover-tip__popover__12-19-5-alpha-1","popover-tip--bottom":"popover-tip--bottom__popover__12-19-5-alpha-1","popover-tip--top":"popover-tip--top__popover__12-19-5-alpha-1","popover-tip--left":"popover-tip--left__popover__12-19-5-alpha-1","popover-tip--right":"popover-tip--right__popover__12-19-5-alpha-1"};
217
266
  styleInject(css);
218
267
 
219
268
  var PopoverBody = function PopoverBody(_ref) {
@@ -254,12 +303,12 @@ var isFocusable = function isFocusable(element) {
254
303
  if (element.tabIndex < 0) {
255
304
  return false;
256
305
  }
257
- if (element.disabled) {
306
+ if ('disabled' in element && element.disabled) {
258
307
  return false;
259
308
  }
260
309
  switch (element.nodeName) {
261
310
  case 'A':
262
- return !!element.href && element.rel !== 'ignore';
311
+ return element.href;
263
312
  case 'INPUT':
264
313
  return element.type !== 'hidden';
265
314
  case 'BUTTON':
@@ -274,38 +323,53 @@ var attemptFocus = function attemptFocus(element) {
274
323
  if (!isFocusable(element)) {
275
324
  return false;
276
325
  }
277
- try {
278
- element.focus();
279
- } catch (err) {}
326
+ element.focus();
280
327
  return document.activeElement === element;
281
328
  };
282
329
  var focusFirstDescendant = function focusFirstDescendant(element) {
283
- var _iteratorNormalCompletion = true;
284
- var _didIteratorError = false;
285
- var _iteratorError = undefined;
286
- try {
287
- for (var _iterator = element.childNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
288
- var child = _step.value;
289
- if (attemptFocus(child) || focusFirstDescendant(child)) {
290
- return true;
291
- }
292
- }
293
- } catch (err) {
294
- _didIteratorError = true;
295
- _iteratorError = err;
296
- } finally {
297
- try {
298
- if (!_iteratorNormalCompletion && _iterator["return"] != null) {
299
- _iterator["return"]();
300
- }
301
- } finally {
302
- if (_didIteratorError) {
303
- throw _iteratorError;
304
- }
330
+ var _arr = Array.from(element.childNodes);
331
+ for (var _i = 0; _i < _arr.length; _i++) {
332
+ var child = _arr[_i];
333
+ if (attemptFocus(child) || focusFirstDescendant(child)) {
334
+ return true;
305
335
  }
306
336
  }
307
337
  return false;
308
338
  };
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
+ };
309
373
 
310
374
  var isScrollParent = function isScrollParent(element) {
311
375
  // Firefox wants us to check `-x` and `-y` variations as well
@@ -434,11 +498,16 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
434
498
  value: function componentDidMount() {
435
499
  this.mounted = true;
436
500
  this.adjustPosition();
437
- if (this.popoverContentRef.current) {
501
+ if (this.popoverContentRef.current && this.props.role === 'dialog') {
438
502
  if (!focusFirstDescendant(this.popoverContentRef.current)) {
439
503
  this.popoverContentRef.current.tabIndex = 0;
440
504
  this.popoverContentRef.current.focus();
441
505
  }
506
+ trapFocus(this.popoverContentRef.current);
507
+ }
508
+ if (this.props.role === 'tooltip') {
509
+ this.popoverContentRef.current.tabIndex = 0;
510
+ this.popoverContentRef.current.focus();
442
511
  }
443
512
  if (this.props.trackScroll) {
444
513
  document.addEventListener('scroll', this.onScroll);
@@ -500,13 +569,13 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
500
569
  }
501
570
  }), React__default.createElement("div", {
502
571
  ref: this.popoverContentRef,
503
- "aria-modal": "true",
504
572
  style: _extends({
505
573
  position: 'absolute',
506
574
  pointerEvents: 'all'
507
575
  }, position),
508
576
  className: this.props.className,
509
577
  role: this.props.role,
578
+ "aria-modal": this.props.role === 'dialog' ? 'true' : 'false',
510
579
  onKeyDown: this.handleKeyDown
511
580
  }, this.props.children));
512
581
  }
@@ -748,7 +817,8 @@ Popover.Position = PopoverPosition;
748
817
  Popover.defaultProps = {
749
818
  zIndex: 19999,
750
819
  outerActionEvents: ['mousedown', 'touchstart'],
751
- getPopoverPosition: 'bottomLeft'
820
+ getPopoverPosition: 'bottomLeft',
821
+ role: 'dialog'
752
822
  };
753
823
 
754
824
  exports.Popover = Popover;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@targetprocess/popover",
3
- "version": "12.19.4-alpha.2",
3
+ "version": "12.19.5-alpha.1",
4
4
  "description": "",
5
5
  "main": "dist/popover.js",
6
6
  "module": "dist/popover.es.js",
@@ -21,5 +21,5 @@
21
21
  "publishConfig": {
22
22
  "access": "public"
23
23
  },
24
- "gitHead": "562ec9194d9b52ce5d8cbc8bb4556ece4ae35503"
24
+ "gitHead": "f828bdeb752c7d340ce6175d3f4305d652d28836"
25
25
  }