I discovered the possibility of using aria-current=“page” to highlight the current link in a nav with CSS rules by reading the excellent guide proposal on accessibility.
[aria-current="page"] {
font-weight: bold;
border-bottom: 2px solid currentColor;
}
This method is better than adding a custom active class to links, and it makes the link more accessible.
I’m thinking about improving the ActionView link_to helper so that it automatically appends this attribute to all links when current_page?(url_target) is true.
For cases when developers want to customize when a link should be marked as current, the link_to helper would accept a current boolean option that overrides the default behavior.