(element: Element, content: string | TooltipOptions)
| 27 | } |
| 28 | |
| 29 | function createTooltipFor(element: Element, content: string | TooltipOptions): HTMLElement { |
| 30 | const options: TooltipOptions = typeof content === 'string' |
| 31 | ? {label: content} |
| 32 | : content; |
| 33 | |
| 34 | // Ensure the element has an ID for the `for` attribute to link to |
| 35 | element.id ||= crypto.randomUUID(); |
| 36 | |
| 37 | const tooltipId = crypto.randomUUID(); |
| 38 | element.setAttribute('aria-labelledby', tooltipId); |
| 39 | |
| 40 | return ( |
| 41 | <tool-tip |
| 42 | id={tooltipId} |
| 43 | className="sr-only position-absolute" |
| 44 | for={element.id} |
| 45 | popover="manual" |
| 46 | data-direction={options.direction ?? 's'} |
| 47 | data-type={options.type ?? 'label'} |
| 48 | aria-hidden="true" |
| 49 | role="tooltip" |
| 50 | > |
| 51 | {options.label} |
| 52 | {options.shortcut && renderShortcut(options.shortcut)} |
| 53 | </tool-tip> |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | Align tooltip behavior with native |
no test coverage detected