@targetprocess/popover 12.19.2-alpha.5 → 12.19.2-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Popover.tsx +9 -4
- package/PopoverContainer.tsx +9 -5
- package/StatlessPopover.tsx +1 -1
- package/dist/Popover.d.ts +1 -0
- package/dist/PopoverContainer.d.ts +1 -1
- package/dist/StatlessPopover.d.ts +1 -1
- package/dist/popover.es.js +74 -11
- package/dist/popover.js +74 -11
- package/package.json +2 -2
package/Popover.tsx
CHANGED
|
@@ -148,6 +148,14 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
onEscapeAction = (event: Event) => {
|
|
152
|
+
this.setOpened(false)
|
|
153
|
+
if (this.props.onOuterAction) {
|
|
154
|
+
this.props.onOuterAction(event)
|
|
155
|
+
}
|
|
156
|
+
this.childrenRef.current?.focus()
|
|
157
|
+
}
|
|
158
|
+
|
|
151
159
|
childrenRef = createRef<HTMLElement>()
|
|
152
160
|
|
|
153
161
|
render() {
|
|
@@ -164,10 +172,7 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
|
|
|
164
172
|
<StatelessPopover
|
|
165
173
|
{...this.props}
|
|
166
174
|
onOuterAction={this.onOuterAction}
|
|
167
|
-
onEscapeAction={
|
|
168
|
-
this.setOpened(false)
|
|
169
|
-
this.childrenRef.current?.focus()
|
|
170
|
-
}}
|
|
175
|
+
onEscapeAction={this.onEscapeAction}
|
|
171
176
|
isOpen={isOpen}
|
|
172
177
|
role={this.props.role}
|
|
173
178
|
>
|
package/PopoverContainer.tsx
CHANGED
|
@@ -7,6 +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
11
|
|
|
11
12
|
type PopoverContainerProps = {
|
|
12
13
|
containerElement?: HTMLElement
|
|
@@ -19,7 +20,7 @@ type PopoverContainerProps = {
|
|
|
19
20
|
showTip?: boolean
|
|
20
21
|
zIndex: number
|
|
21
22
|
role?: 'tooltip' | 'dialog'
|
|
22
|
-
onEscapeAction: () => void
|
|
23
|
+
onEscapeAction: (event: Event) => void
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
type PopoverContainerState = {
|
|
@@ -153,8 +154,11 @@ export class PopoverContainer extends React.Component<
|
|
|
153
154
|
this.mounted = true
|
|
154
155
|
this.adjustPosition()
|
|
155
156
|
|
|
156
|
-
if (this.popoverContentRef) {
|
|
157
|
-
this.popoverContentRef.current
|
|
157
|
+
if (this.popoverContentRef.current) {
|
|
158
|
+
if (!focusFirstDescendant(this.popoverContentRef.current)) {
|
|
159
|
+
this.popoverContentRef.current.tabIndex = 0
|
|
160
|
+
this.popoverContentRef.current.focus()
|
|
161
|
+
}
|
|
158
162
|
}
|
|
159
163
|
|
|
160
164
|
if (this.props.trackScroll) {
|
|
@@ -202,9 +206,10 @@ export class PopoverContainer extends React.Component<
|
|
|
202
206
|
|
|
203
207
|
return null
|
|
204
208
|
}
|
|
209
|
+
|
|
205
210
|
handleKeyDown = event => {
|
|
206
211
|
if (event.key === 'Escape') {
|
|
207
|
-
this.props.onEscapeAction()
|
|
212
|
+
this.props.onEscapeAction(event)
|
|
208
213
|
}
|
|
209
214
|
}
|
|
210
215
|
|
|
@@ -269,7 +274,6 @@ export class PopoverContainer extends React.Component<
|
|
|
269
274
|
}}
|
|
270
275
|
className={this.props.className}
|
|
271
276
|
role={this.props.role}
|
|
272
|
-
tabIndex={0}
|
|
273
277
|
onKeyDown={this.handleKeyDown}
|
|
274
278
|
>
|
|
275
279
|
{this.props.children}
|
package/StatlessPopover.tsx
CHANGED
|
@@ -16,9 +16,9 @@ export type StatelessPopoverProps = {
|
|
|
16
16
|
className?: string
|
|
17
17
|
outerActionEvents?: string[]
|
|
18
18
|
onOuterAction?: (evt: Event) => void
|
|
19
|
+
onEscapeAction: (evt: Event) => void
|
|
19
20
|
trackScroll?: boolean
|
|
20
21
|
role?: 'tooltip' | 'dialog'
|
|
21
|
-
onEscapeAction: () => void
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export class StatelessPopover extends React.Component<StatelessPopoverProps> {
|
package/dist/Popover.d.ts
CHANGED
|
@@ -124,6 +124,7 @@ export declare class Popover extends React.Component<PopoverProps, PopoverState>
|
|
|
124
124
|
};
|
|
125
125
|
setOpened: (isOpen: boolean) => void;
|
|
126
126
|
onOuterAction: (event: Event) => void;
|
|
127
|
+
onEscapeAction: (event: Event) => void;
|
|
127
128
|
childrenRef: React.RefObject<HTMLElement>;
|
|
128
129
|
render(): JSX.Element;
|
|
129
130
|
}
|
|
@@ -11,9 +11,9 @@ export declare type StatelessPopoverProps = {
|
|
|
11
11
|
className?: string;
|
|
12
12
|
outerActionEvents?: string[];
|
|
13
13
|
onOuterAction?: (evt: Event) => void;
|
|
14
|
+
onEscapeAction: (evt: Event) => void;
|
|
14
15
|
trackScroll?: boolean;
|
|
15
16
|
role?: 'tooltip' | 'dialog';
|
|
16
|
-
onEscapeAction: () => void;
|
|
17
17
|
};
|
|
18
18
|
export declare class StatelessPopover extends React.Component<StatelessPopoverProps> {
|
|
19
19
|
renderPortalContent({ props, container, positioningTarget }: {
|
package/dist/popover.es.js
CHANGED
|
@@ -205,8 +205,8 @@ function styleInject(css, ref) {
|
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
var css = ".popover-body-container__popover__12-19-2-alpha-
|
|
209
|
-
var styles = {"popover-body-container":"popover-body-container__popover__12-19-2-alpha-
|
|
208
|
+
var css = ".popover-body-container__popover__12-19-2-alpha-6 {\r\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n border-radius: var(--BorderRadiusL, 4px);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n background: var(--BackgroundDefault, #FFFFFF);\r\n z-index: var(--ZIndexModal, 10001);\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n}\r\n\r\n.popover-body__popover__12-19-2-alpha-6 {\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n padding: var(--SpaceSM, 12px);\r\n font-size: var(--FontSizeDefault, 13px);\r\n color: var(--FontColorDefault, #000000);\r\n}\r\n\r\n.popover-body--no-padding__popover__12-19-2-alpha-6 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-2-alpha-6 {\r\n position: absolute;\r\n pointer-events: none;\r\n z-index: calc(var(--ZIndexModal, 10001) + 1);\r\n overflow: hidden;\r\n display: -webkit-box;\r\n display: -ms-flexbox;\r\n display: flex;\r\n -webkit-box-align: center;\r\n -ms-flex-align: center;\r\n align-items: center;\r\n -webkit-box-pack: center;\r\n -ms-flex-pack: center;\r\n justify-content: center;\r\n}\r\n\r\n.popover-tip__popover__12-19-2-alpha-6:before {\r\n content: '';\r\n position: absolute;\r\n display: block;\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n background-color: var(--BackgroundDefault, #FFFFFF);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n /*\r\n geometry FTW\r\n\r\n 2*$popoverTipSize\r\n _______ _______\r\n | /|\\ |\r\n | / | \\ | $popoverTipSize\r\n | / | \\ |\r\n |/______|______\\|\r\n since tip is rotated 45 degrees, its width and height is a\r\n diagonal of a square with side=$popoverTipSize, thus diagonal\r\n is sqrt(2) * $popoverTipSize.\r\n sqrt(2) ~= 1.414, 1.4 used here to prevent too much rounding\r\n */\r\n width: 11.2px;\r\n height: 11.2px;\r\n -webkit-transform: rotate(45deg);\r\n transform: rotate(45deg);\r\n }\r\n\r\n.popover-tip--bottom__popover__12-19-2-alpha-6,\r\n .popover-tip--top__popover__12-19-2-alpha-6 {\r\n width: 100%;\r\n border-top: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-bottom: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 9px;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-2-alpha-6,\r\n .popover-tip--right__popover__12-19-2-alpha-6 {\r\n border-left: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-right: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 100%;\r\n width: 9px;\r\n }\r\n\r\n/*\r\n To determine tip position, we need to rotate it\r\n along the \"tip\" point, after that, the \"tip\" point\r\n can be placed with exactly 50% offset from the origin\r\n so that it is centered.\r\n */\r\n\r\n.popover-tip--bottom__popover__12-19-2-alpha-6:before {\r\n -webkit-transform-origin: left top;\r\n transform-origin: left top;\r\n left: 50%;\r\n top: 0;\r\n }\r\n\r\n.popover-tip--top__popover__12-19-2-alpha-6:before {\r\n -webkit-transform-origin: right bottom;\r\n transform-origin: right bottom;\r\n right: 50%;\r\n bottom: 0;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-2-alpha-6:before {\r\n -webkit-transform-origin: right top;\r\n transform-origin: right top;\r\n right: 0;\r\n top: 50%;\r\n }\r\n\r\n.popover-tip--right__popover__12-19-2-alpha-6:before {\r\n -webkit-transform-origin: left bottom;\r\n transform-origin: left bottom;\r\n left: 0;\r\n bottom: 50%;\r\n }\r\n";
|
|
209
|
+
var styles = {"popover-body-container":"popover-body-container__popover__12-19-2-alpha-6","popover-body":"popover-body__popover__12-19-2-alpha-6","popover-body--no-padding":"popover-body--no-padding__popover__12-19-2-alpha-6","popover-tip":"popover-tip__popover__12-19-2-alpha-6","popover-tip--bottom":"popover-tip--bottom__popover__12-19-2-alpha-6","popover-tip--top":"popover-tip--top__popover__12-19-2-alpha-6","popover-tip--left":"popover-tip--left__popover__12-19-2-alpha-6","popover-tip--right":"popover-tip--right__popover__12-19-2-alpha-6"};
|
|
210
210
|
styleInject(css);
|
|
211
211
|
|
|
212
212
|
var PopoverBody = function PopoverBody(_ref) {
|
|
@@ -243,6 +243,63 @@ var throttle = function throttle(func, limit) {
|
|
|
243
243
|
};
|
|
244
244
|
};
|
|
245
245
|
|
|
246
|
+
var isFocusable = function isFocusable(element) {
|
|
247
|
+
if (element.tabIndex < 0) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
if (element.disabled) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
switch (element.nodeName) {
|
|
254
|
+
case 'A':
|
|
255
|
+
return !!element.href && element.rel !== 'ignore';
|
|
256
|
+
case 'INPUT':
|
|
257
|
+
return element.type !== 'hidden';
|
|
258
|
+
case 'BUTTON':
|
|
259
|
+
case 'SELECT':
|
|
260
|
+
case 'TEXTAREA':
|
|
261
|
+
return true;
|
|
262
|
+
default:
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
var attemptFocus = function attemptFocus(element) {
|
|
267
|
+
if (!isFocusable(element)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
element.focus();
|
|
272
|
+
} catch (err) {}
|
|
273
|
+
return document.activeElement === element;
|
|
274
|
+
};
|
|
275
|
+
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
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return false;
|
|
301
|
+
};
|
|
302
|
+
|
|
246
303
|
var isScrollParent = function isScrollParent(element) {
|
|
247
304
|
// Firefox wants us to check `-x` and `-y` variations as well
|
|
248
305
|
var _getComputedStyle = getComputedStyle(element),
|
|
@@ -325,7 +382,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
325
382
|
};
|
|
326
383
|
_this.handleKeyDown = function (event) {
|
|
327
384
|
if (event.key === 'Escape') {
|
|
328
|
-
_this.props.onEscapeAction();
|
|
385
|
+
_this.props.onEscapeAction(event);
|
|
329
386
|
}
|
|
330
387
|
};
|
|
331
388
|
return _this;
|
|
@@ -370,8 +427,11 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
370
427
|
value: function componentDidMount() {
|
|
371
428
|
this.mounted = true;
|
|
372
429
|
this.adjustPosition();
|
|
373
|
-
if (this.popoverContentRef) {
|
|
374
|
-
this.popoverContentRef.current
|
|
430
|
+
if (this.popoverContentRef.current) {
|
|
431
|
+
if (!focusFirstDescendant(this.popoverContentRef.current)) {
|
|
432
|
+
this.popoverContentRef.current.tabIndex = 0;
|
|
433
|
+
this.popoverContentRef.current.focus();
|
|
434
|
+
}
|
|
375
435
|
}
|
|
376
436
|
if (this.props.trackScroll) {
|
|
377
437
|
document.addEventListener('scroll', this.onScroll);
|
|
@@ -440,7 +500,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
440
500
|
}, position),
|
|
441
501
|
className: this.props.className,
|
|
442
502
|
role: this.props.role,
|
|
443
|
-
tabIndex: 0,
|
|
444
503
|
onKeyDown: this.handleKeyDown
|
|
445
504
|
}, this.props.children));
|
|
446
505
|
}
|
|
@@ -641,6 +700,14 @@ var Popover = /*#__PURE__*/function (_React$Component) {
|
|
|
641
700
|
_this.props.onOuterAction(event);
|
|
642
701
|
}
|
|
643
702
|
};
|
|
703
|
+
_this.onEscapeAction = function (event) {
|
|
704
|
+
var _a;
|
|
705
|
+
_this.setOpened(false);
|
|
706
|
+
if (_this.props.onOuterAction) {
|
|
707
|
+
_this.props.onOuterAction(event);
|
|
708
|
+
}
|
|
709
|
+
(_a = _this.childrenRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
710
|
+
};
|
|
644
711
|
_this.childrenRef = createRef();
|
|
645
712
|
return _this;
|
|
646
713
|
}
|
|
@@ -661,11 +728,7 @@ var Popover = /*#__PURE__*/function (_React$Component) {
|
|
|
661
728
|
});
|
|
662
729
|
return React.createElement(StatelessPopover, Object.assign({}, this.props, {
|
|
663
730
|
onOuterAction: this.onOuterAction,
|
|
664
|
-
onEscapeAction:
|
|
665
|
-
var _a;
|
|
666
|
-
_this2.setOpened(false);
|
|
667
|
-
(_a = _this2.childrenRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
668
|
-
},
|
|
731
|
+
onEscapeAction: this.onEscapeAction,
|
|
669
732
|
isOpen: isOpen,
|
|
670
733
|
role: this.props.role
|
|
671
734
|
}), childrenWithRef);
|
package/dist/popover.js
CHANGED
|
@@ -212,8 +212,8 @@ function styleInject(css, ref) {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
var css = ".popover-body-container__popover__12-19-2-alpha-
|
|
216
|
-
var styles = {"popover-body-container":"popover-body-container__popover__12-19-2-alpha-
|
|
215
|
+
var css = ".popover-body-container__popover__12-19-2-alpha-6 {\r\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n border-radius: var(--BorderRadiusL, 4px);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n background: var(--BackgroundDefault, #FFFFFF);\r\n z-index: var(--ZIndexModal, 10001);\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n}\r\n\r\n.popover-body__popover__12-19-2-alpha-6 {\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n padding: var(--SpaceSM, 12px);\r\n font-size: var(--FontSizeDefault, 13px);\r\n color: var(--FontColorDefault, #000000);\r\n}\r\n\r\n.popover-body--no-padding__popover__12-19-2-alpha-6 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-2-alpha-6 {\r\n position: absolute;\r\n pointer-events: none;\r\n z-index: calc(var(--ZIndexModal, 10001) + 1);\r\n overflow: hidden;\r\n display: -webkit-box;\r\n display: -ms-flexbox;\r\n display: flex;\r\n -webkit-box-align: center;\r\n -ms-flex-align: center;\r\n align-items: center;\r\n -webkit-box-pack: center;\r\n -ms-flex-pack: center;\r\n justify-content: center;\r\n}\r\n\r\n.popover-tip__popover__12-19-2-alpha-6:before {\r\n content: '';\r\n position: absolute;\r\n display: block;\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n background-color: var(--BackgroundDefault, #FFFFFF);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n /*\r\n geometry FTW\r\n\r\n 2*$popoverTipSize\r\n _______ _______\r\n | /|\\ |\r\n | / | \\ | $popoverTipSize\r\n | / | \\ |\r\n |/______|______\\|\r\n since tip is rotated 45 degrees, its width and height is a\r\n diagonal of a square with side=$popoverTipSize, thus diagonal\r\n is sqrt(2) * $popoverTipSize.\r\n sqrt(2) ~= 1.414, 1.4 used here to prevent too much rounding\r\n */\r\n width: 11.2px;\r\n height: 11.2px;\r\n -webkit-transform: rotate(45deg);\r\n transform: rotate(45deg);\r\n }\r\n\r\n.popover-tip--bottom__popover__12-19-2-alpha-6,\r\n .popover-tip--top__popover__12-19-2-alpha-6 {\r\n width: 100%;\r\n border-top: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-bottom: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 9px;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-2-alpha-6,\r\n .popover-tip--right__popover__12-19-2-alpha-6 {\r\n border-left: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-right: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 100%;\r\n width: 9px;\r\n }\r\n\r\n/*\r\n To determine tip position, we need to rotate it\r\n along the \"tip\" point, after that, the \"tip\" point\r\n can be placed with exactly 50% offset from the origin\r\n so that it is centered.\r\n */\r\n\r\n.popover-tip--bottom__popover__12-19-2-alpha-6:before {\r\n -webkit-transform-origin: left top;\r\n transform-origin: left top;\r\n left: 50%;\r\n top: 0;\r\n }\r\n\r\n.popover-tip--top__popover__12-19-2-alpha-6:before {\r\n -webkit-transform-origin: right bottom;\r\n transform-origin: right bottom;\r\n right: 50%;\r\n bottom: 0;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-2-alpha-6:before {\r\n -webkit-transform-origin: right top;\r\n transform-origin: right top;\r\n right: 0;\r\n top: 50%;\r\n }\r\n\r\n.popover-tip--right__popover__12-19-2-alpha-6:before {\r\n -webkit-transform-origin: left bottom;\r\n transform-origin: left bottom;\r\n left: 0;\r\n bottom: 50%;\r\n }\r\n";
|
|
216
|
+
var styles = {"popover-body-container":"popover-body-container__popover__12-19-2-alpha-6","popover-body":"popover-body__popover__12-19-2-alpha-6","popover-body--no-padding":"popover-body--no-padding__popover__12-19-2-alpha-6","popover-tip":"popover-tip__popover__12-19-2-alpha-6","popover-tip--bottom":"popover-tip--bottom__popover__12-19-2-alpha-6","popover-tip--top":"popover-tip--top__popover__12-19-2-alpha-6","popover-tip--left":"popover-tip--left__popover__12-19-2-alpha-6","popover-tip--right":"popover-tip--right__popover__12-19-2-alpha-6"};
|
|
217
217
|
styleInject(css);
|
|
218
218
|
|
|
219
219
|
var PopoverBody = function PopoverBody(_ref) {
|
|
@@ -250,6 +250,63 @@ var throttle = function throttle(func, limit) {
|
|
|
250
250
|
};
|
|
251
251
|
};
|
|
252
252
|
|
|
253
|
+
var isFocusable = function isFocusable(element) {
|
|
254
|
+
if (element.tabIndex < 0) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
if (element.disabled) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
switch (element.nodeName) {
|
|
261
|
+
case 'A':
|
|
262
|
+
return !!element.href && element.rel !== 'ignore';
|
|
263
|
+
case 'INPUT':
|
|
264
|
+
return element.type !== 'hidden';
|
|
265
|
+
case 'BUTTON':
|
|
266
|
+
case 'SELECT':
|
|
267
|
+
case 'TEXTAREA':
|
|
268
|
+
return true;
|
|
269
|
+
default:
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
var attemptFocus = function attemptFocus(element) {
|
|
274
|
+
if (!isFocusable(element)) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
try {
|
|
278
|
+
element.focus();
|
|
279
|
+
} catch (err) {}
|
|
280
|
+
return document.activeElement === element;
|
|
281
|
+
};
|
|
282
|
+
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
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return false;
|
|
308
|
+
};
|
|
309
|
+
|
|
253
310
|
var isScrollParent = function isScrollParent(element) {
|
|
254
311
|
// Firefox wants us to check `-x` and `-y` variations as well
|
|
255
312
|
var _getComputedStyle = getComputedStyle(element),
|
|
@@ -332,7 +389,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
332
389
|
};
|
|
333
390
|
_this.handleKeyDown = function (event) {
|
|
334
391
|
if (event.key === 'Escape') {
|
|
335
|
-
_this.props.onEscapeAction();
|
|
392
|
+
_this.props.onEscapeAction(event);
|
|
336
393
|
}
|
|
337
394
|
};
|
|
338
395
|
return _this;
|
|
@@ -377,8 +434,11 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
377
434
|
value: function componentDidMount() {
|
|
378
435
|
this.mounted = true;
|
|
379
436
|
this.adjustPosition();
|
|
380
|
-
if (this.popoverContentRef) {
|
|
381
|
-
this.popoverContentRef.current
|
|
437
|
+
if (this.popoverContentRef.current) {
|
|
438
|
+
if (!focusFirstDescendant(this.popoverContentRef.current)) {
|
|
439
|
+
this.popoverContentRef.current.tabIndex = 0;
|
|
440
|
+
this.popoverContentRef.current.focus();
|
|
441
|
+
}
|
|
382
442
|
}
|
|
383
443
|
if (this.props.trackScroll) {
|
|
384
444
|
document.addEventListener('scroll', this.onScroll);
|
|
@@ -447,7 +507,6 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
447
507
|
}, position),
|
|
448
508
|
className: this.props.className,
|
|
449
509
|
role: this.props.role,
|
|
450
|
-
tabIndex: 0,
|
|
451
510
|
onKeyDown: this.handleKeyDown
|
|
452
511
|
}, this.props.children));
|
|
453
512
|
}
|
|
@@ -648,6 +707,14 @@ var Popover = /*#__PURE__*/function (_React$Component) {
|
|
|
648
707
|
_this.props.onOuterAction(event);
|
|
649
708
|
}
|
|
650
709
|
};
|
|
710
|
+
_this.onEscapeAction = function (event) {
|
|
711
|
+
var _a;
|
|
712
|
+
_this.setOpened(false);
|
|
713
|
+
if (_this.props.onOuterAction) {
|
|
714
|
+
_this.props.onOuterAction(event);
|
|
715
|
+
}
|
|
716
|
+
(_a = _this.childrenRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
717
|
+
};
|
|
651
718
|
_this.childrenRef = React.createRef();
|
|
652
719
|
return _this;
|
|
653
720
|
}
|
|
@@ -668,11 +735,7 @@ var Popover = /*#__PURE__*/function (_React$Component) {
|
|
|
668
735
|
});
|
|
669
736
|
return React__default.createElement(StatelessPopover, Object.assign({}, this.props, {
|
|
670
737
|
onOuterAction: this.onOuterAction,
|
|
671
|
-
onEscapeAction:
|
|
672
|
-
var _a;
|
|
673
|
-
_this2.setOpened(false);
|
|
674
|
-
(_a = _this2.childrenRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
675
|
-
},
|
|
738
|
+
onEscapeAction: this.onEscapeAction,
|
|
676
739
|
isOpen: isOpen,
|
|
677
740
|
role: this.props.role
|
|
678
741
|
}), childrenWithRef);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@targetprocess/popover",
|
|
3
|
-
"version": "12.19.2-alpha.
|
|
3
|
+
"version": "12.19.2-alpha.6",
|
|
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": "cc4bc23e51d53edf286ab13cda5555cbcdd1c49f"
|
|
25
25
|
}
|