@targetprocess/popover 12.19.4-alpha.2 → 12.19.5-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 +2 -1
- package/PopoverContainer.tsx +9 -3
- package/dist/Popover.d.ts +1 -0
- package/dist/popover.es.js +103 -32
- package/dist/popover.js +103 -32
- package/package.json +2 -2
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 = {
|
package/PopoverContainer.tsx
CHANGED
|
@@ -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) {
|
|
@@ -209,6 +214,7 @@ export class PopoverContainer extends React.Component<
|
|
|
209
214
|
|
|
210
215
|
handleKeyDown = event => {
|
|
211
216
|
if (event.key === 'Escape') {
|
|
217
|
+
event.stopPropagation()
|
|
212
218
|
this.props.onEscapeAction(event)
|
|
213
219
|
}
|
|
214
220
|
}
|
|
@@ -266,7 +272,6 @@ export class PopoverContainer extends React.Component<
|
|
|
266
272
|
)}
|
|
267
273
|
<div
|
|
268
274
|
ref={this.popoverContentRef}
|
|
269
|
-
aria-modal="true"
|
|
270
275
|
style={{
|
|
271
276
|
position: 'absolute',
|
|
272
277
|
pointerEvents: 'all',
|
|
@@ -274,6 +279,7 @@ export class PopoverContainer extends React.Component<
|
|
|
274
279
|
}}
|
|
275
280
|
className={this.props.className}
|
|
276
281
|
role={this.props.role}
|
|
282
|
+
aria-modal={this.props.role === 'dialog' ? 'true' : 'false'}
|
|
277
283
|
onKeyDown={this.handleKeyDown}
|
|
278
284
|
>
|
|
279
285
|
{this.props.children}
|
package/dist/Popover.d.ts
CHANGED
package/dist/popover.es.js
CHANGED
|
@@ -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-
|
|
209
|
-
var styles = {"popover-body-container":"popover-body-container__popover__12-19-
|
|
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"};
|
|
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
|
|
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
|
-
|
|
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
|
|
277
|
-
var
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
|
@@ -382,6 +446,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
382
446
|
};
|
|
383
447
|
_this.handleKeyDown = function (event) {
|
|
384
448
|
if (event.key === 'Escape') {
|
|
449
|
+
event.stopPropagation();
|
|
385
450
|
_this.props.onEscapeAction(event);
|
|
386
451
|
}
|
|
387
452
|
};
|
|
@@ -427,11 +492,16 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
427
492
|
value: function componentDidMount() {
|
|
428
493
|
this.mounted = true;
|
|
429
494
|
this.adjustPosition();
|
|
430
|
-
if (this.popoverContentRef.current) {
|
|
495
|
+
if (this.popoverContentRef.current && this.props.role === 'dialog') {
|
|
431
496
|
if (!focusFirstDescendant(this.popoverContentRef.current)) {
|
|
432
497
|
this.popoverContentRef.current.tabIndex = 0;
|
|
433
498
|
this.popoverContentRef.current.focus();
|
|
434
499
|
}
|
|
500
|
+
trapFocus(this.popoverContentRef.current);
|
|
501
|
+
}
|
|
502
|
+
if (this.props.role === 'tooltip') {
|
|
503
|
+
this.popoverContentRef.current.tabIndex = 0;
|
|
504
|
+
this.popoverContentRef.current.focus();
|
|
435
505
|
}
|
|
436
506
|
if (this.props.trackScroll) {
|
|
437
507
|
document.addEventListener('scroll', this.onScroll);
|
|
@@ -493,13 +563,13 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
493
563
|
}
|
|
494
564
|
}), React.createElement("div", {
|
|
495
565
|
ref: this.popoverContentRef,
|
|
496
|
-
"aria-modal": "true",
|
|
497
566
|
style: _extends({
|
|
498
567
|
position: 'absolute',
|
|
499
568
|
pointerEvents: 'all'
|
|
500
569
|
}, position),
|
|
501
570
|
className: this.props.className,
|
|
502
571
|
role: this.props.role,
|
|
572
|
+
"aria-modal": this.props.role === 'dialog' ? 'true' : 'false',
|
|
503
573
|
onKeyDown: this.handleKeyDown
|
|
504
574
|
}, this.props.children));
|
|
505
575
|
}
|
|
@@ -741,7 +811,8 @@ Popover.Position = PopoverPosition;
|
|
|
741
811
|
Popover.defaultProps = {
|
|
742
812
|
zIndex: 19999,
|
|
743
813
|
outerActionEvents: ['mousedown', 'touchstart'],
|
|
744
|
-
getPopoverPosition: 'bottomLeft'
|
|
814
|
+
getPopoverPosition: 'bottomLeft',
|
|
815
|
+
role: 'dialog'
|
|
745
816
|
};
|
|
746
817
|
|
|
747
818
|
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-
|
|
216
|
-
var styles = {"popover-body-container":"popover-body-container__popover__12-19-
|
|
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"};
|
|
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
|
|
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
|
-
|
|
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
|
|
284
|
-
var
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
|
@@ -389,6 +453,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
389
453
|
};
|
|
390
454
|
_this.handleKeyDown = function (event) {
|
|
391
455
|
if (event.key === 'Escape') {
|
|
456
|
+
event.stopPropagation();
|
|
392
457
|
_this.props.onEscapeAction(event);
|
|
393
458
|
}
|
|
394
459
|
};
|
|
@@ -434,11 +499,16 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
434
499
|
value: function componentDidMount() {
|
|
435
500
|
this.mounted = true;
|
|
436
501
|
this.adjustPosition();
|
|
437
|
-
if (this.popoverContentRef.current) {
|
|
502
|
+
if (this.popoverContentRef.current && this.props.role === 'dialog') {
|
|
438
503
|
if (!focusFirstDescendant(this.popoverContentRef.current)) {
|
|
439
504
|
this.popoverContentRef.current.tabIndex = 0;
|
|
440
505
|
this.popoverContentRef.current.focus();
|
|
441
506
|
}
|
|
507
|
+
trapFocus(this.popoverContentRef.current);
|
|
508
|
+
}
|
|
509
|
+
if (this.props.role === 'tooltip') {
|
|
510
|
+
this.popoverContentRef.current.tabIndex = 0;
|
|
511
|
+
this.popoverContentRef.current.focus();
|
|
442
512
|
}
|
|
443
513
|
if (this.props.trackScroll) {
|
|
444
514
|
document.addEventListener('scroll', this.onScroll);
|
|
@@ -500,13 +570,13 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
500
570
|
}
|
|
501
571
|
}), React__default.createElement("div", {
|
|
502
572
|
ref: this.popoverContentRef,
|
|
503
|
-
"aria-modal": "true",
|
|
504
573
|
style: _extends({
|
|
505
574
|
position: 'absolute',
|
|
506
575
|
pointerEvents: 'all'
|
|
507
576
|
}, position),
|
|
508
577
|
className: this.props.className,
|
|
509
578
|
role: this.props.role,
|
|
579
|
+
"aria-modal": this.props.role === 'dialog' ? 'true' : 'false',
|
|
510
580
|
onKeyDown: this.handleKeyDown
|
|
511
581
|
}, this.props.children));
|
|
512
582
|
}
|
|
@@ -748,7 +818,8 @@ Popover.Position = PopoverPosition;
|
|
|
748
818
|
Popover.defaultProps = {
|
|
749
819
|
zIndex: 19999,
|
|
750
820
|
outerActionEvents: ['mousedown', 'touchstart'],
|
|
751
|
-
getPopoverPosition: 'bottomLeft'
|
|
821
|
+
getPopoverPosition: 'bottomLeft',
|
|
822
|
+
role: 'dialog'
|
|
752
823
|
};
|
|
753
824
|
|
|
754
825
|
exports.Popover = Popover;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@targetprocess/popover",
|
|
3
|
-
"version": "12.19.
|
|
3
|
+
"version": "12.19.5-alpha.3",
|
|
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": "
|
|
24
|
+
"gitHead": "6acc350de401d2739358a5a64f0a5e923e9a7c08"
|
|
25
25
|
}
|