forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: extract html-interactive-content util (HTML §3.2.5.2.7 authority)
#37
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
be1a15d
refactor: reconcile native-interactive-elements via shared util
johanrd ad391dc
refactor: split native-interactive-elements into HTML-content-model a…
johanrd 15ea10e
refactor: consume #27's aria-query-derived INTERACTIVE_ROLES
johanrd af35568
fix: normalize <input type>, plumb ignoreUsemap, align contenteditabl…
johanrd daf30f5
sync: interactive-roles to canonical (use strict added)
johanrd b1e970d
docs: address Copilot review wording (PR #37)
johanrd c17ac2d
fix(template-no-nested-interactive): isMenuItemNode matches all three…
johanrd aecd9ed
chore(rules): add 'use strict' header to no-nested-interactive and no…
johanrd 2bbcee0
fix(template-no-nested-interactive): guard canvas in isInteractiveOnl…
johanrd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * HTML "interactive content" classification, authoritative per | ||
| * [HTML Living Standard §3.2.5.2.7 Interactive content] | ||
| * (https://html.spec.whatwg.org/multipage/dom.html#interactive-content): | ||
| * | ||
| * a (if the href attribute is present), audio (if the controls attribute | ||
| * is present), button, details, embed, iframe, img (if the usemap | ||
| * attribute is present), input (if the type attribute is not in the | ||
| * Hidden state), label, select, textarea, video (if the controls | ||
| * attribute is present). | ||
| * | ||
| * Plus <summary>, which is not in §3.2.5.2.7 but is keyboard-activatable per | ||
| * [§4.11.2 The summary element](https://html.spec.whatwg.org/multipage/interactive-elements.html#the-summary-element). | ||
| * | ||
| * This is the HTML-content-model authority — it answers "does the HTML spec | ||
| * prohibit nesting this inside an interactive parent?" It does NOT answer | ||
| * "is this an ARIA widget for AT semantics?" (see `interactive-roles.js` | ||
| * for that). The two questions diverge on rows like <label> (HTML: yes; | ||
| * ARIA: structure role), <canvas> (HTML: no; ARIA: widget per axobject), | ||
| * and <option>/<datalist> (HTML: no; ARIA: widgets). Rules that need | ||
| * "interactive for any reason" should compose both authorities. | ||
| */ | ||
|
|
||
| const UNCONDITIONAL_INTERACTIVE_TAGS = new Set([ | ||
| 'button', | ||
| 'details', | ||
| 'embed', | ||
| 'iframe', | ||
| 'label', | ||
| 'select', | ||
| 'summary', | ||
| 'textarea', | ||
| ]); | ||
|
|
||
| /** | ||
| * Determine whether a Glimmer element node is HTML-interactive content per | ||
| * §3.2.5.2.7 (+ summary). | ||
| * | ||
| * @param {object} node Glimmer ElementNode (has a string `tag`). | ||
| * @param {Function} getTextAttrValue Helper (node, attrName) -> string | undefined | ||
| * returning the static text value of an | ||
| * attribute, or undefined for dynamic / missing. | ||
| * @param {object} [options] | ||
| * @param {boolean} [options.ignoreUsemap=false] Treat `<img usemap>` as NOT interactive. | ||
| * Consumed by rules with an `ignoreUsemap` | ||
| * config option that lets authors opt out | ||
| * of image-map-based interactivity. | ||
| * @returns {boolean} | ||
| */ | ||
| function isHtmlInteractiveContent(node, getTextAttrValue, options = {}) { | ||
| const rawTag = node && node.tag; | ||
| if (typeof rawTag !== 'string' || rawTag.length === 0) { | ||
| return false; | ||
| } | ||
| const tag = rawTag.toLowerCase(); | ||
|
|
||
| if (UNCONDITIONAL_INTERACTIVE_TAGS.has(tag)) { | ||
| return true; | ||
| } | ||
|
|
||
| // input — interactive unless type="hidden" | ||
| if (tag === 'input') { | ||
| const type = getTextAttrValue(node, 'type'); | ||
| return type === undefined || type === null || type.trim().toLowerCase() !== 'hidden'; | ||
| } | ||
|
|
||
| // a — interactive only when href is present | ||
| if (tag === 'a') { | ||
| return hasAttribute(node, 'href'); | ||
| } | ||
|
|
||
| // img — interactive only when usemap is present (image map) | ||
| if (tag === 'img') { | ||
| if (options.ignoreUsemap) { | ||
| return false; | ||
| } | ||
| return hasAttribute(node, 'usemap'); | ||
| } | ||
|
|
||
| // audio / video — interactive only when controls is present | ||
| if (tag === 'audio' || tag === 'video') { | ||
| return hasAttribute(node, 'controls'); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| function hasAttribute(node, name) { | ||
| return Boolean(node.attributes && node.attributes.some((a) => a.name === name)); | ||
| } | ||
|
|
||
| module.exports = { isHtmlInteractiveContent }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.