|
1 | 1 | import {arrow, computePosition, flip, shift, size, autoUpdate, offset, VirtualElement, ReferenceElement, ComputePositionConfig} from '@floating-ui/dom'; |
2 | | -import {Component, $, ComponentEvents, JSX, evalValue, toCssSize, nextGid} from '@zui/core'; |
| 2 | +import {Component, $, ComponentEvents, JSX, evalValue, toCssSize, nextGid, ComponentOptions} from '@zui/core'; |
3 | 3 | import {PopoverEvents, PopoverOptions, PopoverPanelOptions, PopoverSide} from '../types'; |
4 | 4 | import {PopoverPanel} from './popover-panel'; |
5 | 5 | import {isElementDetached} from '@zui/core/src/dom'; |
@@ -65,6 +65,8 @@ export class Popover<O extends PopoverOptions = PopoverOptions, E extends Compon |
65 | 65 |
|
66 | 66 | protected declare _zIndex: number; |
67 | 67 |
|
| 68 | + protected _lastTriggerAttr = ''; |
| 69 | + |
68 | 70 | get shown() { |
69 | 71 | return this._shown; |
70 | 72 | } |
@@ -97,10 +99,19 @@ export class Popover<O extends PopoverOptions = PopoverOptions, E extends Compon |
97 | 99 | const {namespace} = this; |
98 | 100 | if (trigger) { |
99 | 101 | const setOptionsFromTrigger = () => { |
| 102 | + const toggleOptions = $triggerElement.attr(`zui-toggle-${this.constructor.ZUI}`) ?? ''; |
| 103 | + if (toggleOptions && this._lastTriggerAttr === toggleOptions) { |
| 104 | + return; |
| 105 | + } |
| 106 | + this._lastTriggerAttr = toggleOptions; |
100 | 107 | let options = $triggerElement.dataset(); |
101 | | - const toggleOptions = $triggerElement.attr(`zui-toggle-${this.constructor.ZUI}`); |
102 | 108 | if (toggleOptions) { |
103 | | - options = $.extend(options, evalValue(toggleOptions)); |
| 109 | + const newOptions = evalValue(toggleOptions) as ComponentOptions<O>; |
| 110 | + let extraOptions = newOptions.$options; |
| 111 | + if (typeof extraOptions === 'function') { |
| 112 | + extraOptions = extraOptions.call(this, this.element, newOptions); |
| 113 | + } |
| 114 | + options = $.extend(options, newOptions, extraOptions || {}); |
104 | 115 | } |
105 | 116 | this.setOptions(options as Partial<O>); |
106 | 117 | }; |
|
0 commit comments