@lumx/react 3.18.2-alpha.4 → 3.19.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/index.js
CHANGED
|
@@ -7229,26 +7229,28 @@ const useTooltipContext = () => React__default.useContext(TooltipContext);
|
|
|
7229
7229
|
|
|
7230
7230
|
/**
|
|
7231
7231
|
* Compute a tooltip label based on a label element `innerText` if the text overflows.
|
|
7232
|
-
*
|
|
7233
|
-
* Warning: only works on first render, does not update on label element resize.
|
|
7232
|
+
* Updates dynamically on content changes (but not on resize!)
|
|
7234
7233
|
*/
|
|
7235
|
-
const useOverflowTooltipLabel =
|
|
7234
|
+
const useOverflowTooltipLabel = content => {
|
|
7236
7235
|
const parentTooltip = useTooltipContext();
|
|
7237
7236
|
const [tooltipLabel, setTooltipLabel] = React__default.useState(undefined);
|
|
7238
|
-
const
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
|
|
7244
|
-
|
|
7245
|
-
//
|
|
7246
|
-
|
|
7237
|
+
const [labelElement, setLabelElement] = React__default.useState(null);
|
|
7238
|
+
React__default.useLayoutEffect(() => {
|
|
7239
|
+
if (
|
|
7240
|
+
// Not inside a tooltip
|
|
7241
|
+
!parentTooltip && labelElement &&
|
|
7242
|
+
// Not inside a visually hidden
|
|
7243
|
+
!(labelElement !== null && labelElement !== void 0 && labelElement.closest(`.${VISUALLY_HIDDEN}`)) &&
|
|
7244
|
+
// Text overflows
|
|
7245
|
+
labelElement.offsetWidth < labelElement.scrollWidth) {
|
|
7246
|
+
// Set tooltip label
|
|
7247
7247
|
setTooltipLabel(labelElement.innerText);
|
|
7248
|
+
} else {
|
|
7249
|
+
setTooltipLabel(undefined);
|
|
7248
7250
|
}
|
|
7249
|
-
}, [parentTooltip]);
|
|
7251
|
+
}, [labelElement, parentTooltip, content]);
|
|
7250
7252
|
return {
|
|
7251
|
-
labelRef,
|
|
7253
|
+
labelRef: setLabelElement,
|
|
7252
7254
|
tooltipLabel
|
|
7253
7255
|
};
|
|
7254
7256
|
};
|
|
@@ -7329,7 +7331,7 @@ const Text = forwardRef((props, ref) => {
|
|
|
7329
7331
|
const {
|
|
7330
7332
|
tooltipLabel,
|
|
7331
7333
|
labelRef
|
|
7332
|
-
} = useOverflowTooltipLabel();
|
|
7334
|
+
} = useOverflowTooltipLabel(children);
|
|
7333
7335
|
return /*#__PURE__*/React__default.createElement(Component, _extends({
|
|
7334
7336
|
ref: useMergeRefs(ref, labelRef),
|
|
7335
7337
|
className: classNames(className, handleBasicClasses({
|
|
@@ -9371,7 +9373,7 @@ const NavigationItem = Object.assign(forwardRefPolymorphic((props, ref) => {
|
|
|
9371
9373
|
const {
|
|
9372
9374
|
tooltipLabel,
|
|
9373
9375
|
labelRef
|
|
9374
|
-
} = useOverflowTooltipLabel();
|
|
9376
|
+
} = useOverflowTooltipLabel(label);
|
|
9375
9377
|
const buttonProps = Element === 'button' ? {
|
|
9376
9378
|
type: 'button'
|
|
9377
9379
|
} : {};
|