Last active
April 10, 2023 16:54
-
-
Save dcyoung-dev/072a27bc96de52abf2dc3c21a969b89a to your computer and use it in GitHub Desktop.
An `active_link_to` helper that adds the `.active` class and sets `aria-current="page"`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def active_link_to(name = nil, options = nil, **html_options, &block) | |
options = block_given? ? name : options | |
if current_page?(options) | |
html_options[:class] = class_names(html_options[:class], :active) | |
html_options[:aria] = html_options.fetch(:aria, {}).merge(current: :page) | |
end | |
if block_given? | |
link_to options, html_options, &block | |
else | |
link_to name, options, html_options | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment