Skip to content

Commit 1b8a3c9

Browse files
committed
* popover: add autoHide option to PopoverOptions and integrate hide functionality in Popover class
1 parent 5891e00 commit 1b8a3c9

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

lib/popover/src/types/popover-options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {Placement, Strategy, ShiftOptions, Derivable, VirtualElement, OffsetOptions} from '@floating-ui/dom';
1+
import type {Placement, Strategy, ShiftOptions, Derivable, VirtualElement, OffsetOptions, HideOptions} from '@floating-ui/dom';
22
import type {Selector, SizeSetting} from '@zui/core';
33
import type {PopoverPanelOptions} from './popover-panel-options';
44

@@ -40,6 +40,7 @@ export type PopoverOptions = Omit<PopoverPanelOptions, 'arrow' | 'arrowStyle' |
4040
flip?: boolean;
4141
shift?: boolean | ShiftOptions | Derivable<ShiftOptions>;
4242
arrow?: boolean | number;
43+
autoHide?: boolean | HideOptions;
4344
offset?: OffsetOptions;
4445
mask?: boolean;
4546
delay?: number;

lib/popover/src/vanilla/popover.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {arrow, computePosition, flip, shift, size, autoUpdate, offset, VirtualElement, ReferenceElement, ComputePositionConfig} from '@floating-ui/dom';
1+
import {arrow, computePosition, flip, shift, hide, size, autoUpdate, offset, VirtualElement, ReferenceElement, ComputePositionConfig} from '@floating-ui/dom';
22
import {Component, $, ComponentEvents, JSX, evalValue, toCssSize, nextGid, ComponentOptions, parseSize} from '@zui/core';
33
import {PopoverEvents, PopoverOptions, PopoverPanelOptions, PopoverSide} from '../types';
44
import {PopoverPanel} from './popover-panel';
@@ -516,7 +516,7 @@ export class Popover<O extends PopoverOptions = PopoverOptions, E extends Compon
516516
protected _getLayoutOptions(): [trigger: ReferenceElement, element: HTMLElement, options: Partial<ComputePositionConfig>] {
517517
const trigger = this.getTriggerElement();
518518
const element = this._targetElement!;
519-
const {placement: placementSetting, flip: isFlip, limitSize, shift: shiftSetting, offset: offsetSetting, arrow: arrowSetting, strategy, maxHeight: maxHeightSetting, maxWidth: maxWidthSetting} = this.options;
519+
const {placement: placementSetting, flip: isFlip, limitSize, shift: shiftSetting, offset: offsetSetting, arrow: arrowSetting, strategy, maxHeight: maxHeightSetting, maxWidth: maxWidthSetting, autoHide} = this.options;
520520
const arrowElement = arrowSetting ? element.querySelector('.arrow') : null;
521521
const arrowSize = arrowElement ? (typeof arrowSetting === 'number' ? arrowSetting : 5) : 0;
522522
const getOffsetSetting = () => {
@@ -555,6 +555,7 @@ export class Popover<O extends PopoverOptions = PopoverOptions, E extends Compon
555555
});
556556
},
557557
}) : null,
558+
autoHide ? hide(typeof autoHide === 'object' ? autoHide : undefined) : null,
558559
].filter(Boolean),
559560
}];
560561
}

0 commit comments

Comments
 (0)