Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlay positions in RTL #7340

Open
1 of 4 tasks
AbdullahHouso opened this issue Feb 27, 2025 · 1 comment
Open
1 of 4 tasks

Overlay positions in RTL #7340

AbdullahHouso opened this issue Feb 27, 2025 · 1 comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@AbdullahHouso
Copy link

Describe the bug

When the website is RTL, any component with overlay (Select, Multiselect, Treeselect, Datepicker...) The RTL does not show exactly above the main component.

Pull Request Link

No response

Reason for not contributing a PR

  • Lack of time
  • Unsure how to implement the fix/feature
  • Difficulty understanding the codebase
  • Other

Other Reason

No response

Reproducer

https://stackblitz.com/edit/primevue-4-vite-issue-template-kxyb596c?file=src%2FApp.vue

Environment

Tailwind V3/V4
Vue 3.5.13 + Nuxt 3.5.13
PostCSS 8.5.3

Note: The issue is also present on PrimeVue docs when changing the theme settings to RTL:
https://primevue.org/select/

Vue version

3.5.13

PrimeVue version

4.3.1

Node version

22.14.0

Browser(s)

No response

Steps to reproduce the behavior

Set HTML attributes to: (dir="rtl")

Expected behavior

The overlay must be in the correct position around the main component, as in the LTR case.

@AbdullahHouso AbdullahHouso added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 27, 2025
@AbdullahHouso
Copy link
Author

AbdullahHouso commented Feb 27, 2025

I found out that there's a CSS value being assigned to the overlay of the component that is called (inset-inline-start). This value should define the position of overlay in the correct position. It works without issues in LTR. However, on RTL it does not.

Image

In order to make the overlay take its correct position, the attribute in RTL must change from (inset-inline-start) to (inset-inline-end) without changing the value

Image

Here's a workaround code that I put in my layout file to assign the value to the correct attribute name and clear the first one (My website is fully RTL):

onMounted(() => {
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            mutation.addedNodes.forEach((node) => {
                if (node.nodeType === 1 && (node as HTMLElement).classList.contains('p-component')) {
                    const htmlEl = document.documentElement;
                    if (document.documentElement.getAttribute('dir') === 'rtl') {
                        const overlay = node as HTMLElement;
                        const startValue = overlay.style.insetInlineStart;
                        if (startValue) {
                            overlay.style.insetInlineEnd = startValue;
                            overlay.style.insetInlineStart = 'auto';
                        }
                    }
                }
            });
        });
    });

    observer.observe(document.body, { childList: true, subtree: true });

    onBeforeUnmount(() => {
        observer.disconnect();
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

1 participant