@lumx/react 3.9.2-alpha.5 → 3.9.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/index.d.ts +2 -0
- package/index.js +36 -23
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/tooltip/Tooltip.test.tsx +160 -61
- package/src/components/tooltip/Tooltip.tsx +15 -4
- package/src/components/tooltip/useInjectTooltipRef.tsx +28 -22
package/index.d.ts
CHANGED
|
@@ -2878,6 +2878,8 @@ interface TooltipProps extends GenericProps, HasCloseMode {
|
|
|
2878
2878
|
label?: string | null | false;
|
|
2879
2879
|
/** Placement of the tooltip relative to the anchor. */
|
|
2880
2880
|
placement?: TooltipPlacement;
|
|
2881
|
+
/** Choose how the tooltip text should link to the anchor */
|
|
2882
|
+
ariaLinkMode?: 'aria-describedby' | 'aria-labelledby';
|
|
2881
2883
|
}
|
|
2882
2884
|
/**
|
|
2883
2885
|
* Tooltip component.
|
package/index.js
CHANGED
|
@@ -13913,17 +13913,18 @@ Toolbar.defaultProps = DEFAULT_PROPS$10;
|
|
|
13913
13913
|
* Add ref and ARIA attribute(s) in tooltip children or wrapped children.
|
|
13914
13914
|
* Button, IconButton, Icon and React HTML elements don't need to be wrapped but any other kind of children (array, fragment, custom components)
|
|
13915
13915
|
* will be wrapped in a <span>.
|
|
13916
|
-
*
|
|
13917
|
-
* @param children Original tooltip anchor.
|
|
13918
|
-
* @param setAnchorElement Set tooltip anchor element.
|
|
13919
|
-
* @param isOpen Whether the tooltip is open or not.
|
|
13920
|
-
* @param id Tooltip id.
|
|
13921
|
-
* @param label Tooltip label.
|
|
13922
|
-
* @return tooltip anchor.
|
|
13923
13916
|
*/
|
|
13924
|
-
const useInjectTooltipRef =
|
|
13925
|
-
|
|
13926
|
-
|
|
13917
|
+
const useInjectTooltipRef = options => {
|
|
13918
|
+
const {
|
|
13919
|
+
children,
|
|
13920
|
+
setAnchorElement,
|
|
13921
|
+
isMounted,
|
|
13922
|
+
id,
|
|
13923
|
+
label,
|
|
13924
|
+
ariaLinkMode
|
|
13925
|
+
} = options;
|
|
13926
|
+
// Only add link when mounted
|
|
13927
|
+
const linkId = isMounted ? id : undefined;
|
|
13927
13928
|
return useMemo(() => {
|
|
13928
13929
|
if (!label) return children;
|
|
13929
13930
|
|
|
@@ -13934,18 +13935,21 @@ const useInjectTooltipRef = (children, setAnchorElement, isOpen, id, label) => {
|
|
|
13934
13935
|
ref
|
|
13935
13936
|
});
|
|
13936
13937
|
|
|
13937
|
-
//
|
|
13938
|
-
if (label !== props['aria-label']
|
|
13939
|
-
props[
|
|
13938
|
+
// Do not add label/description if the tooltip label is already in aria-label
|
|
13939
|
+
if (linkId && label !== props['aria-label']) {
|
|
13940
|
+
if (props[ariaLinkMode]) props[ariaLinkMode] += ' ';else props[ariaLinkMode] = '';
|
|
13941
|
+
props[ariaLinkMode] += linkId;
|
|
13940
13942
|
}
|
|
13941
13943
|
return /*#__PURE__*/cloneElement(children, props);
|
|
13942
13944
|
}
|
|
13943
|
-
|
|
13945
|
+
const aria = linkId ? {
|
|
13946
|
+
[ariaLinkMode]: linkId
|
|
13947
|
+
} : undefined;
|
|
13948
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
13944
13949
|
className: "lumx-tooltip-anchor-wrapper",
|
|
13945
|
-
ref: setAnchorElement
|
|
13946
|
-
|
|
13947
|
-
|
|
13948
|
-
}, [children, setAnchorElement, describedBy, label]);
|
|
13950
|
+
ref: setAnchorElement
|
|
13951
|
+
}, aria), children);
|
|
13952
|
+
}, [label, children, setAnchorElement, linkId, ariaLinkMode]);
|
|
13949
13953
|
};
|
|
13950
13954
|
|
|
13951
13955
|
/** Return true if the browser does not support pointer hover */
|
|
@@ -14088,7 +14092,7 @@ function useTooltipOpen(delay, anchorElement) {
|
|
|
14088
14092
|
};
|
|
14089
14093
|
}
|
|
14090
14094
|
|
|
14091
|
-
const _excluded$1q = ["label", "children", "className", "delay", "placement", "forceOpen", "closeMode"];
|
|
14095
|
+
const _excluded$1q = ["label", "children", "className", "delay", "placement", "forceOpen", "closeMode", "ariaLinkMode"];
|
|
14092
14096
|
|
|
14093
14097
|
/** Position of the tooltip relative to the anchor element. */
|
|
14094
14098
|
|
|
@@ -14111,7 +14115,8 @@ const CLASSNAME$1h = getRootClassName(COMPONENT_NAME$1k);
|
|
|
14111
14115
|
*/
|
|
14112
14116
|
const DEFAULT_PROPS$11 = {
|
|
14113
14117
|
placement: Placement.BOTTOM,
|
|
14114
|
-
closeMode: 'unmount'
|
|
14118
|
+
closeMode: 'unmount',
|
|
14119
|
+
ariaLinkMode: 'aria-describedby'
|
|
14115
14120
|
};
|
|
14116
14121
|
|
|
14117
14122
|
/**
|
|
@@ -14135,7 +14140,8 @@ const Tooltip = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
14135
14140
|
delay,
|
|
14136
14141
|
placement,
|
|
14137
14142
|
forceOpen,
|
|
14138
|
-
closeMode
|
|
14143
|
+
closeMode,
|
|
14144
|
+
ariaLinkMode
|
|
14139
14145
|
} = props,
|
|
14140
14146
|
forwardedProps = _objectWithoutProperties(props, _excluded$1q);
|
|
14141
14147
|
// Disable in SSR.
|
|
@@ -14163,8 +14169,15 @@ const Tooltip = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
14163
14169
|
onPopperMount
|
|
14164
14170
|
} = useTooltipOpen(delay, anchorElement);
|
|
14165
14171
|
const isOpen = (isActivated || forceOpen) && !!label;
|
|
14166
|
-
const isMounted = isOpen || closeMode === 'hide';
|
|
14167
|
-
const wrappedChildren = useInjectTooltipRef(
|
|
14172
|
+
const isMounted = !!label && (isOpen || closeMode === 'hide');
|
|
14173
|
+
const wrappedChildren = useInjectTooltipRef({
|
|
14174
|
+
children,
|
|
14175
|
+
setAnchorElement,
|
|
14176
|
+
isMounted,
|
|
14177
|
+
id,
|
|
14178
|
+
label,
|
|
14179
|
+
ariaLinkMode: ariaLinkMode
|
|
14180
|
+
});
|
|
14168
14181
|
const labelLines = label ? label.split('\n') : [];
|
|
14169
14182
|
const tooltipRef = useMergeRefs(ref, setPopperElement, onPopperMount);
|
|
14170
14183
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TooltipContextProvider, null, wrappedChildren), isMounted && /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement("div", _extends({
|