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

Emulate :target to allow styling anchor element #53

Closed
1 of 3 tasks
daun opened this issue Jun 4, 2023 · 0 comments · Fixed by #69
Closed
1 of 3 tasks

Emulate :target to allow styling anchor element #53

daun opened this issue Jun 4, 2023 · 0 comments · Fixed by #69

Comments

@daun
Copy link
Member

daun commented Jun 4, 2023

Describe the problem

When clicking a hash link on a page, swup scrolls to the matching target element. But the :target selector doesn't have any effect. This example will paint the element #my-element red without swup enabled, but won't do anything with swup.

<a href="#element">Scroll to element</a>

<div id="element">Element</div>

<style>
  :target {
    background: red;
  }
</style>

Describe the proposed solution

From the discussion of the original issue on the core repo:

Seems like fitting aria-current values could be location or simply true. I worry that using that attribute could interfere with consumer-scripts, though (they may be using the aria-current attribute already to mark an active tab or the like).

Maybe a simple swup-scroll-target or swup-current-target or swup-hash-target attribute would be less intrusive? In that case, it should be part of the Scroll Plugin, as you first suggested.

Research

A few links with prior discussions or solutions:

How important is this feature to you?

  • Nice to have
  • Would make my life a lot easier
  • I cannot use swup without it
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 a pull request may close this issue.

1 participant