fix: enforce a single open user profile preview across ProfilePreview instances (#27578)
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
<script context="module" lang="ts">
|
||||
/**
|
||||
* At most one user profile preview may be open across all ProfilePreview
|
||||
* instances. bits-ui's safe-polygon close only re-evaluates on pointermove,
|
||||
* so a preview can be left open when the pointer stops on a neighboring
|
||||
* row while still inside the previous row's grace area; opening a preview
|
||||
* therefore force-closes whichever one is still up.
|
||||
*/
|
||||
let closeActiveProfilePreview: (() => void) | null = null;
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { LinkPreview } from 'bits-ui';
|
||||
import { getContext } from 'svelte';
|
||||
import { getContext, onDestroy } from 'svelte';
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
import UserStatus from './UserStatus.svelte';
|
||||
@@ -13,6 +24,23 @@
|
||||
export let sideOffset = 8;
|
||||
|
||||
let openPreview = false;
|
||||
|
||||
const closeProfilePreview = () => {
|
||||
if (openPreview) {
|
||||
openPreview = false;
|
||||
}
|
||||
};
|
||||
|
||||
$: if (openPreview && closeActiveProfilePreview !== closeProfilePreview) {
|
||||
closeActiveProfilePreview?.();
|
||||
closeActiveProfilePreview = closeProfilePreview;
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
if (closeActiveProfilePreview === closeProfilePreview) {
|
||||
closeActiveProfilePreview = null;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<LinkPreview.Root openDelay={0} closeDelay={200} bind:open={openPreview}>
|
||||
|
||||
Reference in New Issue
Block a user