@jetbrains/ring-ui 7.0.80 → 7.0.82
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/components/dialog/dialog.js +4 -3
- package/components/dropdown/dropdown.css +4 -0
- package/components/dropdown/dropdown.js +6 -4
- package/components/popup/popup.d.ts +1 -0
- package/components/popup/popup.js +8 -32
- package/components/popup/popup.target.d.ts +7 -1
- package/components/popup/popup.target.js +3 -0
- package/components/select/select-popup.js +2 -2
- package/package.json +1 -1
|
@@ -9,7 +9,7 @@ import dataTests from '../global/data-tests';
|
|
|
9
9
|
import Shortcuts from '../shortcuts/shortcuts';
|
|
10
10
|
import TabTrap from '../tab-trap/tab-trap';
|
|
11
11
|
import Button from '../button/button';
|
|
12
|
-
import { PopupTarget, PopupTargetContext } from '../popup/popup.target';
|
|
12
|
+
import { normalizePopupTarget, PopupTarget, PopupTargetContext } from '../popup/popup.target';
|
|
13
13
|
import { getPopupContainer } from '../popup/popup';
|
|
14
14
|
import { preventerFactory as scrollPreventerFactory } from './dialog-body-scroll-preventer';
|
|
15
15
|
import styles from './dialog.css';
|
|
@@ -144,12 +144,13 @@ export default class Dialog extends PureComponent {
|
|
|
144
144
|
}
|
|
145
145
|
return (show && (<PopupTargetContext.Consumer>
|
|
146
146
|
{contextTarget => {
|
|
147
|
+
const normalizedContextTarget = normalizePopupTarget(contextTarget);
|
|
147
148
|
let targetElement = document.body;
|
|
148
149
|
if (portalTarget instanceof HTMLElement) {
|
|
149
150
|
targetElement = portalTarget;
|
|
150
151
|
}
|
|
151
|
-
else if (
|
|
152
|
-
const container = getPopupContainer(
|
|
152
|
+
else if (normalizedContextTarget !== undefined) {
|
|
153
|
+
const container = getPopupContainer(normalizedContextTarget);
|
|
153
154
|
if (container) {
|
|
154
155
|
targetElement = container;
|
|
155
156
|
}
|
|
@@ -125,10 +125,12 @@ export default class Dropdown extends Component {
|
|
|
125
125
|
onContextMenu: hoverMode ? this.handlePopupInteraction : undefined,
|
|
126
126
|
dontCloseOnAnchorClick: true,
|
|
127
127
|
};
|
|
128
|
-
return (<div data-test={dataTests('ring-dropdown', dataTest)} {...restProps}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
return (<div data-test={dataTests('ring-dropdown', dataTest)} {...restProps} onMouseEnter={hoverMode ? this.onMouseEnter : undefined} onMouseLeave={hoverMode ? this.onMouseLeave : undefined} className={classes}>
|
|
129
|
+
{clickMode ? (<div data-test='ring-dropdown-anchor-click-interceptor' className={styles.clickInterceptor} onClick={this.onClick}
|
|
130
|
+
// anchorElement should be a `button` or an `a`
|
|
131
|
+
role='presentation'>
|
|
132
|
+
{anchorElement}
|
|
133
|
+
</div>) : (anchorElement)}
|
|
132
134
|
{typeof children === 'function'
|
|
133
135
|
? children(childProps)
|
|
134
136
|
: cloneElement(children, childProps)}
|
|
@@ -94,6 +94,7 @@ export default class Popup<P extends BasePopupProps = PopupProps> extends PureCo
|
|
|
94
94
|
parent?: HTMLElement | null;
|
|
95
95
|
container?: HTMLElement | null;
|
|
96
96
|
ringPopupTarget?: string | Element;
|
|
97
|
+
private cssPositioningFromContext;
|
|
97
98
|
clickStartedInsidePopup: boolean;
|
|
98
99
|
shouldUseShortcuts(): boolean;
|
|
99
100
|
listeners: Listeners;
|
|
@@ -15,33 +15,11 @@ import TabTrap from '../tab-trap/tab-trap';
|
|
|
15
15
|
import { getConfiguration } from '../global/configuration';
|
|
16
16
|
import position from './position';
|
|
17
17
|
import { DEFAULT_DIRECTIONS, Dimension, Directions, Display, MaxHeight, MinWidth } from './popup.consts';
|
|
18
|
-
import { PopupTargetContext, PopupTarget } from './popup.target';
|
|
18
|
+
import { PopupTargetContext, PopupTarget, normalizePopupTarget } from './popup.target';
|
|
19
19
|
import { setCSSAnchorPositioning, supportsCSSAnchorPositioning } from './position-css';
|
|
20
20
|
import { ThemeContext, WithThemeClasses } from '../global/theme';
|
|
21
21
|
import styles from './popup.css';
|
|
22
22
|
export { PopupTargetContext, PopupTarget };
|
|
23
|
-
const isPossibleClientSideNavigation = (event) => {
|
|
24
|
-
const target = event.target;
|
|
25
|
-
const link = target.closest('a');
|
|
26
|
-
// Taken from https://github.com/nanostores/router/blob/80a333db4cf0789fda21a02715ebabca15192642/index.js#L58-L69
|
|
27
|
-
return (link &&
|
|
28
|
-
event.button === 0 && // Left mouse button
|
|
29
|
-
link.target !== '_blank' && // Not for new tab
|
|
30
|
-
link.origin === location.origin && // Not external link
|
|
31
|
-
link.rel !== 'external' && // Not external link
|
|
32
|
-
link.target !== '_self' && // Now manually disabled
|
|
33
|
-
!link.download && // Not download link
|
|
34
|
-
!event.altKey && // Not download link by user
|
|
35
|
-
!event.metaKey && // Not open in new tab by user
|
|
36
|
-
!event.ctrlKey && // Not open in new tab by user
|
|
37
|
-
!event.shiftKey && // Not open in new window by user
|
|
38
|
-
!event.defaultPrevented);
|
|
39
|
-
};
|
|
40
|
-
const stop = (event) => {
|
|
41
|
-
if (!isPossibleClientSideNavigation(event)) {
|
|
42
|
-
event.stopPropagation();
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
23
|
export const getPopupContainer = (target) => typeof target === 'string' ? document.querySelector(`[data-portaltarget=${target}]`) : target;
|
|
46
24
|
/**
|
|
47
25
|
* @constructor
|
|
@@ -101,6 +79,7 @@ export default class Popup extends PureComponent {
|
|
|
101
79
|
parent;
|
|
102
80
|
container;
|
|
103
81
|
ringPopupTarget;
|
|
82
|
+
cssPositioningFromContext;
|
|
104
83
|
clickStartedInsidePopup = false;
|
|
105
84
|
shouldUseShortcuts() {
|
|
106
85
|
const { shortcuts, hidden } = this.props;
|
|
@@ -167,9 +146,7 @@ export default class Popup extends PureComponent {
|
|
|
167
146
|
if (!supportsCSSAnchorPositioning()) {
|
|
168
147
|
return false;
|
|
169
148
|
}
|
|
170
|
-
return this.props.cssPositioning
|
|
171
|
-
? this.props.cssPositioning
|
|
172
|
-
: getConfiguration().popupsCssPositioning;
|
|
149
|
+
return this.props.cssPositioning ?? this.cssPositioningFromContext ?? getConfiguration().popupsCssPositioning;
|
|
173
150
|
}
|
|
174
151
|
_updatePosition = () => {
|
|
175
152
|
const popup = this.popup;
|
|
@@ -307,7 +284,10 @@ export default class Popup extends PureComponent {
|
|
|
307
284
|
{theme => (<WithThemeClasses theme={theme.theme}>
|
|
308
285
|
{themeClasses => (<PopupTargetContext.Consumer>
|
|
309
286
|
{value => {
|
|
310
|
-
this.ringPopupTarget = value;
|
|
287
|
+
this.ringPopupTarget = normalizePopupTarget(value);
|
|
288
|
+
if (!(typeof value === 'string' || value instanceof Element)) {
|
|
289
|
+
this.cssPositioningFromContext = value?.cssPositioning;
|
|
290
|
+
}
|
|
311
291
|
const classes = classNames(className, theme.passToPopups ? themeClasses : null, styles.popup, {
|
|
312
292
|
[styles.cssAnchoredPopup]: this.shouldUseCssPositioning(),
|
|
313
293
|
[styles.attached]: attached,
|
|
@@ -315,11 +295,7 @@ export default class Popup extends PureComponent {
|
|
|
315
295
|
[styles.showing]: showing,
|
|
316
296
|
[styles.largeBorderRadius]: largeBorderRadius,
|
|
317
297
|
});
|
|
318
|
-
return (<span
|
|
319
|
-
// prevent bubbling through portal
|
|
320
|
-
onClick={stop}
|
|
321
|
-
// This handler only blocks bubbling through React portal
|
|
322
|
-
role='presentation' ref={this.portalRef}>
|
|
298
|
+
return (<span ref={this.portalRef}>
|
|
323
299
|
{this.shouldUseShortcuts() && <Shortcuts map={this.shortcutsMap} scope={this.shortcutsScope}/>}
|
|
324
300
|
|
|
325
301
|
{client !== false &&
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
-
|
|
2
|
+
interface ComplexConfig {
|
|
3
|
+
target: string | Element | undefined;
|
|
4
|
+
cssPositioning?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const PopupTargetContext: import("react").Context<string | Element | ComplexConfig | undefined>;
|
|
3
7
|
export interface PopupTargetProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
4
8
|
id: string;
|
|
5
9
|
children: ReactNode | ((target: ReactNode) => ReactNode);
|
|
6
10
|
}
|
|
11
|
+
export declare function normalizePopupTarget(value: string | Element | undefined | ComplexConfig): string | Element | undefined;
|
|
7
12
|
export declare const PopupTarget: import("react").ForwardRefExoticComponent<PopupTargetProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
13
|
+
export {};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createContext, forwardRef } from 'react';
|
|
2
2
|
export const PopupTargetContext = createContext(undefined);
|
|
3
|
+
export function normalizePopupTarget(value) {
|
|
4
|
+
return typeof value === 'string' || value instanceof Element ? value : value?.target;
|
|
5
|
+
}
|
|
3
6
|
export const PopupTarget = forwardRef(function PopupTarget({ id, children, ...restProps }, ref) {
|
|
4
7
|
const target = (<div {...restProps} data-portaltarget={id} ref={ref}>
|
|
5
8
|
{typeof children !== 'function' && children}
|
|
@@ -10,7 +10,7 @@ import memoizeOne from 'memoize-one';
|
|
|
10
10
|
import Icon from '../icon/icon';
|
|
11
11
|
import Popup, { getPopupContainer } from '../popup/popup';
|
|
12
12
|
import { maxHeightForDirection } from '../popup/position';
|
|
13
|
-
import { PopupTargetContext } from '../popup/popup.target';
|
|
13
|
+
import { normalizePopupTarget, PopupTargetContext } from '../popup/popup.target';
|
|
14
14
|
import List from '../list/list';
|
|
15
15
|
import LoaderInline from '../loader-inline/loader-inline';
|
|
16
16
|
import shortcutsHOC from '../shortcuts/shortcuts-hoc';
|
|
@@ -329,7 +329,7 @@ export default class SelectPopup extends PureComponent {
|
|
|
329
329
|
{ringPopupTarget => {
|
|
330
330
|
const filterWithTags = this.getFilterWithTags();
|
|
331
331
|
const selectAll = multiple && typeof multiple === 'object' && !multiple.limit && multiple.selectAll && this.getSelectAll();
|
|
332
|
-
const list = this.getList(this.props.ringPopupTarget || ringPopupTarget);
|
|
332
|
+
const list = this.getList(this.props.ringPopupTarget || normalizePopupTarget(ringPopupTarget));
|
|
333
333
|
const bottomLine = this.getBottomLine();
|
|
334
334
|
const hasContent = filterWithTags || selectAll || list || bottomLine || toolbar || topbar;
|
|
335
335
|
return (<Popup trapFocus={false} ref={this.popupRef} hidden={hidden || !hasContent} attached={isInputMode} className={classes} dontCloseOnAnchorClick anchorElement={anchorElement} minWidth={minWidth} onCloseAttempt={onCloseAttempt} onOutsideClick={onOutsideClick} directions={directions} top={top} left={left} offset={offset} onMouseDown={this.mouseDownHandler} target={this.props.ringPopupTarget} autoCorrectTopOverflow={false} style={style} largeBorderRadius>
|