microsoft / vscode-edge-devtools

A VSCode extension that allows you to use browser devtools from within the editor. The devtools will connect to an instance of Microsoft Edge giving you the ability to alter CSS styling, perform diagnostics, and debugging. Get it now at http://aka.ms/devtools-for-code
https://docs.microsoft.com/microsoft-edge/visual-studio-code/microsoft-edge-devtools-extension
MIT License
753 stars 257 forks source link

Invalid aria-invalid="{expression}" (React) #1270

Open andrecasal opened 1 year ago

andrecasal commented 1 year ago

Environment (please complete the following information):

Describe the bug:

"ARIA attributes must conform to valid values: Invalid ARIA attribute value: aria-invalid="{expression}" Microsoft Edge Tools axe/aria" shows up on valid aria-invalid expression.

Screenshot 2022-11-25 at 11 00 24

Repro steps:

  1. Create login.tsx component
  2. Copy this code to it:
    const Login = () => {
    return (
        <div>
            <form method="post">
                <div>
                    <label htmlFor="email-input">Email</label>
                    <input type="text" id="email-input" name="email" aria-invalid={Boolean(true)}
                </div>
            </form>
        </div>
    )
    }
  3. Notice the aria-invalid error, even though the expression is valid.

Expected behavior:

Expected the error to not show up.

Additional context:

captainbrosset commented 1 year ago

Thanks a lot for the report. Adding this to the team's backlog for prioritization and investigation.

codepo8 commented 1 year ago

It seems to be the problem that the webhint engine expects true or false as values and not the variable you have in there right now. This is a tricky thing to work around as ARIA values are defined, and we can't know that your expression will have the right value or not. This is a wontfix, I'm afraid, but you can use the "Quick fix" option to not get this error report any more.

andrecasal commented 1 year ago

@codepo8, out of curiosity, wouldn't it be possible to access the aria-invalid={Boolean(actionData?.fieldErrors?.email)} expression slot and check if typeof is boolean? If so, disable the error.

dparramon commented 1 year ago

@codepo8 Not sure I see the utility of a rule that accepts only true/false and not an expression, in many cases an attribute like this is going to be dynamic and is going to be controlled by an expression. For anyone working on Javascript (or any other language or framework that converts to Javascript) this often will become an expression.

Can't @andrecasal fix be used? or as he suggests disable the error? Or maybe turn it into a warning?

To me this looks like an engine limitation not an accessibility issue. If the only solution is to totally disable this hint, why have it on the first place?

captainbrosset commented 1 year ago

I have to agree with this, and will re-open this issue. Even though this might be a technically complex one to fix, I do think it makes sense to keep it on the backlog.

cyonder commented 12 months ago

I believe this error also exists in this case:

IDs used in ARIA and labels must be unique: Document has multiple elements referenced with ARIA with the same id attribute: {expression}

Even though, I'm doing this:

<span id={`${uniqueId}-helperText`}>{helperText}</span>
<span id={`${uniqueId}-errorMessage`} role="alert">{error.message}</span>