Skip to content

Commit c7b5d50

Browse files
committed
fix(ui): popover toggle fix
1 parent f8878f9 commit c7b5d50

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

codex-ui/dev/pages/components/Popover.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div>
1616
<Button
1717
secondary
18-
@click="show($event.target, {vertically: 'below', horizontally: 'left'})"
18+
@click="!isOpen ? show($event.target, {vertically: 'below', horizontally: 'left'}) : hide()"
1919
>
2020
Open below left
2121
</Button>
@@ -82,7 +82,7 @@
8282
import PageHeader from '../../components/PageHeader.vue';
8383
import { usePopover, PopoverShowParams, Button, ContextMenu, Heading } from '../../../src/vue';
8484
85-
const { showPopover } = usePopover();
85+
const { showPopover, isOpen, hide } = usePopover();
8686
8787
/**
8888
* Example of working with Popover

codex-ui/src/vue/components/popover/Popover.vue

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ const {
2929
hide,
3030
content,
3131
width,
32+
targetElement,
3233
} = usePopover();
3334
3435
/**
3536
* Close the popover when clicking outside of it
3637
*/
37-
onClickOutside(popoverEl, hide);
38+
onClickOutside(popoverEl, hide, {
39+
/**
40+
* Allow clicks on the target element to implemet toggle behavior
41+
*/
42+
ignore: [targetElement],
43+
});
3844
</script>
3945

4046
<style module>

codex-ui/src/vue/components/popover/usePopover.ts

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ export const usePopover = createSharedComposable(() => {
5151
*/
5252
const content = shallowRef<PopoverContent | null>(null);
5353

54+
/**
55+
* Target element to move popover to
56+
*/
57+
const targetElement = ref<HTMLElement | null>(null);
58+
5459
/**
5560
* Move popover to the target element
5661
* Also, align and set width
@@ -128,6 +133,7 @@ export const usePopover = createSharedComposable(() => {
128133
* @param params - popover showing configuration
129134
*/
130135
function showPopover(params: PopoverShowParams): void {
136+
targetElement.value = params.targetEl;
131137
move(params.targetEl, params.align, params.width);
132138
mountComponent(params.with.component, params.with.props);
133139
show();
@@ -137,6 +143,7 @@ export const usePopover = createSharedComposable(() => {
137143
* Empty content, position and hide popover
138144
*/
139145
function resetPopover(): void {
146+
targetElement.value = null;
140147
content.value = null;
141148
position.left = 0;
142149
position.top = 0;
@@ -159,5 +166,6 @@ export const usePopover = createSharedComposable(() => {
159166
hide,
160167
content,
161168
width,
169+
targetElement,
162170
};
163171
});

0 commit comments

Comments
 (0)