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

Expose event to onChange callback #22

Open
jbadan opened this issue Jun 14, 2019 · 2 comments
Open

Expose event to onChange callback #22

jbadan opened this issue Jun 14, 2019 · 2 comments

Comments

@jbadan
Copy link

jbadan commented Jun 14, 2019

Would you accept a pr that exposes the click event to the callback for onChange?

https://github.com/ultimate-pagination/react-ultimate-pagination/blob/master/src/react-ultimate-pagination.js#L9

It makes it easier for the consumer to handle state and gives more flexibility. Something like onChange(value, event), so as to not make a breaking change.

@kachkaev
Copy link

👋 @jbadan have you found a workaround for this issue by any chance?

I have a pagination component with renders Next.js links, each pointing to URLs like /current-url?p=42. When a link is clicked, I disable the whole pagination component, wait for Next.js to reload the page and re-enable it the component again. All works well except in cases when a user ctrl-clicks on a link.

When a new page is opened in a different tab, onChange with a new page value still fires but there is no easy way me to tell if we’re navigating to a new page in the current tab or not. Thus, the component ends up disabled forever because it waits for the new URL to eventually load, but this does not happen.

@kachkaev
Copy link

UPD: Looks like I found a solution. Instead of passing Pagination’s onClick straight down to <Link />, I have added a custom handler which stops the event from firing upwards when a modifier key is pressed:

  // Prevent pagination onChange event from firing when a link is opened in a new tab. Context:
  // https://github.com/ultimate-pagination/react-ultimate-pagination/issues/22#issuecomment-1644667936
  const handleClick = React.useCallback(
    (event: React.MouseEvent) => {
      if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) {
        return
      }

      onClick()
    },
    [onClick],
  )

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

2 participants