Fix the accessibility check for a modal dialog
Your task
A modal dialog in your app looks right, but keyboard and screen reader users cannot use it. It closes when you click the overlay, and its close "button" is a span with a click handler. Your team now runs an acceptance check that lists which dialog requirements a modal still misses.
An assistant wrote missing_dialog_requirements(implemented). It is in the editor. It has a bug. Find it and fix it.
Input and output:
implemented: the names of the things the modal does, as strings. It can be empty, hold duplicates and hold names that are not requirements.- Return a list of the requirement names the modal does not meet.
Rules the tests check:
- There are exactly eight requirements:
"aria-labelledby","aria-modal","button-close","escape-closes","focus-on-open","focus-restore","focus-trap"and"role-dialog". - A requirement is met only when its exact name is in
implemented. Matching is case sensitive. - No other entry meets any requirement.
- Duplicates change nothing.
- Return the unmet requirements in the order listed above, which is alphabetical. Return an empty list when all eight are met.
Examples
missing_dialog_requirements(implemented: list[str]) -> list[str]Example 1
Input
missing_dialog_requirements([])Output
["aria-labelledby", "aria-modal", "button-close", "escape-closes", "focus-on-open", "focus-restore", "focus-trap", "role-dialog"]Example 2
Input
missing_dialog_requirements(["aria-labelledby", "aria-modal", "button-close", "escape-closes", "focus-on-open", "focus-restore", "focus-trap", "role-dialog"])Output
[]Example 3
Input
missing_dialog_requirements(["role-dialog", "aria-modal"])Output
["aria-labelledby", "button-close", "escape-closes", "focus-on-open", "focus-restore", "focus-trap"]