-
Notifications
You must be signed in to change notification settings - Fork 0
fix(template-no-invalid-aria-attributes): absorb allowundefined handling into validateByType #49
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,16 +11,20 @@ function isNumeric(value) { | |
| return !Number.isNaN(Number(value)); | ||
| } | ||
|
|
||
| function isValidAriaValue(attrName, value) { | ||
| const attrDef = aria.get(attrName); | ||
| if (!attrDef) { | ||
| return true; | ||
| } | ||
| // Per aria-query's `allowundefined` convention: some attribute definitions | ||
| // (notably the 4 boolean-type attrs aria-expanded / aria-hidden / aria-grabbed | ||
| // / aria-selected) mark the literal string 'undefined' as a spec-valid value | ||
| // meaning "state is not applicable" (per WAI-ARIA 1.2 value table, e.g. | ||
| // https://www.w3.org/TR/wai-aria-1.2/#aria-expanded). Any attribute type can | ||
| // in principle accept 'undefined' via this flag. | ||
| function allowsUndefinedLiteral(attrDef, value) { | ||
| return value === 'undefined' && Boolean(attrDef.allowundefined); | ||
| } | ||
|
|
||
| if (value === 'undefined') { | ||
| return Boolean(attrDef.allowundefined); | ||
| function validateByType(attrDef, value) { | ||
| if (allowsUndefinedLiteral(attrDef, value)) { | ||
| return true; | ||
| } | ||
|
|
||
| switch (attrDef.type) { | ||
| case 'boolean': { | ||
| return isBoolean(value); | ||
|
|
@@ -45,7 +49,9 @@ function isValidAriaValue(attrName, value) { | |
| return isNumeric(value) && !isBoolean(value); | ||
| } | ||
| case 'token': { | ||
| // aria-query stores boolean values as actual booleans, convert for comparison | ||
| // aria-query stores boolean values as actual booleans; stringify for comparison. | ||
| // The string literal 'undefined' that appears in some values arrays (e.g. | ||
| // aria-orientation) passes through this check naturally — no special-casing. | ||
| const permittedValues = attrDef.values.map((v) => | ||
| typeof v === 'boolean' ? v.toString() : v | ||
| ); | ||
|
|
@@ -60,6 +66,14 @@ function isValidAriaValue(attrName, value) { | |
| } | ||
| } | ||
|
|
||
| function isValidAriaValue(attrName, value) { | ||
| const attrDef = aria.get(attrName); | ||
| if (!attrDef) { | ||
| return true; | ||
| } | ||
| return validateByType(attrDef, value); | ||
| } | ||
|
Comment on lines
+71
to
+77
|
||
|
|
||
| function getExpectedTypeDescription(attrName) { | ||
| const attrDef = aria.get(attrName); | ||
| if (!attrDef) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.