UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

1 lines 1.52 kB
{"version":3,"file":"hoverOnlyPress.mjs","names":[],"sources":["../../../src/base-ui/Popover/hoverOnlyPress.ts"],"sourcesContent":["/**\n * Base UI Popover.Trigger always wires useClick. With openOnHover, a press while\n * the popup is hover-open can re-open with reason `trigger-press` (stickIfOpen),\n * which disables mouseleave dismiss. Hover-only triggers must cancel press-driven\n * opens so antd-compatible `trigger=\"hover\"` keeps hover close semantics.\n */\nexport function shouldCancelHoverOnlyPressOpen(\n openOnClick: boolean,\n nextOpen: boolean,\n reason: string | undefined,\n): boolean {\n return !openOnClick && nextOpen && reason === 'trigger-press';\n}\n\n/**\n * Stamped on a grouped trigger that only opens on hover. The group arbitrates\n * open changes for every member from one handler, and the event only carries the\n * trigger element — without this it cannot tell which member the press belongs to\n * and would judge it by whichever member happens to be active.\n */\nexport const HOVER_ONLY_TRIGGER_ATTR = 'data-hover-only-trigger';\n\nexport function isHoverOnlyTriggerElement(trigger: unknown): boolean | null {\n if (typeof Element === 'undefined' || !(trigger instanceof Element)) return null;\n\n return trigger.hasAttribute(HOVER_ONLY_TRIGGER_ATTR);\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,+BACd,aACA,UACA,QACS;CACT,OAAO,CAAC,eAAe,YAAY,WAAW;AAChD;;;;;;;AAQA,MAAa,0BAA0B;AAEvC,SAAgB,0BAA0B,SAAkC;CAC1E,IAAI,OAAO,YAAY,eAAe,EAAE,mBAAmB,UAAU,OAAO;CAE5E,OAAO,QAAQ,aAAa,uBAAuB;AACrD"}