diff --git a/src/createTippy.ts b/src/createTippy.ts index c9d3d4a5..ef526c64 100644 --- a/src/createTippy.ts +++ b/src/createTippy.ts @@ -313,9 +313,9 @@ export default function createTippy( // Clicked on the event listeners target if ( - normalizeToArray(instance.props.triggerTarget || reference).indexOf( - actualTarget as Element - ) !== -1 + normalizeToArray(instance.props.triggerTarget || reference).some((el) => + actualContains(el, actualTarget as Element) + ) ) { if (currentInput.isTouch) { return; diff --git a/test/integration/props.test.js b/test/integration/props.test.js index 05d4bffd..7d8e2e78 100644 --- a/test/integration/props.test.js +++ b/test/integration/props.test.js @@ -1220,6 +1220,24 @@ describe('trigger', () => { expect(instance.state.isVisible).toBe(false); }); + + it('toggles on repeated clicks with inner element target', () => { + const inner = h(); + const outer = h(); + outer.appendChild(inner); + + const instance = tippy(outer, {trigger: 'click'}); + + fireEvent.mouseDown(inner, {bubbles: true}); + fireEvent.click(inner, {bubbles: true}); + + expect(instance.state.isVisible).toBe(true); + + fireEvent.mouseDown(inner, {bubbles: true}); + fireEvent.click(inner, {bubbles: true}); + + expect(instance.state.isVisible).toBe(false); + }); }); describe('click focus', () => {