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

fix(Pagination): handle max > 5 and max equal total pages #728

Merged
merged 11 commits into from
Sep 28, 2023

Conversation

Haythamasalama
Copy link
Contributor

@Haythamasalama Haythamasalama commented Sep 22, 2023

πŸ”— Linked issue

#723

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)

πŸ“š Description

  • When the maximum value is set to 0, 1, 2, 3, or 4, the pagination display is not correct.
Before: After:
Before After

Resolves #723

@vercel
Copy link

vercel bot commented Sep 22, 2023

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated (UTC)
ui βœ… Ready (Inspect) Visit Preview Sep 28, 2023 10:33am

@Haythamasalama
Copy link
Contributor Author

Haythamasalama commented Sep 22, 2023

  • Another use case is when the maximum displayed pages are equal to or greater than the total pages.
Before Before
After After

Copy link
Contributor

Hi @Haythamasalama !

Thanks for the PR! Indeed there is no correct handling of max < 5. This is due to the fact that max is not intended to be set below 5 as it technically has no sens, based on its initial purpose. Let me explain what was thought in the first place πŸ™‚

max has the goal to keep a max number of buttons (not only "pages" buttons but also "ellipsis" buttons), to keep consistency in its integration/display.
See how the number of buttons don't change on production:
CleanShot 2023-09-26 at 15.09.29.gif
And see how the changes affect this UX:
CleanShot 2023-09-26 at 15.10.05.gif

I'm fully open to rewrite that algorithm, I'm not really satisfied of what I've written initially and of how maintainable it is. But it should keep the initial behaviour, to allow some users to restrict the Pagination width and have a consistent UI.

Also about your PR, it looks good when page 1 is selected, but not fine when moving to page 2/3 in this case:
CleanShot 2023-09-26 at 15.18.32.gif

If you can fix that, we are good to go! πŸš€

@Haythamasalama
Copy link
Contributor Author

Thanks ❀️ @smarroufin for explaining the Max props. The first time, I thought max was only for buttons without dividers

However, after the explanation of what max is, I agree that it doesn't make sense for it to be max > 5 but we still need to handle cases when max > 5 as 5 and when max is equal to the total number of pages.

So, I made a refactor for it using the same algorithm to handle those cases.

@Haythamasalama Haythamasalama changed the title fix(Pagination): correct displayedPages() fix(Pagination): handle max > 5 and max equal total pages Sep 27, 2023
Copy link
Contributor

@smarroufin smarroufin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with your last updates! Works very well!

Also, to be a bit picky, why wouldn't we remove (or update) the props.max validator with it?
I guess it doesn't make sens since we fallback to a valid value on our own now.

      validate (value) {
        return value >= 7 && value < Number.MAX_VALUE
      }

@Haythamasalama
Copy link
Contributor Author

@smarroufin

I agree that we need to set the maximum value on the validator to 5, but should we remove the number from here?

                                               
 const maxDisplayedPages = Math.max(props.max, 5)

Copy link
Contributor

Do you mean 5 as minimum value? Then yes. From 5 to anything.

And I guess your fallback is to be kept anyways, otherwise we would end up with the issue we currently have, meaning that the docs number select can "disrespect" the validator by giving an unappropriated number.

@Haythamasalama
Copy link
Contributor Author

Sure, I've updated to 5.

Copy link
Contributor

@smarroufin smarroufin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good for me, thanks a lot @Haythamasalama!

@Haythamasalama
Copy link
Contributor Author

All good for me, thanks a lot @Haythamasalama!

You're welcome, @smarroufin ❀️. Thank you for reviewing it.

@benjamincanac benjamincanac merged commit a071e4b into nuxt:dev Sep 28, 2023
1 check passed
@Haythamasalama Haythamasalama deleted the fix/pagination branch September 28, 2023 16:57
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

Successfully merging this pull request may close these issues.

pagination duplicate buttons when max <= 4
3 participants