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

Confirm Popup Through Custom Directive #7241

Open
hcancelik opened this issue Feb 12, 2025 · 2 comments
Open

Confirm Popup Through Custom Directive #7241

hcancelik opened this issue Feb 12, 2025 · 2 comments
Labels
Resolution: Cannot Replicate Issue could not be replicated by Core Team

Comments

@hcancelik
Copy link

hcancelik commented Feb 12, 2025

Hi,

I'm seeking help to solve a positioning issue with a confirm popup.

I have this custom directive.

function reClick(el) {
  const newEvent = new MouseEvent("click", {
    bubbles: true,
    cancelable: true,
    view: window,
  });

  el.dispatchEvent(newEvent);
}

export default {
  beforeMount(el, binding) {
    let reDispatching = false;

    el.addEventListener(
      "click",
      (event) => {
        if (reDispatching) {
          return;
        }

        event.preventDefault();
        event.stopImmediatePropagation();

        const { appContext } = binding.instance.$;
        const confirm = appContext.config.globalProperties.$confirm;

        const { modifiers, value } = binding;

        let severity;
        let icon = "pi pi-question-circle";

        if (modifiers.destructive) {
          severity = "danger";
          icon = "pi pi-exclamation-triangle";
        }

        confirm.require({
          target: el, // Also tried without it
          header: "Confirm",
          message: "Are you sure you want to proceed?",
          group: "popover",
          icon,
          acceptProps: {
            label: "Confirm",
            severity,
          },
          rejectProps: {
            label: "Cancel",
            severity: "secondary",
            outlined: true,
          },
          reject: () => {},
          ...value,
          accept: () => {
            reDispatching = true;
            reClick(el);
            reDispatching = false;
          },
        });
      },
      { capture: true },
    );
  },
};

The problem is that the popover is always positioned at the top left of the document.

Image

Can anyone guide me on how I would fix this?

Thanks.

Example: https://stackblitz.com/edit/primevue-4-vite-issue-template-oxg9ytnv
Click "Button" for the popover

@tugcekucukoglu tugcekucukoglu added the Resolution: Cannot Replicate Issue could not be replicated by Core Team label Feb 20, 2025
Copy link

We're unable to replicate your issue, if you are able to create a reproducer by using PrimeVue Issue Template or add details please edit this issue. This issue will be closed if no activities in 20 days.

@hcancelik
Copy link
Author

@tugcekucukoglu here is a reproducable example of the issue

https://stackblitz.com/edit/primevue-4-vite-issue-template-oxg9ytnv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Cannot Replicate Issue could not be replicated by Core Team
Projects
None yet
Development

No branches or pull requests

2 participants