From 6a90fdbf1bfb5600d2064f6e3ba7b03a8b70de9d Mon Sep 17 00:00:00 2001 From: Reed von Redwitz Date: Tue, 28 Nov 2023 17:32:48 +0100 Subject: [PATCH] docs: switch to aria-current in active links page (#2019) --- docs/latest/examples/active-links.md | 32 ++++++++++++++++------------ www/components/DocsSidebar.tsx | 4 ++-- www/components/NavigationBar.tsx | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/docs/latest/examples/active-links.md b/docs/latest/examples/active-links.md index af636240..626549e5 100644 --- a/docs/latest/examples/active-links.md +++ b/docs/latest/examples/active-links.md @@ -3,39 +3,43 @@ description: | Style active links with ease in Fresh --- -When Fresh renders an ``-element, it will automatically add a -[data attribute](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes) -to the link which can be used for styling purposes. Fresh will add one of the -two following attributes: +Fresh automatically enhances the accessibility of elements by adding the +aria-current attribute when rendering links that match the current URL. This +attribute is recognized by assistive technologies and clearly indicates the +current page within a set of pages. -- `data-current` - Added to links with an exact path match -- `data-ancestor` - Added to links which partially match the current URL +- aria-current="page" - Added to links with an exact path match, enhancing + accessibility by indicating the current page to assistive technologies. + +As we aim to improve accessibility, we encourage the use of aria-current for +styling current links where applicable. ## Styling with CSS -`data-*` attributes can be natively styled in CSS via attribute selectors. +The aria-current attribute is easily styled with CSS using attribute selectors, +providing a native way to visually differentiate the active link. ```css /* Give links pointing to the current page a green color */ -a[data-current] { +a[aria-current='page'] { color: green; } /* Color all ancestor links of the current page */ -a[data-ancestor] { +a[aria-current='true'] { color: peachpuff; } ``` ## Tailwind / Twind -In tailwind or tailwind-like styling solutions you can style `data-*`-attributes -by prepending the classes with `[data-current]:` +In Tailwind or similar CSS frameworks, you can apply styles to elements with the +aria-current attribute by using bracket notation in your class definitions. ```tsx function Menu() { return ( - + link to some page ); @@ -48,7 +52,7 @@ The original twind plugin (`import twindPlugin from "$fresh/plugins/twind.ts";`) supports the above style: ```tsx -class="[data-current]:text-green-600" +class="[aria-current='page']:text-green-600" ``` ### TwindV1 Plugin @@ -57,5 +61,5 @@ The new twind plugin (`import twindPlugin from "$fresh/plugins/twindv1.ts";`) requires a slightly different syntax (note the position of the left bracket): ```tsx -class="data-[current]:text-green-600" +class="aria-[current='page']:text-green-600" ``` diff --git a/www/components/DocsSidebar.tsx b/www/components/DocsSidebar.tsx index 39e99b12..6ccf6aa1 100644 --- a/www/components/DocsSidebar.tsx +++ b/www/components/DocsSidebar.tsx @@ -54,7 +54,7 @@ export function SidebarCategory(props: {
  • {title} @@ -78,7 +78,7 @@ export function SidebarEntry(props: {
  • {title} diff --git a/www/components/NavigationBar.tsx b/www/components/NavigationBar.tsx index 0c403401..86aeb1b7 100644 --- a/www/components/NavigationBar.tsx +++ b/www/components/NavigationBar.tsx @@ -31,7 +31,7 @@ export default function NavigationBar( href={item.href} class={`p-1 sm:p-2 ${ isHome ? "text-green-900" : "text-gray-600" - } hover:underline data-[current]:font-bold data-[ancestor]:font-bold`} + } hover:underline aria-[current]:font-bold`} > {item.name}