-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
fix: a11y rule "interactive-supports-focus" fails with a warning #4159
Changes from 3 commits
30fbe56
4ed2d74
c8d5121
201cd63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import React from "react"; | ||
|
||
import { useRouter } from "next/router"; | ||
import Link from "next/link"; | ||
import clsx from "clsx"; | ||
|
@@ -25,6 +24,7 @@ interface SubTabsListProps extends TabListProps { | |
const TabList = ({ tabList, pageId, selectedTab }: TabListProps) => { | ||
const router = useRouter(); | ||
const range = router.query.range ? Number(router.query.range) : 30; | ||
|
||
return ( | ||
<nav | ||
role="tablist" | ||
|
@@ -37,13 +37,13 @@ const TabList = ({ tabList, pageId, selectedTab }: TabListProps) => { | |
role="tab" | ||
aria-selected={selectedTab === tab.name.toLowerCase() ? "true" : "false"} | ||
data-state={selectedTab === tab.name.toLowerCase() ? "active" : "inactive"} | ||
tabIndex={-1} | ||
key={index} | ||
className={`tool-list-item border-b-2 transition-all ease-in-out ${ | ||
className={clsx( | ||
"tool-list-item border-b-2 transition-all ease-in-out", | ||
nickytonline marked this conversation as resolved.
Show resolved
Hide resolved
|
||
selectedTab === tab.name.toLowerCase() | ||
? "border-orange-500" | ||
: "border-transparent hover:border-light-slate-8" | ||
}`} | ||
)} | ||
> | ||
<TabListItem | ||
tab={tab} | ||
|
@@ -77,6 +77,11 @@ export const SubTabsList = ({ tabList, pageId, selectedTab, label, textSize, onS | |
key={index} | ||
className={clsx(isSelected && "bg-white shadow", "rounded py-1 px-2", !isSelected && "text-light-slate-11")} | ||
onClick={onSelect ? () => onSelect(tab) : undefined} | ||
onKeyDown={(e) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the SubTabsList, it's not a tab list if there is no export const SubTabsList = ({ tabList, pageId, selectedTab, label, textSize, onSelect }: SubTabsListProps) => {
const ContainerComponent = onSelect ? "div" : "nav";
const extraProps = onSelect ? { role: "tablist" } : {};
return (
<ContainerComponent
{...extraProps}
aria-label={label}
className={clsx(
"flex items-center w-max overflow-x-auto overflow-y-hidden gap-2 bg-light-slate-3 p-1 rounded",
textSize === "small" && "text-sm"
)}
>
{tabList.map((tab, index) => {
const isSelected = selectedTab === tab.name.toLowerCase();
return (
<div
key={index}
className={clsx(isSelected && "bg-white shadow", "rounded py-1 px-2", !isSelected && "text-light-slate-11")}
>
{onSelect ? (
<button role="tab" onClick={() => onSelect(tab)}>
tab.name
</button>
) : (
<Link href={`${pageId ? `${pageId}/` : ""}${tab.path}`}>{tab.name}</Link>
)}
</div>
);
})}
</ContainerComponent>
);
}; This could be improved, but I don't want to introduced too much refactoring for the moment as the goal of the issue was to sort out some accessibility issues. Note that because we've introduced a button when the
we no longer need the |
||
if (e.key === "Enter" || e.key === " ") { | ||
onSelect?.(tab); | ||
} | ||
}} // Added keyboard interaction for Enter/Space keys | ||
> | ||
{onSelect ? tab.name : <Link href={`${pageId ? `${pageId}/` : ""}${tab.path}`}>{tab.name}</Link>} | ||
</div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reviewing the pull request, this really is just links in a navigation element that look like tabs, but they really are just. links.
The
role="tablist"
can be removed from the<nav />
and therole="tab"
on the<div />
can be removed.