ycs77 / headlessui-float

Easily use Headless UI with Floating UI to position floating elements.
https://headlessui-float.vercel.app
MIT License
344 stars 11 forks source link

OriginClassResolver not properly works in rtl direction. #63

Closed mohammadhosseinmoradi closed 9 months ago

mohammadhosseinmoradi commented 1 year ago

OriginClassResolver not properly works in rtl direction.

ycs77 commented 10 months ago

Hi @mohammadhosseinmoradi, Do you mean when you set direction: rtl; in CSS?

mohammadhosseinmoradi commented 10 months ago

Hi, when set direction: rtl; directly in html tag for whole document. this change works great:

export default function originClassResolvers(placement: Placement | "center") {
  switch (placement) {
    case "top":
      return "origin-bottom";
    case "bottom":
      return "origin-top";
    case "left":
      return "ltr:origin-right rtl:origin-left";
    case "right":
      return "ltr:origin-left rtl:origin-right";
    case "top-start":
    case "right-end":
      return "ltr:origin-bottom-left rtl:origin-bottom-right";
    case "top-end":
    case "left-end":
      return "ltr:origin-bottom-right rtl:origin-bottom-left";
    case "right-start":
    case "bottom-start":
      return "ltr:origin-top-left rtl:origin-top-right";
    case "left-start":
    case "bottom-end":
      return "ltr:origin-top-right rtl:origin-top-left";
    default:
      return "origin-center";
  }
}

export const tailwindcssOriginSafelist = [
  "origin-bottom",
  "origin-top",
  "ltr:origin-right rtl:origin-left",
  "ltr:origin-left rtl:origin-right",
  "ltr:origin-bottom-left rtl:origin-bottom-right",
  "ltr:origin-bottom-right rtl:origin-bottom-left",
  "ltr:origin-top-left rtl:origin-top-right",
  "ltr:origin-top-right rtl:origin-top-left",
];
ycs77 commented 9 months ago

Thanks for report, I using above your code into the PR #82 and added your is co-author.