( content: string | TooltipOptions, element: Element, )
| 74 | @example return <div>{tooltipped('Does something', <button type="button">...</button>)}</div>; |
| 75 | */ |
| 76 | export function tooltipped( |
| 77 | content: string | TooltipOptions, |
| 78 | element: Element, |
| 79 | ): Element { |
| 80 | const tooltip = createTooltipFor(element, content); |
| 81 | element.append(tooltip); |
| 82 | |
| 83 | queueMicrotask(() => { |
| 84 | // TODO: Replace with https://github.com/sindresorhus/ts-extras/issues/75 |
| 85 | if (!element.isConnected) { |
| 86 | throw new Error('Element must be attached to the document before the tooltip'); |
| 87 | } |
| 88 | |
| 89 | attachToDocument(tooltip); |
| 90 | }); |
| 91 | |
| 92 | return element; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | Attaches a tooltip to an existing element. Don't use this with JSX. |
no test coverage detected