import { type ComponentPublicInstance, type ComputedRef, type MaybeRefOrGetter, type Ref } from "vue"; /** A template ref that may point to an element or a Vue/Kendo component. */ export type PopupMenuElementRef = Ref; export type PopupMenuTriggerMode = "button" | "row"; export type PopupMenuOffset = { left: number; top: number; }; /** Offset-positioning options for a Popup with a dynamically changing trigger. */ export type PopupMenuAnchorOptions = { /** Scrollable/clipping container used for out-of-view dismissal. */ clipRoot?: MaybeRefOrGetter; /** Closes the menu after its trigger leaves the clipping container. */ hideWhenAnchorClipped?: boolean; /** Intersection ratio required to keep the anchor considered visible. Defaults to `0.5`. */ intersectionThreshold?: number | number[]; /** Overrides the trigger rect for pointer-positioned menus. */ getRect?: () => DOMRect | null; }; /** Why the popup was closed, including the focus policy for mouse paths. */ export type PopupMenuCloseReason = /** Keyboard-driven menu selection (Enter/Space on a menu item); restores the configured focus target. */ "keyboard" /** Escape key; restores the configured focus target, then `escapeFocusTarget`, then the trigger. */ | "escape" /** Pointer menu selection; restores focus to the trigger. */ | "mouse-selection" /** Pointer interaction outside the menu; leaves browser focus unchanged. */ | "outside-click" /** Interaction with the open trigger; leaves browser focus unchanged. */ | "trigger-click" /** Trigger left its clipping area; closes without scrolling it back into view. */ | "anchor-hidden" /** No close has been requested yet. */ | null; export type PopupMenuCloseTrigger = Exclude; /** Minimal event shape emitted by Kendo Menu `@select`. */ export type KendoMenuSelectEvent = { item?: TItem; event?: { type?: string; } | null; }; /** Options for configuring {@link usePopupMenu}. */ export type UsePopupMenuOptions = { /** Reactive flag reflecting whether the popup menu is currently open. */ isOpen: Ref; /** Ref to the popup menu element or component. Used for outside-click detection. */ menuRef: PopupMenuElementRef; /** Ref to the trigger button element or component. Ignored by outside-click detection. */ triggerRef: PopupMenuElementRef; /** Called to open the popup menu. Kendo passes its event args as a rest tuple. */ requestShow: (...args: unknown[]) => void; /** Called to close the popup menu. Kendo passes its event args as a rest tuple. */ requestHide: (...args: unknown[]) => void; /** * Optional target to focus after a keyboard-driven close. * Supports ordinary elements and Vue/Kendo components exposing `$el`. */ focusTargetRef?: PopupMenuElementRef; /** * Resolves the focus target when it is virtualized or dynamically rendered. * Takes precedence over `focusTargetRef`. */ resolveFocusTarget?: () => HTMLElement | null; /** * Resolves a fallback focus target for Escape closes when no `focusTargetRef`/ * `resolveFocusTarget` is configured, e.g. the trigger's containing grid row so * keyboard users land back in row navigation instead of on the trigger button. * Only consulted for `triggerMode: "button"`; row triggers already restore to * themselves. Takes effect only for Escape, not keyboard menu selection. * Takes precedence over `escapeFocusContainerSelector`. */ escapeFocusTarget?: () => HTMLElement | null; /** * CSS selector for the closest ancestor of the trigger (or, if the menu was * never opened, of `document.activeElement`) to focus on Escape. Sugar over * `escapeFocusTarget` for the common "collapse back into the row" case. * Defaults to `".k-table-row"` for `triggerMode: "button"`; harmless to leave * at its default for non-grid button triggers since a missing ancestor simply * falls through to focusing the trigger. Ignored when `escapeFocusTarget` is set. */ escapeFocusContainerSelector?: string; /** * CSS selector used to find the first focusable menu item after open. * Defaults to `".k-menu-item:not(.k-disabled)"` for Kendo Menu. */ menuItemSelector?: string; /** * Keeps `aria-expanded` in sync with `isOpen` on the resolved `triggerRef`. * Defaults to `true`. The consumer is always responsible for the static * `aria-haspopup="menu"` and baseline `aria-expanded="false"` attributes. */ manageMenuTriggerAria?: boolean; /** Applies an accessible name to the rendered `role="menubar"` when provided. */ menuLabel?: MaybeRefOrGetter; /** * Declares whether `triggerRef` is a button or a `tr.k-table-row`. Required so * misrouted refs (e.g. a button-mode ref that resolves to a row) are never * silently managed. */ triggerMode: PopupMenuTriggerMode; /** Enables offset positioning and lifecycle tracking for a dynamic trigger. */ anchor?: PopupMenuAnchorOptions | true; }; /** Functions returned by {@link usePopupMenu} for the action menu. */ export type UsePopupMenuReturn = { /** Opens the menu, or closes it when it is already open. */ handleActionButtonClick: (...args: unknown[]) => void; /** * Handles keyboard input on the action button. Enter and Space open or close * the menu. Escape closes an open menu or moves focus to the configured target. */ handleActionButtonKeydown: (...args: unknown[]) => void; /** Closes the menu when Escape is pressed while using the menu. */ handleActionMenuEscape: (event: KeyboardEvent) => void; /** * Closes the menu after an item is chosen, then runs the optional action * provided by the consuming component. */ handleMenuSelect: (event: KendoMenuSelectEvent, onAction?: (event: KendoMenuSelectEvent) => void) => void; /** * Restores focus after the popup closes. Keyboard actions prefer the * configured focus target; mouse menu selections return focus to the trigger. */ handlePopupClose: () => void; /** Bind to Kendo Popup's `offset` prop when `anchor` is enabled. */ offset: ComputedRef; }; /** * Composable for accessible Kendo Popup + Menu action-menu interactions. * * It manages toggling, menu-item focus, selection modality, and contextual * focus restoration. The consuming component keeps ownership of menu state * and business-specific actions. * * @param options - Parent-owned popup state, refs, and focus configuration. * @returns Template event handlers for the action trigger, Kendo Menu, and Popup. */ export declare const usePopupMenu: (options: UsePopupMenuOptions) => UsePopupMenuReturn;