@dnb/eufemia 9.32.0 → 9.32.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/CHANGELOG.md +8 -0
- package/cjs/components/slider/SliderThumb.js +17 -4
- package/cjs/components/slider/SliderTrack.js +3 -6
- package/cjs/components/slider/hooks/useSliderEvents.d.ts +2 -2
- package/cjs/components/slider/hooks/useSliderEvents.js +3 -2
- package/cjs/components/tooltip/Tooltip.js +21 -18
- package/cjs/components/tooltip/TooltipContainer.js +42 -17
- package/cjs/components/tooltip/TooltipHelpers.d.ts +1 -1
- package/cjs/components/tooltip/TooltipHelpers.js +5 -9
- package/cjs/components/tooltip/TooltipPortal.d.ts +1 -1
- package/cjs/components/tooltip/TooltipPortal.js +47 -30
- package/cjs/components/tooltip/TooltipWithEvents.d.ts +1 -1
- package/cjs/components/tooltip/TooltipWithEvents.js +69 -41
- package/cjs/components/tooltip/types.d.ts +1 -0
- package/cjs/shared/Eufemia.js +1 -1
- package/cjs/shared/component-helper.js +1 -1
- package/cjs/style/dnb-ui-elements.css +31 -16
- package/cjs/style/dnb-ui-elements.min.css +1 -1
- package/cjs/style/dnb-ui-tags.css +60 -31
- package/cjs/style/dnb-ui-tags.min.css +1 -1
- package/cjs/style/elements/ui-spacing.scss +3 -1
- package/cjs/style/themes/theme-eiendom/dnb-theme-eiendom.css +31 -16
- package/cjs/style/themes/theme-eiendom/dnb-theme-eiendom.min.css +1 -1
- package/cjs/style/themes/theme-ui/dnb-theme-ui.css +31 -16
- package/cjs/style/themes/theme-ui/dnb-theme-ui.min.css +1 -1
- package/components/slider/SliderThumb.js +18 -5
- package/components/slider/SliderTrack.js +3 -6
- package/components/slider/hooks/useSliderEvents.d.ts +2 -2
- package/components/slider/hooks/useSliderEvents.js +3 -2
- package/components/tooltip/Tooltip.js +21 -18
- package/components/tooltip/TooltipContainer.js +41 -18
- package/components/tooltip/TooltipHelpers.d.ts +1 -1
- package/components/tooltip/TooltipHelpers.js +5 -9
- package/components/tooltip/TooltipPortal.d.ts +1 -1
- package/components/tooltip/TooltipPortal.js +46 -29
- package/components/tooltip/TooltipWithEvents.d.ts +1 -1
- package/components/tooltip/TooltipWithEvents.js +67 -42
- package/components/tooltip/types.d.ts +1 -0
- package/es/components/slider/SliderThumb.js +18 -5
- package/es/components/slider/SliderTrack.js +3 -6
- package/es/components/slider/hooks/useSliderEvents.d.ts +2 -2
- package/es/components/slider/hooks/useSliderEvents.js +3 -2
- package/es/components/tooltip/Tooltip.js +13 -15
- package/es/components/tooltip/TooltipContainer.js +37 -20
- package/es/components/tooltip/TooltipHelpers.d.ts +1 -1
- package/es/components/tooltip/TooltipHelpers.js +5 -9
- package/es/components/tooltip/TooltipPortal.d.ts +1 -1
- package/es/components/tooltip/TooltipPortal.js +44 -29
- package/es/components/tooltip/TooltipWithEvents.d.ts +1 -1
- package/es/components/tooltip/TooltipWithEvents.js +69 -43
- package/es/components/tooltip/types.d.ts +1 -0
- package/es/shared/Eufemia.js +1 -1
- package/es/shared/component-helper.js +1 -1
- package/es/style/dnb-ui-elements.css +31 -16
- package/es/style/dnb-ui-elements.min.css +1 -1
- package/es/style/dnb-ui-tags.css +60 -31
- package/es/style/dnb-ui-tags.min.css +1 -1
- package/es/style/elements/ui-spacing.scss +3 -1
- package/es/style/themes/theme-eiendom/dnb-theme-eiendom.css +31 -16
- package/es/style/themes/theme-eiendom/dnb-theme-eiendom.min.css +1 -1
- package/es/style/themes/theme-ui/dnb-theme-ui.css +31 -16
- package/es/style/themes/theme-ui/dnb-theme-ui.min.css +1 -1
- package/esm/dnb-ui-basis.min.mjs +1 -1
- package/esm/dnb-ui-components.min.mjs +1 -1
- package/esm/dnb-ui-elements.min.mjs +3 -3
- package/esm/dnb-ui-extensions.min.mjs +1 -1
- package/esm/dnb-ui-lib.min.mjs +2 -2
- package/esm/dnb-ui-web-components.min.mjs +2 -2
- package/package.json +1 -1
- package/shared/Eufemia.js +1 -1
- package/shared/component-helper.js +1 -1
- package/style/dnb-ui-elements.css +31 -16
- package/style/dnb-ui-elements.min.css +1 -1
- package/style/dnb-ui-tags.css +60 -31
- package/style/dnb-ui-tags.min.css +1 -1
- package/style/elements/ui-spacing.scss +3 -1
- package/style/themes/theme-eiendom/dnb-theme-eiendom.css +31 -16
- package/style/themes/theme-eiendom/dnb-theme-eiendom.min.css +1 -1
- package/style/themes/theme-ui/dnb-theme-ui.css +31 -16
- package/style/themes/theme-ui/dnb-theme-ui.min.css +1 -1
- package/umd/dnb-ui-basis.min.js +1 -1
- package/umd/dnb-ui-components.min.js +1 -1
- package/umd/dnb-ui-elements.min.js +2 -2
- package/umd/dnb-ui-extensions.min.js +1 -1
- package/umd/dnb-ui-lib.min.js +2 -2
- package/umd/dnb-ui-web-components.min.js +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { combineDescribedBy, combineLabelledBy, validateDOMAttributes } from '../../shared/component-helper';
|
|
3
|
+
import { combineDescribedBy, combineLabelledBy, validateDOMAttributes, warn } from '../../shared/component-helper';
|
|
4
4
|
import Button from '../button/Button';
|
|
5
5
|
import Tooltip from '../tooltip/Tooltip';
|
|
6
6
|
import { useSliderEvents } from './hooks/useSliderEvents';
|
|
@@ -68,6 +68,12 @@ function Thumb({
|
|
|
68
68
|
|
|
69
69
|
const onMouseLeaveHandler = () => {
|
|
70
70
|
setShowTooltip(false);
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
elemRef.current.dispatchEvent(new Event('mouseleave'));
|
|
74
|
+
} catch (e) {
|
|
75
|
+
warn(e);
|
|
76
|
+
}
|
|
71
77
|
};
|
|
72
78
|
|
|
73
79
|
const {
|
|
@@ -98,6 +104,12 @@ function Thumb({
|
|
|
98
104
|
helperParams.onFocus = event => {
|
|
99
105
|
onHelperFocusHandler(event);
|
|
100
106
|
onMouseEnterHandler();
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
elemRef.current.dispatchEvent(new Event('mouseenter'));
|
|
110
|
+
} catch (e) {
|
|
111
|
+
warn(e);
|
|
112
|
+
}
|
|
101
113
|
};
|
|
102
114
|
}
|
|
103
115
|
|
|
@@ -105,8 +117,7 @@ function Thumb({
|
|
|
105
117
|
const elemRef = React.useRef();
|
|
106
118
|
return React.createElement(React.Fragment, null, React.createElement("span", {
|
|
107
119
|
className: "dnb-slider__thumb",
|
|
108
|
-
style: style
|
|
109
|
-
ref: elemRef
|
|
120
|
+
style: style
|
|
110
121
|
}, React.createElement("input", _extends({
|
|
111
122
|
type: "range",
|
|
112
123
|
className: "dnb-slider__button-helper",
|
|
@@ -130,12 +141,14 @@ function Thumb({
|
|
|
130
141
|
type: "",
|
|
131
142
|
variant: "secondary",
|
|
132
143
|
disabled: disabled,
|
|
133
|
-
skeleton: skeleton
|
|
144
|
+
skeleton: skeleton,
|
|
145
|
+
innerRef: elemRef
|
|
134
146
|
}, thumbParams)), tooltip && React.createElement(Tooltip, {
|
|
135
147
|
key: `group-${currentIndex}`,
|
|
136
148
|
targetElement: elemRef,
|
|
137
149
|
animatePosition: shouldAnimate,
|
|
138
|
-
active: showTooltip || alwaysShowTooltip,
|
|
150
|
+
active: Boolean(showTooltip || alwaysShowTooltip),
|
|
151
|
+
showDelay: 1,
|
|
139
152
|
hideDelay: 300
|
|
140
153
|
}, number || value, shouldAnimate)));
|
|
141
154
|
}
|
|
@@ -23,8 +23,7 @@ export function SliderMainTrack({
|
|
|
23
23
|
onInit
|
|
24
24
|
} = allProps;
|
|
25
25
|
const {
|
|
26
|
-
|
|
27
|
-
onThumbMouseDownHandler,
|
|
26
|
+
onTrackMouseDownHandler,
|
|
28
27
|
removeEvents
|
|
29
28
|
} = useSliderEvents();
|
|
30
29
|
React.useEffect(() => {
|
|
@@ -47,10 +46,8 @@ export function SliderMainTrack({
|
|
|
47
46
|
};
|
|
48
47
|
}, []);
|
|
49
48
|
const trackParams = {
|
|
50
|
-
onTouchStart:
|
|
51
|
-
|
|
52
|
-
onMouseDown: onTrackMouseUpHandler,
|
|
53
|
-
onMouseDownCapture: onThumbMouseDownHandler
|
|
49
|
+
onTouchStart: onTrackMouseDownHandler,
|
|
50
|
+
onMouseDown: onTrackMouseDownHandler
|
|
54
51
|
};
|
|
55
52
|
return React.createElement("span", _extends({
|
|
56
53
|
id: id,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export declare function useSliderEvents(): {
|
|
3
|
-
onThumbMouseDownHandler: (event: React.SyntheticEvent) => void;
|
|
3
|
+
onThumbMouseDownHandler: (event: MouseEvent | TouchEvent | React.SyntheticEvent) => void;
|
|
4
4
|
onThumbMouseUpHandler: () => void;
|
|
5
|
-
|
|
5
|
+
onTrackMouseDownHandler: (event: MouseEvent | TouchEvent) => void;
|
|
6
6
|
onHelperChangeHandler: (event: React.FormEvent<HTMLInputElement>) => void;
|
|
7
7
|
onHelperFocusHandler: (event: React.FormEvent<HTMLInputElement>) => void;
|
|
8
8
|
removeEvents: () => void;
|
|
@@ -20,7 +20,8 @@ export function useSliderEvents() {
|
|
|
20
20
|
onDragEnd
|
|
21
21
|
} = allProps;
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const onTrackMouseDownHandler = event => {
|
|
24
|
+
onThumbMouseDownHandler(event);
|
|
24
25
|
const percent = calculatePercent(trackRef.current, event, isVertical);
|
|
25
26
|
emitChange(event, percentToValue(percent, min, max, isReverse));
|
|
26
27
|
setShouldAnimate(true);
|
|
@@ -108,7 +109,7 @@ export function useSliderEvents() {
|
|
|
108
109
|
return {
|
|
109
110
|
onThumbMouseDownHandler,
|
|
110
111
|
onThumbMouseUpHandler,
|
|
111
|
-
|
|
112
|
+
onTrackMouseDownHandler,
|
|
112
113
|
onHelperChangeHandler,
|
|
113
114
|
onHelperFocusHandler,
|
|
114
115
|
removeEvents
|
|
@@ -10,12 +10,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
10
10
|
import React from 'react';
|
|
11
11
|
import classnames from 'classnames';
|
|
12
12
|
import Context from '../../shared/Context';
|
|
13
|
-
import { makeUniqueId, validateDOMAttributes
|
|
13
|
+
import { makeUniqueId, validateDOMAttributes } from '../../shared/component-helper';
|
|
14
14
|
import { createSpacingClasses } from '../space/SpacingHelper';
|
|
15
|
-
import TooltipContainer from './TooltipContainer';
|
|
16
15
|
import TooltipWithEvents from './TooltipWithEvents';
|
|
17
|
-
import
|
|
18
|
-
import { defaultProps, getPropsFromTooltipProp, injectTooltipSemantic } from './TooltipHelpers';
|
|
16
|
+
import { defaultProps, getPropsFromTooltipProp, getRefElement, getTargetElement, injectTooltipSemantic } from './TooltipHelpers';
|
|
19
17
|
import { convertSnakeCaseProps } from '../../shared/helpers/withSnakeCaseProps';
|
|
20
18
|
|
|
21
19
|
function Tooltip(localProps) {
|
|
@@ -44,8 +42,14 @@ function Tooltip(localProps) {
|
|
|
44
42
|
} = props,
|
|
45
43
|
params = _objectWithoutProperties(props, _excluded);
|
|
46
44
|
|
|
45
|
+
const target = targetElement || targetSelector;
|
|
46
|
+
const [element, setElement] = React.useState();
|
|
47
47
|
const [internalId] = React.useState(() => props.id || makeUniqueId());
|
|
48
48
|
props.internalId = internalId;
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
const element = getTargetElement(getRefElement(target));
|
|
51
|
+
setElement(element);
|
|
52
|
+
}, [target]);
|
|
49
53
|
const classes = classnames('dnb-tooltip', createSpacingClasses(props), className, size === 'large' && 'dnb-tooltip--large');
|
|
50
54
|
|
|
51
55
|
const attributes = _objectSpread({
|
|
@@ -54,20 +58,14 @@ function Tooltip(localProps) {
|
|
|
54
58
|
|
|
55
59
|
validateDOMAttributes(localProps, attributes);
|
|
56
60
|
|
|
57
|
-
if (!
|
|
58
|
-
|
|
61
|
+
if (target && !element) {
|
|
62
|
+
return null;
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
return React.createElement(
|
|
62
|
-
target:
|
|
65
|
+
return React.createElement(TooltipWithEvents, _extends({
|
|
66
|
+
target: element,
|
|
63
67
|
attributes: attributes
|
|
64
|
-
}, props), props.children)
|
|
65
|
-
target: targetElement,
|
|
66
|
-
attributes: attributes
|
|
67
|
-
}, props), props.children) : targetSelector && React.createElement(TooltipPortal, _extends({
|
|
68
|
-
target: targetSelector,
|
|
69
|
-
attributes: attributes
|
|
70
|
-
}, props), props.children));
|
|
68
|
+
}, props), props.children);
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
export { injectTooltipSemantic };
|
|
@@ -7,7 +7,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
7
7
|
|
|
8
8
|
import React from 'react';
|
|
9
9
|
import { isTrue } from '../../shared/component-helper';
|
|
10
|
-
import { getOffsetLeft } from '../../shared/helpers';
|
|
10
|
+
import { getOffsetLeft, getOffsetTop } from '../../shared/helpers';
|
|
11
11
|
import classnames from 'classnames';
|
|
12
12
|
export default function TooltipContainer(props) {
|
|
13
13
|
const {
|
|
@@ -16,11 +16,16 @@ export default function TooltipContainer(props) {
|
|
|
16
16
|
attributes,
|
|
17
17
|
arrow,
|
|
18
18
|
position,
|
|
19
|
+
align,
|
|
20
|
+
group,
|
|
21
|
+
hideDelay,
|
|
19
22
|
animatePosition,
|
|
20
23
|
fixedPosition,
|
|
21
24
|
noAnimation,
|
|
25
|
+
skipPortal,
|
|
22
26
|
useHover,
|
|
23
|
-
children
|
|
27
|
+
children,
|
|
28
|
+
targetElement: target
|
|
24
29
|
} = props;
|
|
25
30
|
const [style, setStyle] = React.useState(null);
|
|
26
31
|
const [hover, setHover] = React.useState(false);
|
|
@@ -51,7 +56,7 @@ export default function TooltipContainer(props) {
|
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
try {
|
|
54
|
-
resizeObserver.current = new ResizeObserver(
|
|
59
|
+
resizeObserver.current = new ResizeObserver(() => {
|
|
55
60
|
clearTimeout(debounceTimeout.current);
|
|
56
61
|
debounceTimeout.current = setTimeout(() => forceRerender(getBodySize()), 100);
|
|
57
62
|
});
|
|
@@ -75,21 +80,27 @@ export default function TooltipContainer(props) {
|
|
|
75
80
|
|
|
76
81
|
return removePositionObserver;
|
|
77
82
|
}, [isActive]);
|
|
83
|
+
const offsetLeft = React.useRef(0);
|
|
84
|
+
const offsetTop = React.useRef(0);
|
|
78
85
|
React.useLayoutEffect(() => {
|
|
86
|
+
if (!isActive) {
|
|
87
|
+
if (group && wasActive) {
|
|
88
|
+
clearTimeout(debounceTimeout.current);
|
|
89
|
+
debounceTimeout.current = setTimeout(() => setStyle(null), hideDelay);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
79
95
|
const element = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current;
|
|
80
|
-
const {
|
|
81
|
-
targetElement: target,
|
|
82
|
-
align,
|
|
83
|
-
fixedPosition
|
|
84
|
-
} = props;
|
|
85
96
|
|
|
86
97
|
if (typeof window === 'undefined' || !element || !(target !== null && target !== void 0 && target.getBoundingClientRect)) {
|
|
87
98
|
return;
|
|
88
99
|
}
|
|
89
100
|
|
|
101
|
+
let alignOffset = 0;
|
|
90
102
|
const elementWidth = element.offsetWidth;
|
|
91
103
|
const elementHeight = element.offsetHeight;
|
|
92
|
-
let alignOffset = 0;
|
|
93
104
|
const rect = target.getBoundingClientRect();
|
|
94
105
|
const targetBodySize = {
|
|
95
106
|
width: target.offsetWidth,
|
|
@@ -101,13 +112,18 @@ export default function TooltipContainer(props) {
|
|
|
101
112
|
targetBodySize.height = rect.height;
|
|
102
113
|
}
|
|
103
114
|
|
|
115
|
+
if (skipPortal && (!offsetLeft.current || !offsetTop.current)) {
|
|
116
|
+
offsetLeft.current = getOffsetLeft(element) - offset.current;
|
|
117
|
+
offsetTop.current = getOffsetTop(element) - offset.current;
|
|
118
|
+
}
|
|
119
|
+
|
|
104
120
|
const scrollY = window.scrollY !== undefined ? window.scrollY : window.pageYOffset;
|
|
105
121
|
const scrollX = window.scrollX !== undefined ? window.scrollX : window.pageXOffset;
|
|
106
|
-
const top = (isTrue(fixedPosition) ? 0 : scrollY) + rect.top;
|
|
122
|
+
const top = (isTrue(fixedPosition) ? 0 : scrollY) + rect.top - offsetTop.current;
|
|
107
123
|
const useMouseWhen = targetBodySize.width > 400;
|
|
108
124
|
const mousePos = getOffsetLeft(target) + rect.left / 2 + (element ? element.offsetWidth : 0);
|
|
109
125
|
const widthBased = scrollX + rect.left;
|
|
110
|
-
const left = useMouseWhen && mousePos < targetBodySize.width ? mousePos : widthBased;
|
|
126
|
+
const left = (useMouseWhen && mousePos < targetBodySize.width ? mousePos : widthBased) - offsetLeft.current;
|
|
111
127
|
|
|
112
128
|
const style = _objectSpread({}, props.style);
|
|
113
129
|
|
|
@@ -154,9 +170,7 @@ export default function TooltipContainer(props) {
|
|
|
154
170
|
|
|
155
171
|
if (stylesFromPosition[position]) {
|
|
156
172
|
stylesFromPosition[position]();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (stylesFromArrow[arrow]) {
|
|
173
|
+
} else if (stylesFromArrow[arrow]) {
|
|
160
174
|
stylesFromArrow[arrow]();
|
|
161
175
|
}
|
|
162
176
|
|
|
@@ -174,10 +188,8 @@ export default function TooltipContainer(props) {
|
|
|
174
188
|
style.top = 0;
|
|
175
189
|
}
|
|
176
190
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
}, [isActive, arrow, position, children, renewStyles]);
|
|
191
|
+
setStyle(style);
|
|
192
|
+
}, [active, arrow, position, children, renewStyles]);
|
|
181
193
|
|
|
182
194
|
const handleMouseEnter = () => {
|
|
183
195
|
if (isTrue(active) && useHover !== false) {
|
|
@@ -191,12 +203,17 @@ export default function TooltipContainer(props) {
|
|
|
191
203
|
}
|
|
192
204
|
};
|
|
193
205
|
|
|
206
|
+
const handlePropagation = e => e.stopPropagation();
|
|
207
|
+
|
|
194
208
|
return React.createElement("span", _extends({
|
|
195
209
|
role: "tooltip",
|
|
196
|
-
"aria-hidden": true,
|
|
210
|
+
"aria-hidden": target ? true : undefined,
|
|
197
211
|
ref: elementRef,
|
|
198
212
|
onMouseEnter: handleMouseEnter,
|
|
199
|
-
onMouseLeave: handleMouseLeave
|
|
213
|
+
onMouseLeave: handleMouseLeave,
|
|
214
|
+
onMouseMove: handlePropagation,
|
|
215
|
+
onMouseDown: handlePropagation,
|
|
216
|
+
onTouchStart: handlePropagation
|
|
200
217
|
}, attributes, {
|
|
201
218
|
className: classnames(attributes === null || attributes === void 0 ? void 0 : attributes.className, isActive ? 'dnb-tooltip--active' : wasActive && 'dnb-tooltip--hide', isTrue(animatePosition) && 'dnb-tooltip--animate_position', isTrue(noAnimation) && 'dnb-tooltip--no-animation', isTrue(fixedPosition) && 'dnb-tooltip--fixed'),
|
|
202
219
|
style: _objectSpread(_objectSpread({}, style), attributes.style)
|
|
@@ -25,7 +25,7 @@ export declare const defaultProps: {
|
|
|
25
25
|
tooltip: any;
|
|
26
26
|
};
|
|
27
27
|
export declare function getTargetElement(target: HTMLElement): HTMLElement;
|
|
28
|
-
export declare function useHandleAria(targetElement:
|
|
28
|
+
export declare function useHandleAria(targetElement: HTMLElement, internalId: string): void;
|
|
29
29
|
export declare function getPropsFromTooltipProp(localProps: any): any;
|
|
30
30
|
export declare function getRefElement(target: React.RefObject<HTMLElement>): any;
|
|
31
31
|
export declare const isTouch: (type: string) => boolean;
|
|
@@ -34,14 +34,10 @@ export function getTargetElement(target) {
|
|
|
34
34
|
export function useHandleAria(targetElement, internalId) {
|
|
35
35
|
React.useEffect(() => {
|
|
36
36
|
try {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
'aria-describedby': elem.getAttribute('aria-describedby')
|
|
42
|
-
};
|
|
43
|
-
elem.setAttribute('aria-describedby', combineDescribedBy(existing, internalId));
|
|
44
|
-
}
|
|
37
|
+
const existing = {
|
|
38
|
+
'aria-describedby': targetElement.getAttribute('aria-describedby')
|
|
39
|
+
};
|
|
40
|
+
targetElement.setAttribute('aria-describedby', combineDescribedBy(existing, internalId));
|
|
45
41
|
} catch (e) {}
|
|
46
42
|
}, [targetElement, internalId]);
|
|
47
43
|
}
|
|
@@ -60,7 +56,7 @@ export function getRefElement(target) {
|
|
|
60
56
|
element = getRefElement(unknownTarget.current._ref);
|
|
61
57
|
}
|
|
62
58
|
|
|
63
|
-
if (Object.prototype.hasOwnProperty.call(element, 'current')) {
|
|
59
|
+
if (element && Object.prototype.hasOwnProperty.call(element, 'current')) {
|
|
64
60
|
element = element.current;
|
|
65
61
|
}
|
|
66
62
|
|
|
@@ -3,7 +3,6 @@ import React from 'react';
|
|
|
3
3
|
import ReactDOM from 'react-dom';
|
|
4
4
|
import { makeUniqueId, warn } from '../../shared/component-helper';
|
|
5
5
|
import TooltipContainer from './TooltipContainer';
|
|
6
|
-
import { getTargetElement } from './TooltipHelpers';
|
|
7
6
|
let tooltipPortal;
|
|
8
7
|
|
|
9
8
|
if (typeof globalThis !== 'undefined') {
|
|
@@ -16,7 +15,7 @@ if (typeof globalThis !== 'undefined') {
|
|
|
16
15
|
function TooltipPortal(props) {
|
|
17
16
|
const {
|
|
18
17
|
active,
|
|
19
|
-
|
|
18
|
+
targetElement,
|
|
20
19
|
hideDelay,
|
|
21
20
|
keepInDOM,
|
|
22
21
|
noAnimation,
|
|
@@ -24,40 +23,56 @@ function TooltipPortal(props) {
|
|
|
24
23
|
} = props;
|
|
25
24
|
const [isMounted, setIsMounted] = React.useState(false);
|
|
26
25
|
const [isActive, setIsActive] = React.useState(active);
|
|
27
|
-
const [
|
|
26
|
+
const [id] = React.useState(() => props.group || makeUniqueId());
|
|
28
27
|
const isInDOM = React.useRef(false);
|
|
29
28
|
const hasGroup = props.group;
|
|
30
29
|
|
|
31
|
-
if (tooltipPortal[group]) {
|
|
32
|
-
tooltipPortal[group].inDOM = isInDOM.current;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
30
|
const makePortal = () => {
|
|
36
|
-
if (!tooltipPortal[
|
|
37
|
-
tooltipPortal[
|
|
38
|
-
|
|
31
|
+
if (!tooltipPortal[id]) {
|
|
32
|
+
tooltipPortal[id] = {
|
|
33
|
+
count: 0,
|
|
34
|
+
node: hasGroup ? createGroupElement(id) : createRootElement()
|
|
39
35
|
};
|
|
40
36
|
}
|
|
41
37
|
};
|
|
42
38
|
|
|
43
|
-
const removeFromDOM =
|
|
44
|
-
if (
|
|
45
|
-
|
|
39
|
+
const removeFromDOM = hide => {
|
|
40
|
+
if (isActive && hide) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const ref = tooltipPortal[id];
|
|
45
|
+
|
|
46
|
+
if (ref !== null && ref !== void 0 && ref.node) {
|
|
47
|
+
ref.count--;
|
|
48
|
+
|
|
49
|
+
if (ref.count <= 0) {
|
|
50
|
+
if (hasGroup) {
|
|
51
|
+
ReactDOM.unmountComponentAtNode(ref.node);
|
|
52
|
+
createRootElement().removeChild(ref.node);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
delete tooltipPortal[id];
|
|
56
|
+
}
|
|
46
57
|
}
|
|
47
58
|
};
|
|
48
59
|
|
|
49
60
|
React.useEffect(() => {
|
|
50
|
-
var _tooltipPortal$
|
|
61
|
+
var _tooltipPortal$id, _tooltipPortal$id2;
|
|
51
62
|
|
|
52
63
|
setIsMounted(true);
|
|
53
|
-
clearTimeout((_tooltipPortal$
|
|
54
|
-
clearTimeout((_tooltipPortal$
|
|
64
|
+
clearTimeout((_tooltipPortal$id = tooltipPortal[id]) === null || _tooltipPortal$id === void 0 ? void 0 : _tooltipPortal$id.delayTimeout);
|
|
65
|
+
clearTimeout((_tooltipPortal$id2 = tooltipPortal[id]) === null || _tooltipPortal$id2 === void 0 ? void 0 : _tooltipPortal$id2.hiddenTimeout);
|
|
55
66
|
|
|
56
67
|
if (active) {
|
|
57
68
|
makePortal();
|
|
58
69
|
setIsActive(true);
|
|
59
70
|
isInDOM.current = true;
|
|
60
71
|
|
|
72
|
+
if (!isMounted) {
|
|
73
|
+
tooltipPortal[id].count++;
|
|
74
|
+
}
|
|
75
|
+
|
|
61
76
|
if (hasGroup) {
|
|
62
77
|
renderPortal(true);
|
|
63
78
|
}
|
|
@@ -72,19 +87,19 @@ function TooltipPortal(props) {
|
|
|
72
87
|
|
|
73
88
|
const delayHidden = () => {
|
|
74
89
|
isInDOM.current = false;
|
|
75
|
-
removeFromDOM();
|
|
90
|
+
removeFromDOM(true);
|
|
76
91
|
};
|
|
77
92
|
|
|
78
93
|
if (noAnimation || globalThis.IS_TEST) {
|
|
79
94
|
delayRender();
|
|
80
95
|
delayHidden();
|
|
81
|
-
} else if (tooltipPortal[
|
|
96
|
+
} else if (tooltipPortal[id]) {
|
|
82
97
|
const delay = parseFloat(String(hideDelay));
|
|
83
|
-
tooltipPortal[
|
|
84
|
-
tooltipPortal[
|
|
98
|
+
tooltipPortal[id].delayTimeout = setTimeout(delayRender, delay);
|
|
99
|
+
tooltipPortal[id].hiddenTimeout = setTimeout(delayHidden, delay + 300);
|
|
85
100
|
}
|
|
86
101
|
}
|
|
87
|
-
}, [children, active,
|
|
102
|
+
}, [children, active, id, hideDelay, noAnimation]);
|
|
88
103
|
React.useEffect(() => {
|
|
89
104
|
if (keepInDOM) {
|
|
90
105
|
makePortal();
|
|
@@ -94,13 +109,13 @@ function TooltipPortal(props) {
|
|
|
94
109
|
}, []);
|
|
95
110
|
|
|
96
111
|
const renderPortal = isActive => {
|
|
97
|
-
var _tooltipPortal$
|
|
112
|
+
var _tooltipPortal$id3;
|
|
98
113
|
|
|
99
|
-
const root = (_tooltipPortal$
|
|
114
|
+
const root = (_tooltipPortal$id3 = tooltipPortal[id]) === null || _tooltipPortal$id3 === void 0 ? void 0 : _tooltipPortal$id3.node;
|
|
100
115
|
|
|
101
116
|
if (root && hasGroup && isInDOM.current) {
|
|
102
117
|
ReactDOM.render(React.createElement(TooltipContainer, _extends({}, props, {
|
|
103
|
-
targetElement:
|
|
118
|
+
targetElement: targetElement,
|
|
104
119
|
active: isActive
|
|
105
120
|
})), root);
|
|
106
121
|
}
|
|
@@ -109,13 +124,13 @@ function TooltipPortal(props) {
|
|
|
109
124
|
};
|
|
110
125
|
|
|
111
126
|
if (!hasGroup) {
|
|
112
|
-
var _tooltipPortal$
|
|
127
|
+
var _tooltipPortal$id4;
|
|
113
128
|
|
|
114
|
-
const root = (_tooltipPortal$
|
|
129
|
+
const root = (_tooltipPortal$id4 = tooltipPortal[id]) === null || _tooltipPortal$id4 === void 0 ? void 0 : _tooltipPortal$id4.node;
|
|
115
130
|
|
|
116
131
|
if (root) {
|
|
117
132
|
return ReactDOM.createPortal(isInDOM.current || keepInDOM ? React.createElement(TooltipContainer, _extends({}, props, {
|
|
118
|
-
targetElement:
|
|
133
|
+
targetElement: targetElement,
|
|
119
134
|
active: isActive
|
|
120
135
|
}), children) : null, root);
|
|
121
136
|
}
|
|
@@ -131,14 +146,14 @@ const createGroupElement = id => {
|
|
|
131
146
|
const elem = document.createElement('div');
|
|
132
147
|
elem.classList.add('dnb-tooltip__group');
|
|
133
148
|
elem.setAttribute('id', id);
|
|
134
|
-
createRootElement(
|
|
149
|
+
createRootElement().appendChild(elem);
|
|
135
150
|
return elem;
|
|
136
151
|
} catch (e) {
|
|
137
152
|
warn(e);
|
|
138
153
|
}
|
|
139
154
|
};
|
|
140
155
|
|
|
141
|
-
const createRootElement = className => {
|
|
156
|
+
const createRootElement = (className = 'dnb-tooltip__portal') => {
|
|
142
157
|
try {
|
|
143
158
|
const element = document.querySelector(`.${className}`);
|
|
144
159
|
|