rpearce / react-medium-image-zoom

🔎 🏞 The original medium.com-inspired image zooming library for React (since 2016)
https://rpearce.github.io/react-medium-image-zoom/
BSD 3-Clause "New" or "Revised" License
1.9k stars 100 forks source link

preventDefault for the un-zoom button #746

Open kayvaninvemo opened 3 weeks ago

kayvaninvemo commented 3 weeks ago

https://github.com/rpearce/react-medium-image-zoom/blob/4ad2a9ceebdbdf247f388c69190f07b90cfa4d71/source/Controlled.tsx#L260

here we need to preventDefault, otherwise it causes un expected behaviour if the zoom component it self is inside a dialog.

rpearce commented 3 weeks ago

@kayvaninvemo do you have time to put an example into a CodeSandbox that I can test with?

rpearce commented 1 week ago

@kayvaninvemo I unfortunately don't yet understand what the problem is. If you can help me understand it with a demo, that would be helpful.

tjx666 commented 1 week ago

@rpearce

try here: https://stackblitz.com/edit/vitejs-vite-nddcft?file=src%2FApp.tsx

  1. click button to open dialog
  2. click image in dialog to open zoomed image
  3. click the zoomed image
    • expect: only exit the zommed state, but keep dialog open
    • actual: not only exit the zoomed state, but also exit modal
kayvaninvemo commented 1 week ago

@tjx666 this is exactly my issue. I did a workaround here

      onClose={(e: any) => {
        if (e.target?.id?.match(/rmiz-modal-.*/)) {
          return;
        }
        handleClose();
      }}
rpearce commented 6 days ago

@tjx666 @kayvaninvemo Got it! Will fix. Many thanks for y'all's patience and sharing info.

rpearce commented 2 days ago

Well, I thought this would be fixed in react-medium-image-zoom@5.2.11, but I went back to that stackblitz, updated the package.json, re-installed, and gave it a whirl, but no difference.

Could one of y'all give this a try for me? It's not impossible @mui/material is doing something unexpected.