Fix the accessibility audit for a sign-up email field

Review the AI's codeEasy12 minMicrosoft style

Your task

An AI built a sign-up email field with inline validation. The label and the red error show on screen, but neither is connected to the input in code. A screen reader announces "edit text" and never reads the error. Your team now audits the attributes each field really renders.

An assistant wrote audit_email_field(attrs). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • attrs: the field's rendered attributes, each written key=value. The keys are id, type, placeholder, aria-label, aria-labelledby, aria-describedby and aria-invalid on the input; label-for, the for of a <label>; and error-id, error-role and error-aria-live on the error message, when one is shown.
  • Return the defect codes found, sorted by plain character order.

Rules the tests check:

  • Skip an entry with no =. Split the rest at the first = and trim both sides. Skip an empty key. When a key repeats, its last value wins. A missing key counts as an empty value.
  • The input has a programmatic label when label-for is not empty and equals id, or aria-label is not empty, or aria-labelledby is not empty. A placeholder is not a label.
  • "no-programmatic-label": the input has no programmatic label. In that case, also add "placeholder-not-a-label" when placeholder is not empty.
  • "wrong-input-type": type is not exactly email.
  • When error-id is not empty, an error is shown and three more checks apply:
    • "error-not-described-by": error-id is not one of the space-separated ids in aria-describedby.
    • "error-not-announced": error-role is not alert, and error-aria-live is neither polite nor assertive.
    • "missing-aria-invalid": aria-invalid is not exactly true.

Examples

audit_email_field(attrs: list[str]) -> list[str]
Example 1
Inputaudit_email_field(["id=email", "type=text", "placeholder=Email", "error-id=email-error"])
Output["error-not-announced", "error-not-described-by", "missing-aria-invalid", "no-programmatic-label", "placeholder-not-a-label", "wrong-input-type"]
Example 2
Inputaudit_email_field(["id=email", "type=email", "label-for=email", "aria-invalid=true", "aria-describedby=email-error", "error-id=email-error", "error-role=alert"])
Output[]
Example 3
Inputaudit_email_field(["id=email", "type=text", "label-for=email"])
Output["wrong-input-type"]