Skip to content

Commit

Permalink
fix: assembly member tooltip overflow in a small screen (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
greatng authored Oct 22, 2024
1 parent 3cf8aae commit c3dcc68
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/components/Assemblies/AssemblyTooltip.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
<script lang="ts">
import { afterUpdate } from 'svelte';
import type { TooltipProp } from './shared';
export let tooltipProp: TooltipProp | null = null;
let tooltipRef: HTMLDivElement;
let innerWidth: number;
afterUpdate(() => {
if (!tooltipProp) return;
const tooltip = tooltipRef.getBoundingClientRect();
const { width } = tooltip;
tooltipProp.x -= width / 2;
// adjust tooltip position when its size exceed window
if (innerWidth < tooltipProp.x + width) {
tooltipProp.x = innerWidth - width;
} else if (tooltipProp.x < 0) {
tooltipProp.x = 0;
}
});
</script>

<svelte:window bind:innerWidth />

{#if tooltipProp}
<div
bind:this={tooltipRef}
style:left="{tooltipProp.x}px"
style:top="{tooltipProp.y}px"
class="label-01 absolute z-10 flex min-w-max flex-col
Expand Down

0 comments on commit c3dcc68

Please sign in to comment.