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

Possibility to control closing. #1463

Open
ItProgerUA opened this issue Dec 10, 2024 · 4 comments
Open

Possibility to control closing. #1463

ItProgerUA opened this issue Dec 10, 2024 · 4 comments

Comments

@ItProgerUA
Copy link

There is no way to control closing the gallery except through the default button

I would like to be able to add a custom button to an open gallery, when clicked you can close the gallery. (This is required if there is logic inside the content that requires interaction with a click)

@ItProgerUA ItProgerUA changed the title Возможность контролировать закрытие. Possibility to control closing. Dec 10, 2024
@akhmadullin
Copy link
Contributor

You can do it now by adding custom ui element, that will be closing gallery

const uiElements = [
  {
    name: 'custom-close-button',
    ariaLabel: 'Close button',
    order: 9,
    isButton: true,
    html: {
      isCustomSVG: true,
      inner:
        '<path d="<ICON_PATH>" id="pswp__icn-cstm-btn"/>',
      outlineID: 'pswp__icn-cstm-btn',
    },
    appendTo: 'bar',
    onClick: (e, el, pswpInstance) => {
      pswpInstance.close();
    },
  },
]

const MyGallery = () => (
  <Gallery uiElements={uiElements}>
    {/*...*/}
  </Gallery>
)

@ItProgerUA
Copy link
Author

Thank you for your response, but I need something slightly different. It’s necessary not to customize the button but to pass it into the item context, where unfortunately there is no access to pswpInstance.close();. For example, I have provided a short piece of code.
Best regards,
Example of what is expected
https://codesandbox.io/p/sandbox/kscfl3

@MaximKondratev
Copy link
Contributor

I think we can add some close api either for useGallery hook or for Item render prop (or both). Is it what you need?

@ItProgerUA
Copy link
Author

I think yes. that would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants