Skip to content
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

valueRegex for forbid-dom-props rule #3876

Open
makxca opened this issue Jan 11, 2025 · 4 comments
Open

valueRegex for forbid-dom-props rule #3876

makxca opened this issue Jan 11, 2025 · 4 comments

Comments

@makxca
Copy link

makxca commented Jan 11, 2025

I want to be able to prohibit the usage of certain values of some dom attributes.

In my case I do not want the other developers in my project to use the listbox aria-role because of its accessibility issues. They should use lists of buttons instead.

This should be invalid

<div role="listbox">

But I do not want to completely forbid the usage of the role attribute, so something like this should be valid

<div role="list">

So I want to be able to configure a rule like the following:

{
    "forbid-dom-props": {
        "forbid": [{
            "propName": "role",
            "valueRegex": "^listbox$",
            "message": "Please do not use listbox. You can use list of buttons instead"
        }]
    }
}
makxca added a commit to makxca/eslint-plugin-react that referenced this issue Jan 11, 2025
makxca added a commit to makxca/eslint-plugin-react that referenced this issue Jan 11, 2025
makxca added a commit to makxca/eslint-plugin-react that referenced this issue Jan 11, 2025
makxca added a commit to makxca/eslint-plugin-react that referenced this issue Jan 11, 2025
@ljharb
Copy link
Member

ljharb commented Jan 12, 2025

Using a regex is a nonstarter, because regexes in an eslint plugin are a CVE magnet (usually it's best to wait for some discussion before making a PR).

@makxca
Copy link
Author

makxca commented Jan 12, 2025

Using a regex is a nonstarter, because regexes in an eslint plugin are a CVE magnet (usually it's best to wait for some discussion before making a PR).

Thank you for the tip!

For my case just listing the prohibited values would work. How do you think, would this work for the plugin?

{
    "forbid-dom-props": {
        "forbid": [{
            "propName": "role",
            "values": ["listbox"],
            "message": "Please do not use listbox. You can use list of buttons instead"
        }]
    }
}

@ljharb
Copy link
Member

ljharb commented Jan 12, 2025

Yes, that seems like it would work.

That said, I'm not sure what a11y issues you have in mind with listbox?

makxca added a commit to makxca/eslint-plugin-react that referenced this issue Jan 12, 2025
@makxca
Copy link
Author

makxca commented Jan 12, 2025

Most users that come to our site and use screen readers prefer Chromium-based browsers and NVDA as their screen reader. Unfortunately, they cannot interact with listbox elements.

It is a known issue. It seems Chromium marks listbox elements as 'read-only'. It seems to have been fixed by the Chromium team in September 2024 (issue), and there is an example of an accessible listbox on w3.org. But it requires monitoring active descendants (I suppose, using JS-events such as focusIn/focusOut).

So, I believe making an accessible listbox is overkill, whereas one could just use a list of buttons.

makxca added a commit to makxca/eslint-plugin-react that referenced this issue Jan 12, 2025
makxca added a commit to makxca/eslint-plugin-react that referenced this issue Jan 12, 2025
makxca added a commit to makxca/eslint-plugin-react that referenced this issue Jan 13, 2025
makxca added a commit to makxca/eslint-plugin-react that referenced this issue Jan 13, 2025
makxca added a commit to makxca/eslint-plugin-react that referenced this issue Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants