Skip to content

Commit 28a4278

Browse files
authored
correction to Popper placement when RTL (#1842)
* correction to Popper placmement when RTL * ExampleRTL defaults to auto
1 parent 7e13d30 commit 28a4278

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

src/lib/tooltip/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { tv, type VariantProps } from "tailwind-variants";
44
export type TooltipVariants = VariantProps<typeof tooltip>;
55

66
export const tooltip = tv({
7-
base: "absolute px-3 py-2 rounded-lg text-sm z-50 pointer-events-none",
7+
base: "px-3 py-2 rounded-lg text-sm z-50 pointer-events-none",
88
variants: {
99
type: {
1010
light: "bg-white text-gray-800 dark:bg-white dark:text-gray-800 border border-gray-200 dark:border-gray-200",

src/lib/utils/Arrow.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { getOppositePlacement, getSide } from "@floating-ui/utils";
44
import type { ArrowProps } from "$lib/types";
55
6-
let { placement = "top", cords, strategy = "absolute", class: className = "" }: ArrowProps = $props();
6+
let { placement = "top", cords, class: className = "" }: ArrowProps = $props();
77
88
const px = (n: number | undefined) => (n ? `${n}px` : "");
99
@@ -25,7 +25,6 @@
2525
2626
function positioning(node: HTMLElement) {
2727
$effect(() => {
28-
node.style.position = strategy;
2928
node.style.left = px(cords.x);
3029
node.style.top = px(cords.y);
3130
node.style.right = "";
@@ -44,7 +43,7 @@
4443
}
4544
</script>
4645

47-
<div use:positioning class="popover-arrow clip pointer-events-none block h-[10px] w-[10px] border-b border-l border-inherit bg-inherit text-inherit {className}"></div>
46+
<div use:positioning class="popover-arrow clip pointer-events-none absolute block h-[10px] w-[10px] border-b border-l border-inherit bg-inherit text-inherit {className}"></div>
4847

4948
<!--
5049
@component

src/lib/utils/Popper.svelte

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import type { ParamsType, PopperProps, TriggeredToggleEvent } from "$lib/types";
3-
import type { Coords, Middleware, Placement, Strategy } from "@floating-ui/dom";
3+
import type { Coords, Middleware, Placement } from "@floating-ui/dom";
44
import * as dom from "@floating-ui/dom";
55
import clsx from "clsx";
66
import { sineIn } from "svelte/easing";
@@ -43,10 +43,9 @@
4343
let invoker: HTMLElement | null = null;
4444
let referenceElement: HTMLElement | null = null;
4545
let triggerEls: HTMLElement[] = [];
46-
let arrowParams: { placement: Placement; cords: Partial<Coords>; strategy: Strategy } = $state({
46+
let arrowParams: { placement: Placement; cords: Partial<Coords> } = $state({
4747
placement,
48-
cords: { x: 0, y: 0 },
49-
strategy
48+
cords: { x: 0, y: 0 }
5049
});
5150
5251
$effect(() => {
@@ -80,10 +79,9 @@
8079
8180
return dom.computePosition(referenceElement ?? invoker, popover, { placement, middleware, strategy }).then(({ x, y, middlewareData: { arrow }, placement: pl, strategy }) => {
8281
if (popover) {
83-
Object.assign(popover.style, { position: strategy, left: yOnly ? "0" : px(x), top: px(y) });
84-
82+
Object.assign(popover.style, { position: strategy, left: yOnly ? "0" : px(x), right: "auto", top: px(y) });
8583
if (arrow && arrowEl) {
86-
arrowParams = { placement: pl, cords: { x: arrow.x, y: arrow.y }, strategy };
84+
arrowParams = { placement: pl, cords: { x: arrow.x, y: arrow.y } };
8785
}
8886
}
8987
});

src/routes/utils/ExampleRTL.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<script lang="ts">
22
type NotificationDirection = "ltr" | "rtl" | "auto";
33
4-
let { rtl = $bindable() }: { rtl?: NotificationDirection } = $props();
4+
let { rtl = $bindable("auto") }: { rtl?: NotificationDirection } = $props();
55
6-
if (rtl === undefined && document.dir) {
6+
if (rtl === "auto" && document.dir) {
77
rtl = document.dir as NotificationDirection;
88
}
99

0 commit comments

Comments
 (0)