An open source design system that's fully customizable and agent ready
TypeScript
fix: Omit the popover source when the trigger is not an HTML element (#7227)
Jeongseok Kang3f45fc2f64ee
diff --git a/.changeset/tooltip-svg-trigger-opens.md b/.changeset/tooltip-svg-trigger-opens.mdnew file mode 100644index 0000000000..e121f616ff--- /dev/null+++ b/.changeset/tooltip-svg-trigger-opens.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Tooltip: an icon-only trigger now opens instead of throwing. The layer passed its trigger to `showPopover` as the invoker `source`, which the Popover API declares as an `HTMLElement`; a caller-rendered icon is an `SVGElement`, whose dictionary conversion throws before the popover opens, so the hint never appeared. An icon trigger now reaches `showPopover` without a source — positioning is unchanged, since the layer is anchored by its anchor-name pair, and only the invoker's focus order is given up.++@rapsealkdiff --git a/packages/core/src/Layer/useLayer.tsx b/packages/core/src/Layer/useLayer.tsxindex 243877d66f..a68c0ec8e6 100644--- a/packages/core/src/Layer/useLayer.tsx+++ b/packages/core/src/Layer/useLayer.tsx@@ -762,7 +762,16 @@ function useLayerImplementation(// hosted away from its trigger then still takes its sequential focus// order (and its popover nesting) from the trigger rather than from// its own DOM position. Browsers without the option ignore it.- popover.showPopover({source: triggerRef.current ?? undefined});+ // `source` is declared as an `HTMLElement`. A caller-rendered icon+ // trigger is an `SVGElement`, whose dictionary conversion throws+ // before the popover opens. Omitting the option for it still anchors+ // the layer, because positioning reads the anchor-name pair, and only+ // gives up the invoker's focus order.+ const trigger =+ triggerRef.current instanceof HTMLElement+ ? triggerRef.current+ : undefined;+ popover.showPopover({source: trigger});});} else {popover.style.display = 'block';diff --git a/packages/core/src/Tooltip/Tooltip.test.tsx b/packages/core/src/Tooltip/Tooltip.test.tsxindex c98b5f4375..ac584dac85 100644--- a/packages/core/src/Tooltip/Tooltip.test.tsx+++ b/packages/core/src/Tooltip/Tooltip.test.tsx@@ -183,6 +183,37 @@ describe('Tooltip', () => {});});+ describe('icon-only trigger', () => {+ // A rendered icon is an SVGElement, and ShowPopoverOptions.source is+ // declared as an HTMLElement. Handing the icon to showPopover throws+ // during dictionary conversion, before the popover opens, so the hint+ // never appeared. (#7226)+ it('opens an icon trigger without passing an SVGElement as the source', async () => {+ const showSpy = vi.mocked(HTMLElement.prototype.showPopover);+ showSpy.mockClear();++ render(+ <Tooltip content="Shared memory" isDefaultOpen>+ <svg data-testid="icon" aria-hidden="true" />+ </Tooltip>,+ );++ await waitFor(() => {+ expect(showSpy).toHaveBeenCalled();+ });++ const [options] = showSpy.mock.calls[0];+ // Compared as a boolean on purpose: a plain `toBeUndefined` failure makes+ // the diff printer walk the SVGElement, which it cannot inspect.+ expect(options?.source === undefined).toBe(true);++ // The icon is still the trigger the ARIA tooltip pattern is wired to.+ expect(screen.getByTestId('icon').getAttribute('aria-describedby')).toBe(+ screen.getByRole('tooltip', {hidden: true}).id,+ );+ });+ });+describe('WCAG 1.4.13 — content on hover or focus', () => {it('dismisses on Escape while visible (dismissible)', async () => {const onOpenChange = vi.fn();