@moneyforward/mfui-components 3.23.0 → 3.24.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.
@@ -42,5 +42,5 @@ export declare const Tooltip: import("react").ForwardRefExoticComponent<{
42
42
  disabled?: boolean;
43
43
  hideFromScreenReader?: boolean;
44
44
  maxWidth?: import("react").CSSProperties["maxWidth"];
45
- contentProps?: Pick<import("react").ComponentPropsWithoutRef<"div">, "className">;
45
+ contentProps?: Pick<import("react").ComponentPropsWithoutRef<"div">, "className" | "id">;
46
46
  } & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref">, "disabled" | "content"> & import("react").RefAttributes<HTMLDivElement>>;
@@ -48,7 +48,10 @@ export const Tooltip = forwardRef(({ children, open, onOpenStateChanged, content
48
48
  const rootRef = useRef(null);
49
49
  const arrowRef = useRef(null);
50
50
  const tooltipRef = useRef(null);
51
- const tooltipId = useId();
51
+ const generatedId = useId();
52
+ // Allow consumers to control the content id so an external element (e.g. a form field)
53
+ // can reference the single accessible copy of the content via its own aria-describedby.
54
+ const tooltipId = contentProps?.id ?? generatedId;
52
55
  // Use automatic target resolution matching Portal.tsx pattern
53
56
  // Resolution order: explicit prop → parent context → document.body fallback
54
57
  const targetElement = useAutomaticTargetDomNode(targetDOMNode, rootRef.current);
@@ -84,7 +84,8 @@ export type TooltipProps = {
84
84
  * will have `aria-hidden="true"`.
85
85
  *
86
86
  * Use this when the tooltip content is redundant with the trigger's accessible name
87
- * (e.g., showing the full text of a truncated label), to avoid double announcement.
87
+ * (e.g., showing the full text of a truncated label, as in the `Breadcrumbs` component),
88
+ * to avoid double announcement.
88
89
  *
89
90
  * @default false
90
91
  */
@@ -103,6 +104,11 @@ export type TooltipProps = {
103
104
  *
104
105
  * @property className - The class name for the tooltip content element (not the root wrapper).
105
106
  *
107
+ * @property id - The id of the tooltip content element. When provided, it overrides the
108
+ * auto-generated id used internally. Provide this when an external element (e.g. a form
109
+ * field) needs to reference the tooltip content via its own `aria-describedby`, so the
110
+ * single accessible copy of the content can be shared instead of duplicated.
111
+ *
106
112
  * @example
107
113
  * ```tsx
108
114
  * // Applies custom styling to the tooltip content
@@ -121,8 +127,16 @@ export type TooltipProps = {
121
127
  * >
122
128
  * <Button>Hover me</Button>
123
129
  * </Tooltip>
130
+ *
131
+ * // Share the tooltip content with an external element via a known id.
132
+ * // Useful for a non-interactive help icon describing a separate form field.
133
+ * const helpId = useId();
134
+ * <Tooltip content="Help text" contentProps={{ id: helpId }} trigger="hover">
135
+ * <Info aria-hidden />
136
+ * </Tooltip>
137
+ * <TextBox aria-describedby={helpId} />
124
138
  * ```
125
139
  */
126
- contentProps?: Pick<ComponentPropsWithoutRef<'div'>, 'className'>;
140
+ contentProps?: Pick<ComponentPropsWithoutRef<'div'>, 'className' | 'id'>;
127
141
  } & Omit<ComponentPropsWithoutRef<'span'>, 'content' | 'disabled'>;
128
142
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneyforward/mfui-components",
3
- "version": "3.23.0",
3
+ "version": "3.24.0",
4
4
  "description": "React UI Component Library for all Money Forward products",
5
5
  "repository": {
6
6
  "type": "git",