@targetprocess/popover 12.32.4 → 12.32.5-ci.0
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/PopoverContainer.tsx +6 -2
- package/__tests__/Popover.tests.tsx +53 -0
- package/dist/popover.es.js +18 -14
- package/dist/popover.js +14 -8
- package/package.json +2 -2
package/PopoverContainer.tsx
CHANGED
|
@@ -186,9 +186,13 @@ export class PopoverContainer extends React.Component<
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
if (this.popoverContentRef.current && !this.props.trapFocus) {
|
|
189
|
-
|
|
189
|
+
// The position computed by adjustPosition() is applied on the next render, so the popover
|
|
190
|
+
// still sits at the top-left corner of its container here. A plain focus() would scroll the
|
|
191
|
+
// container to that corner, so the page jumps away from the trigger.
|
|
192
|
+
const focusOptions = {preventScroll: true}
|
|
193
|
+
if (!focusFirstDescendant(this.popoverContentRef.current, focusOptions)) {
|
|
190
194
|
this.popoverContentRef.current.tabIndex = -1
|
|
191
|
-
this.popoverContentRef.current.focus()
|
|
195
|
+
this.popoverContentRef.current.focus(focusOptions)
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
}
|
|
@@ -18,6 +18,17 @@ const ComponentWithRef = React.forwardRef<HTMLElement>((prop, ref) => (
|
|
|
18
18
|
</div>
|
|
19
19
|
))
|
|
20
20
|
|
|
21
|
+
const originalFocus = HTMLElement.prototype.focus
|
|
22
|
+
|
|
23
|
+
const mockFocus = () => {
|
|
24
|
+
const focus = jest.fn(function (this: HTMLElement, options?: FocusOptions) {
|
|
25
|
+
originalFocus.call(this, options)
|
|
26
|
+
})
|
|
27
|
+
HTMLElement.prototype.focus = focus
|
|
28
|
+
|
|
29
|
+
return focus
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
describe('Popover', () => {
|
|
22
33
|
beforeEach(() => {
|
|
23
34
|
cleanDocumentBody()
|
|
@@ -78,4 +89,46 @@ describe('Popover', () => {
|
|
|
78
89
|
expect(ref1).toHaveBeenCalled()
|
|
79
90
|
expect(ref2).toHaveBeenCalled()
|
|
80
91
|
})
|
|
92
|
+
|
|
93
|
+
describe('without focus trap', () => {
|
|
94
|
+
afterEach(() => {
|
|
95
|
+
HTMLElement.prototype.focus = originalFocus
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('should focus container without scrolling when body has no focusable elements', () => {
|
|
99
|
+
const focus = mockFocus()
|
|
100
|
+
|
|
101
|
+
mount(
|
|
102
|
+
<Popover isOpen trapFocus={false} body={<PopoverBody>foo</PopoverBody>}>
|
|
103
|
+
<button />
|
|
104
|
+
</Popover>
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
expect(document.activeElement).toBe(document.querySelector('[id^="popover-container-"]'))
|
|
108
|
+
expect(focus).toHaveBeenCalledTimes(1)
|
|
109
|
+
expect(focus).toHaveBeenCalledWith({preventScroll: true})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('should focus first focusable element without scrolling', () => {
|
|
113
|
+
const focus = mockFocus()
|
|
114
|
+
|
|
115
|
+
mount(
|
|
116
|
+
<Popover
|
|
117
|
+
isOpen
|
|
118
|
+
trapFocus={false}
|
|
119
|
+
body={
|
|
120
|
+
<PopoverBody>
|
|
121
|
+
<button className="foo" />
|
|
122
|
+
</PopoverBody>
|
|
123
|
+
}
|
|
124
|
+
>
|
|
125
|
+
<button />
|
|
126
|
+
</Popover>
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
expect(document.activeElement).toBe(document.querySelector('.foo'))
|
|
130
|
+
expect(focus).toHaveBeenCalledTimes(1)
|
|
131
|
+
expect(focus).toHaveBeenCalledWith({preventScroll: true})
|
|
132
|
+
})
|
|
133
|
+
})
|
|
81
134
|
})
|
package/dist/popover.es.js
CHANGED
|
@@ -169,15 +169,14 @@ var PopoverPosition = {
|
|
|
169
169
|
};
|
|
170
170
|
|
|
171
171
|
function styleInject(css, ref) {
|
|
172
|
-
if (
|
|
172
|
+
if (ref === void 0) ref = {};
|
|
173
173
|
var insertAt = ref.insertAt;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
if (typeof document === 'undefined') {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
177
|
var head = document.head || document.getElementsByTagName('head')[0];
|
|
178
178
|
var style = document.createElement('style');
|
|
179
179
|
style.type = 'text/css';
|
|
180
|
-
|
|
181
180
|
if (insertAt === 'top') {
|
|
182
181
|
if (head.firstChild) {
|
|
183
182
|
head.insertBefore(style, head.firstChild);
|
|
@@ -187,7 +186,6 @@ function styleInject(css, ref) {
|
|
|
187
186
|
} else {
|
|
188
187
|
head.appendChild(style);
|
|
189
188
|
}
|
|
190
|
-
|
|
191
189
|
if (style.styleSheet) {
|
|
192
190
|
style.styleSheet.cssText = css;
|
|
193
191
|
} else {
|
|
@@ -195,8 +193,8 @@ function styleInject(css, ref) {
|
|
|
195
193
|
}
|
|
196
194
|
}
|
|
197
195
|
|
|
198
|
-
var css_248z = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n\n.popover-body-container__popover__12-32-
|
|
199
|
-
var styles = {"popover-body-container":"popover-body-container__popover__12-32-
|
|
196
|
+
var css_248z = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n\n.popover-body-container__popover__12-32-5-ci-0 {\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\n border-radius: var(--BorderRadiusL, 4px);\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\n background: var(--BackgroundDefault, #FFFFFF);\n z-index: var(--ZIndexModal, 10001);\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n}\n\n.popover-body__popover__12-32-5-ci-0 {\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n padding: var(--SpaceSM, 12px);\n font-size: var(--FontSizeDefault, 13px);\n color: var(--FontColorDefault, #000000);\n}\n\n.popover-body--no-padding__popover__12-32-5-ci-0 {\n padding: 0;\n }\n\n.popover-tip__popover__12-32-5-ci-0 {\n position: absolute;\n pointer-events: none;\n z-index: calc(1 + var(--ZIndexModal, 10001));\n overflow: hidden;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n\n /*\n To determine tip position, we need to rotate it\n along the \"tip\" point, after that, the \"tip\" point\n can be placed with exactly 50% offset from the origin\n so that it is centered.\n */\n}\n\n.popover-tip__popover__12-32-5-ci-0:before {\n content: '';\n position: absolute;\n display: block;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n background-color: var(--BackgroundDefault, #FFFFFF);\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\n /*\n geometry FTW\n\n 2*$popoverTipSize\n _______ _______\n | /|\\ |\n | / | \\ | $popoverTipSize\n | / | \\ |\n |/______|______\\|\n since tip is rotated 45 degrees, its width and height is a\n diagonal of a square with side=$popoverTipSize, thus diagonal\n is sqrt(2) * $popoverTipSize.\n sqrt(2) ~= 1.414, 1.4 used here to prevent too much rounding\n */\n width: calc(11.2px);\n height: calc(11.2px);\n -webkit-transform: rotate(45deg);\n transform: rotate(45deg);\n }\n\n.popover-tip--bottom__popover__12-32-5-ci-0,\n .popover-tip--top__popover__12-32-5-ci-0 {\n width: 100%;\n border-top: 1px var(--BackgroundDefault, #FFFFFF);\n border-bottom: 1px var(--BackgroundDefault, #FFFFFF);\n height: calc(9px);\n }\n\n.popover-tip--left__popover__12-32-5-ci-0,\n .popover-tip--right__popover__12-32-5-ci-0 {\n border-left: 1px var(--BackgroundDefault, #FFFFFF);\n border-right: 1px var(--BackgroundDefault, #FFFFFF);\n height: 100%;\n width: calc(9px);\n }\n\n.popover-tip--bottom__popover__12-32-5-ci-0:before {\n -webkit-transform-origin: left top;\n transform-origin: left top;\n left: 50%;\n top: 0;\n }\n\n.popover-tip--top__popover__12-32-5-ci-0:before {\n -webkit-transform-origin: right bottom;\n transform-origin: right bottom;\n right: 50%;\n bottom: 0;\n }\n\n.popover-tip--left__popover__12-32-5-ci-0:before {\n -webkit-transform-origin: right top;\n transform-origin: right top;\n right: 0;\n top: 50%;\n }\n\n.popover-tip--right__popover__12-32-5-ci-0:before {\n -webkit-transform-origin: left bottom;\n transform-origin: left bottom;\n left: 0;\n bottom: 50%;\n }\n";
|
|
197
|
+
var styles = {"popover-body-container":"popover-body-container__popover__12-32-5-ci-0","popover-body":"popover-body__popover__12-32-5-ci-0","popover-body--no-padding":"popover-body--no-padding__popover__12-32-5-ci-0","popover-tip":"popover-tip__popover__12-32-5-ci-0","popover-tip--bottom":"popover-tip--bottom__popover__12-32-5-ci-0","popover-tip--top":"popover-tip--top__popover__12-32-5-ci-0","popover-tip--left":"popover-tip--left__popover__12-32-5-ci-0","popover-tip--right":"popover-tip--right__popover__12-32-5-ci-0"};
|
|
200
198
|
styleInject(css_248z);
|
|
201
199
|
|
|
202
200
|
/*********************************************************************
|
|
@@ -268,17 +266,17 @@ var isFocusable = function isFocusable(element) {
|
|
|
268
266
|
return false;
|
|
269
267
|
}
|
|
270
268
|
};
|
|
271
|
-
var attemptFocus = function attemptFocus(element) {
|
|
269
|
+
var attemptFocus = function attemptFocus(element, options) {
|
|
272
270
|
if (!isFocusable(element)) {
|
|
273
271
|
return false;
|
|
274
272
|
}
|
|
275
|
-
element.focus();
|
|
273
|
+
element.focus(options);
|
|
276
274
|
return document.activeElement === element;
|
|
277
275
|
};
|
|
278
|
-
var _focusFirstDescendant = function focusFirstDescendant(element) {
|
|
276
|
+
var _focusFirstDescendant = function focusFirstDescendant(element, options) {
|
|
279
277
|
for (var _i = 0, _Array$from = Array.from(element.childNodes); _i < _Array$from.length; _i++) {
|
|
280
278
|
var child = _Array$from[_i];
|
|
281
|
-
if (attemptFocus(child) || _focusFirstDescendant(child)) {
|
|
279
|
+
if (attemptFocus(child, options) || _focusFirstDescendant(child, options)) {
|
|
282
280
|
return true;
|
|
283
281
|
}
|
|
284
282
|
}
|
|
@@ -423,9 +421,15 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
423
421
|
}
|
|
424
422
|
}
|
|
425
423
|
if (this.popoverContentRef.current && !this.props.trapFocus) {
|
|
426
|
-
|
|
424
|
+
// The position computed by adjustPosition() is applied on the next render, so the popover
|
|
425
|
+
// still sits at the top-left corner of its container here. A plain focus() would scroll the
|
|
426
|
+
// container to that corner, so the page jumps away from the trigger.
|
|
427
|
+
var focusOptions = {
|
|
428
|
+
preventScroll: true
|
|
429
|
+
};
|
|
430
|
+
if (!_focusFirstDescendant(this.popoverContentRef.current, focusOptions)) {
|
|
427
431
|
this.popoverContentRef.current.tabIndex = -1;
|
|
428
|
-
this.popoverContentRef.current.focus();
|
|
432
|
+
this.popoverContentRef.current.focus(focusOptions);
|
|
429
433
|
}
|
|
430
434
|
}
|
|
431
435
|
}
|
package/dist/popover.js
CHANGED
|
@@ -206,8 +206,8 @@ function styleInject(css, ref) {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
var css_248z = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n\n.popover-body-container__popover__12-32-
|
|
210
|
-
var styles = {"popover-body-container":"popover-body-container__popover__12-32-
|
|
209
|
+
var css_248z = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n\n.popover-body-container__popover__12-32-5-ci-0 {\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\n border-radius: var(--BorderRadiusL, 4px);\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\n background: var(--BackgroundDefault, #FFFFFF);\n z-index: var(--ZIndexModal, 10001);\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n}\n\n.popover-body__popover__12-32-5-ci-0 {\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n padding: var(--SpaceSM, 12px);\n font-size: var(--FontSizeDefault, 13px);\n color: var(--FontColorDefault, #000000);\n}\n\n.popover-body--no-padding__popover__12-32-5-ci-0 {\n padding: 0;\n }\n\n.popover-tip__popover__12-32-5-ci-0 {\n position: absolute;\n pointer-events: none;\n z-index: calc(1 + var(--ZIndexModal, 10001));\n overflow: hidden;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n\n /*\n To determine tip position, we need to rotate it\n along the \"tip\" point, after that, the \"tip\" point\n can be placed with exactly 50% offset from the origin\n so that it is centered.\n */\n}\n\n.popover-tip__popover__12-32-5-ci-0:before {\n content: '';\n position: absolute;\n display: block;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n background-color: var(--BackgroundDefault, #FFFFFF);\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\n /*\n geometry FTW\n\n 2*$popoverTipSize\n _______ _______\n | /|\\ |\n | / | \\ | $popoverTipSize\n | / | \\ |\n |/______|______\\|\n since tip is rotated 45 degrees, its width and height is a\n diagonal of a square with side=$popoverTipSize, thus diagonal\n is sqrt(2) * $popoverTipSize.\n sqrt(2) ~= 1.414, 1.4 used here to prevent too much rounding\n */\n width: calc(11.2px);\n height: calc(11.2px);\n -webkit-transform: rotate(45deg);\n transform: rotate(45deg);\n }\n\n.popover-tip--bottom__popover__12-32-5-ci-0,\n .popover-tip--top__popover__12-32-5-ci-0 {\n width: 100%;\n border-top: 1px var(--BackgroundDefault, #FFFFFF);\n border-bottom: 1px var(--BackgroundDefault, #FFFFFF);\n height: calc(9px);\n }\n\n.popover-tip--left__popover__12-32-5-ci-0,\n .popover-tip--right__popover__12-32-5-ci-0 {\n border-left: 1px var(--BackgroundDefault, #FFFFFF);\n border-right: 1px var(--BackgroundDefault, #FFFFFF);\n height: 100%;\n width: calc(9px);\n }\n\n.popover-tip--bottom__popover__12-32-5-ci-0:before {\n -webkit-transform-origin: left top;\n transform-origin: left top;\n left: 50%;\n top: 0;\n }\n\n.popover-tip--top__popover__12-32-5-ci-0:before {\n -webkit-transform-origin: right bottom;\n transform-origin: right bottom;\n right: 50%;\n bottom: 0;\n }\n\n.popover-tip--left__popover__12-32-5-ci-0:before {\n -webkit-transform-origin: right top;\n transform-origin: right top;\n right: 0;\n top: 50%;\n }\n\n.popover-tip--right__popover__12-32-5-ci-0:before {\n -webkit-transform-origin: left bottom;\n transform-origin: left bottom;\n left: 0;\n bottom: 50%;\n }\n";
|
|
210
|
+
var styles = {"popover-body-container":"popover-body-container__popover__12-32-5-ci-0","popover-body":"popover-body__popover__12-32-5-ci-0","popover-body--no-padding":"popover-body--no-padding__popover__12-32-5-ci-0","popover-tip":"popover-tip__popover__12-32-5-ci-0","popover-tip--bottom":"popover-tip--bottom__popover__12-32-5-ci-0","popover-tip--top":"popover-tip--top__popover__12-32-5-ci-0","popover-tip--left":"popover-tip--left__popover__12-32-5-ci-0","popover-tip--right":"popover-tip--right__popover__12-32-5-ci-0"};
|
|
211
211
|
styleInject(css_248z);
|
|
212
212
|
|
|
213
213
|
/*********************************************************************
|
|
@@ -279,17 +279,17 @@ var isFocusable = function isFocusable(element) {
|
|
|
279
279
|
return false;
|
|
280
280
|
}
|
|
281
281
|
};
|
|
282
|
-
var attemptFocus = function attemptFocus(element) {
|
|
282
|
+
var attemptFocus = function attemptFocus(element, options) {
|
|
283
283
|
if (!isFocusable(element)) {
|
|
284
284
|
return false;
|
|
285
285
|
}
|
|
286
|
-
element.focus();
|
|
286
|
+
element.focus(options);
|
|
287
287
|
return document.activeElement === element;
|
|
288
288
|
};
|
|
289
|
-
var _focusFirstDescendant = function focusFirstDescendant(element) {
|
|
289
|
+
var _focusFirstDescendant = function focusFirstDescendant(element, options) {
|
|
290
290
|
for (var _i = 0, _Array$from = Array.from(element.childNodes); _i < _Array$from.length; _i++) {
|
|
291
291
|
var child = _Array$from[_i];
|
|
292
|
-
if (attemptFocus(child) || _focusFirstDescendant(child)) {
|
|
292
|
+
if (attemptFocus(child, options) || _focusFirstDescendant(child, options)) {
|
|
293
293
|
return true;
|
|
294
294
|
}
|
|
295
295
|
}
|
|
@@ -434,9 +434,15 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
436
|
if (this.popoverContentRef.current && !this.props.trapFocus) {
|
|
437
|
-
|
|
437
|
+
// The position computed by adjustPosition() is applied on the next render, so the popover
|
|
438
|
+
// still sits at the top-left corner of its container here. A plain focus() would scroll the
|
|
439
|
+
// container to that corner, so the page jumps away from the trigger.
|
|
440
|
+
var focusOptions = {
|
|
441
|
+
preventScroll: true
|
|
442
|
+
};
|
|
443
|
+
if (!_focusFirstDescendant(this.popoverContentRef.current, focusOptions)) {
|
|
438
444
|
this.popoverContentRef.current.tabIndex = -1;
|
|
439
|
-
this.popoverContentRef.current.focus();
|
|
445
|
+
this.popoverContentRef.current.focus(focusOptions);
|
|
440
446
|
}
|
|
441
447
|
}
|
|
442
448
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@targetprocess/popover",
|
|
3
|
-
"version": "12.32.
|
|
3
|
+
"version": "12.32.5-ci.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/popover.js",
|
|
6
6
|
"module": "dist/popover.es.js",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "2ac54070a00e3021378b51dc806c7a7b5973ea2b"
|
|
26
26
|
}
|