Skip to content

Commit

Permalink
* popover: refactor with component toggle config.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Jul 14, 2024
1 parent 128cf04 commit 79e2e7a
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lib/popover/src/vanilla/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,24 @@ export class Popover<O extends PopoverOptions = PopoverOptions, E extends Compon
}
}

$(document).on(`click${Popover.NAMESPACE} mouseenter${Popover.NAMESPACE}`, TOGGLE_SELECTOR, (event: MouseEvent) => {
const $toggleBtn = $(event.currentTarget as HTMLElement);
if ($toggleBtn.length && !$toggleBtn.data(Popover.KEY)) {
const trigger = $toggleBtn.data('trigger') || 'click';
const eventForTrigger = event.type === 'mouseover' ? 'hover' : 'click';
if (eventForTrigger !== trigger) {
return;
Popover.toggle = {
trigger: ['click', 'hover'],
check(element, type) {
const $element = $(element);
if ($element.data(this.KEY)) {
return false;
}
Popover.ensure($toggleBtn, {show: true, triggerEvent: event});
event.preventDefault();
}
});
if (type === 'hover') {
return $element.dataset('trigger') === 'hover';
}
return true;
},
onCreate(element, event, options) {
return new this(element, {triggerEvent: event, ...options});
},
onToggle(component, event) {
(component as Popover).toggle({event});
},
};

Popover.register();

0 comments on commit 79e2e7a

Please sign in to comment.