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

Bug: Anchor_string does not apply to disabled anchors #732

Closed
7 tasks done
ibrahima opened this issue Aug 15, 2024 · 4 comments
Closed
7 tasks done

Bug: Anchor_string does not apply to disabled anchors #732

ibrahima opened this issue Aug 15, 2024 · 4 comments

Comments

@ibrahima
Copy link

👀 Before submitting...

  • I upgraded to pagy version 9.0.5
  • I searched through the Documentation
  • I searched through the Issues
  • I searched through the Q&A

🧐 REQUIREMENTS

  • I am providing a VALID code file that confirms the bug
  • I am NOT posting any of the USELESS THINGS listed above
  • I am aware that this issue will be automatically closed if the code file is missing or INVALID

💬 Description

Hi! I'm just getting started with pagy, and I was trying to figure out how best to style it within the context of my application. I wanted to apply some classes that are already defined to the anchors. I noticed though that the anchor_string argument only applies to the non-disabled anchors, which isn't what I'd want personally. Is this intentional, or a bug? Thank you!

Here's my reproduction: https://gist.github.com/ibrahima/cc448df2be46b6c22095d9de3a9e2ffa#file-repro-ru

The relevant portion is

    /* My addition */
    .pagy .my-favorite-class {
      background-color: red !important;
    }

and

  <%= pagy_nav(@pagy, id: 'nav', aria_label: 'Pages nav', anchor_string: 'class="my-favorite-class"') %>

image

I was expecting in this example that all the anchors would be turned red, even the disabled ones.

I understand if this is intended behavior, I can figure out a different way to style things. I was just trying to understand if this was intentional. Thank you!

@ibrahima ibrahima added the bug label Aug 15, 2024
@ddnexus
Copy link
Owner

ddnexus commented Aug 16, 2024

Hi @ibrahima,
the current page was not an anchor in previous versions, so what was the anchor_string in that version was not included in the current page markup. The successive refactoring made the current page an anchor without href, but continued to ignore it in the markup.

That's an inconsistency which should be considered a bug, so this issue is valid.

Your particular example is good for highlighting the inconsistent behavior, however using the anchor_string to add a class is probably not the best way to do it.

You can target the anchors with a CSS rule, and with the classes keyword argument, which is currently ignored in the simple pagy_nav (which is another inconsistency, hence a possible bug to be fixed)

Will fix ASAP.

benkoshy added a commit that referenced this issue Aug 17, 2024
work in progress commit to fix: issue #732.

i have only done the pagy_nav helper so far. I want to make sure i am on
the correct track

fix: rematch-rebuild the anchor-string for the calendar extra
@benkoshy
Copy link
Collaborator

92fd345 - all i did was add it in the markup for the anchor-string for the gaps and current pages.

Is this the correct approach?

I can easily do for the other nav helpers and add tests.

@ddnexus
Copy link
Owner

ddnexus commented Aug 24, 2024

OK, so I finally had a bit of time to analyze the matter properly.

The main goal of the anchor_string is allowing to use data-* attributes. Its naming is generic enough so to cover any string that you may want to add to the actual page links, but that does not mean we should abuse it. Current page and gaps became disabled anchors only to get an easier and more consistent way to target them with CSS rules, but are actually NOT used as active page links.

Now, using anchor_string to target also the disabled links (that became links only to be consistently targeted by CSS rules) would make it technically consistent, but would add things that we don't need - exactly because now we can easily target them with CSS rules.

In conclusion the anchor_string seems better added only to the active links - as it was designed originally. That means that unless there is some request with a valid use-case that require the change, the code is fine as-is ATM.

On the other hand, the docs require changes to fix and clarify the matter.

Will do ASAP.

@ibrahima
Copy link
Author

Thanks for looking into it!

ddnexus added a commit that referenced this issue Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants