Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use crate::{
context::LintContext,
globals::HTML_TAG,
rule::Rule,
utils::{get_element_type, has_jsx_prop_ignore_case, is_interactive_element, parse_jsx_value},
utils::{
get_element_type, has_jsx_prop_ignore_case, is_interactive_element, is_interactive_role,
parse_jsx_value,
},
};

fn no_noninteractive_tabindex_diagnostic(span: Span) -> OxcDiagnostic {
Expand Down Expand Up @@ -91,40 +94,6 @@ declare_oxc_lint!(
version = "0.15.4",
);

// https://www.w3.org/TR/wai-aria/#widget_roles
// NOTE: "tabpanel" is not included here because it's technically a section role. It can optionally be considered interactive within the context of a tablist, because its visibility is dynamically controlled by an element with the "tab" aria role. It's included in the recommended jsx-a11y config for this reason.
const INTERACTIVE_HTML_ROLES: [&str; 29] = [
"button",
"checkbox",
"combobox",
"grid",
"gridcell",
"link",
"listbox",
"menu",
"menubar",
"menuitem",
"menuitemcheckbox",
"menuitemradio",
"option",
"progressbar",
"radio",
"radiogroup",
"scrollbar",
"searchbox",
"separator",
"slider",
"spinbutton",
"switch",
"tab",
"tablist",
"textbox",
"toolbar",
"tree",
"treegrid",
"treeitem",
];

impl Rule for NoNoninteractiveTabindex {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
let AstKind::JSXOpeningElement(jsx_el) = node.kind() else {
Expand Down Expand Up @@ -180,7 +149,7 @@ impl Rule for NoNoninteractiveTabindex {
JSXAttributeValue::StringLiteral(role) => {
let is_interactive_role =
role.value.split_whitespace().next().is_some_and(|role| {
INTERACTIVE_HTML_ROLES.contains(&role)
is_interactive_role(role)
|| self.0.roles.iter().any(|allowed_role| allowed_role == role)
});

Expand Down
Loading