-
Notifications
You must be signed in to change notification settings - Fork 779
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
[CLOSING > See: #1081] feat(rule): css-orientation-lock new wcag21 rule #971
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3fcee60
feat: new orientation lock rule init work
jeeyyy de0291a
Merge branch 'develop' into new-rule-css-orientation-lock
jeeyyy 11dad07
Merge branch 'develop' into new-rule-css-orientation-lock
jeeyyy 63ca41e
feat: new cssom rule and unit tests
jeeyyy 0eb473e
test: added integration tests
jeeyyy 1756a30
chore: remove redundant files
jeeyyy 12d5c4e
refactor: updates based on review
jeeyyy dfe6acd
chore: Tag css-orientation-lock as experimental
WilcoFiers e0a17f0
test: ignore cssom tests on integration mode
jeeyyy ec0a418
test: add catch for driver errors & ignore cssom integration tests
jeeyyy 502128c
test: udpate tests for ci
jeeyyy 4487942
test: run all tests
jeeyyy f9074ac
test: update preload-cssom tests
jeeyyy 20d08cc
test: add implicit wait of 10s for webdriver
jeeyyy 6f333aa
test: revert frame wait skip and remove media in preload cssom
jeeyyy efb4f28
test: give webdriver time to await page load
jeeyyy bcd9933
test: fix preload tests
jeeyyy 04cb3eb
test: attempt defer tag
jeeyyy 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 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 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 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,129 @@ | ||
/* global context */ | ||
|
||
// extract asset of type `cssom` from context | ||
const { cssom = undefined } = context || {}; | ||
const checkPass = true; | ||
const checkFail = false; | ||
const checkIncomplete = undefined; | ||
|
||
// if there is no cssom <- return incomplete | ||
if (!cssom || !cssom.length) { | ||
return checkIncomplete; | ||
} | ||
|
||
// combine all rules from each sheet into one array | ||
const rulesGroupByDocumentFragment = cssom.reduce( | ||
(out, { sheet, root, shadowId }) => { | ||
// construct key based on shadowId or top level document | ||
const key = shadowId ? shadowId : 'topDocument'; | ||
// init property if does not exist | ||
if (!out[key]) { | ||
out[key] = { | ||
root, | ||
rules: [] | ||
}; | ||
} | ||
// check if sheet and rules exist | ||
if (!sheet || !sheet.rules) { | ||
//return | ||
return out; | ||
} | ||
const rules = Array.from(sheet.rules); | ||
// add rules into same document fragment | ||
out[key].rules = out[key].rules.concat(rules); | ||
|
||
//return | ||
return out; | ||
}, | ||
{} | ||
); | ||
|
||
// Note: | ||
// Some of these functions can be extracted to utils, but best to do it when other cssom rules are authored. | ||
|
||
// extract styles for each orientation rule to verify transform is applied | ||
let isLocked = false; | ||
let relatedElements = []; | ||
|
||
Object.keys(rulesGroupByDocumentFragment).forEach(key => { | ||
const { root, rules } = rulesGroupByDocumentFragment[key]; | ||
|
||
// filter media rules from all rules | ||
const mediaRules = rules.filter(r => { | ||
// doc: https://developer.mozilla.org/en-US/docs/Web/API/CSSMediaRule | ||
// type value of 4 (CSSRule.MEDIA_RULE) pertains to media rules | ||
return r.type === 4; | ||
}); | ||
|
||
// narrow down to media rules with `orientation` as a keyword | ||
const orientationRules = mediaRules.filter(r => { | ||
// conditionText exists on media rules, which contains only the @media condition | ||
// eg: screen and (max-width: 767px) and (min-width: 320px) and (orientation: landscape) | ||
const cssText = r.cssText; | ||
return ( | ||
/orientation:\s+landscape/i.test(cssText) || | ||
/orientation:\s+portrait/i.test(cssText) | ||
); | ||
}); | ||
|
||
orientationRules.forEach(r => { | ||
// r.cssRules is a RULEList and not an array | ||
if (!r.cssRules.length) { | ||
return; | ||
} | ||
// cssRules ia a list of rules | ||
// a media query has framents of css styles applied to various selectors | ||
// iteration through cssRules and see if orientation lock has been applied | ||
Array.from(r.cssRules).forEach(cssRule => { | ||
/* eslint max-statements: ["error", 20], complexity: ["error", 15] */ | ||
|
||
// ensure selectorText exists | ||
if (!cssRule.selectorText) { | ||
return; | ||
} | ||
// ensure the given selector has styles declared (non empty selector) | ||
if (cssRule.styleMap && cssRule.styleMap.size <= 0) { | ||
return; | ||
} | ||
|
||
// check if transform style exists | ||
const transformStyleValue = cssRule.style.transform || false; | ||
// transformStyleValue -> is the value applied to property | ||
// eg: "rotate(-90deg)" | ||
if (!transformStyleValue) { | ||
return; | ||
} | ||
|
||
const rotate = transformStyleValue.match(/rotate\(([^)]+)deg\)/); | ||
const deg = parseInt((rotate && rotate[1]) || 0); | ||
const locked = deg % 90 === 0 && deg % 180 !== 0; | ||
|
||
// if locked | ||
// and not root HTML | ||
// preserve as relatedNodes | ||
if (locked && cssRule.selectorText.toUpperCase() !== 'HTML') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for this HTML selector thing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To exclude the matches |
||
const selector = cssRule.selectorText; | ||
const elms = Array.from(root.querySelectorAll(selector)); | ||
if (elms && elms.length) { | ||
relatedElements = relatedElements.concat(elms); | ||
} | ||
} | ||
|
||
// set locked boolean | ||
isLocked = locked; | ||
}); | ||
}); | ||
}); | ||
|
||
if (!isLocked) { | ||
// return | ||
return checkPass; | ||
} | ||
|
||
// set relatedNodes | ||
if (relatedElements.length) { | ||
this.relatedNodes(relatedElements); | ||
} | ||
|
||
// return | ||
return checkFail; |
This file contains 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,11 @@ | ||
{ | ||
"id": "css-orientation-lock", | ||
"evaluate": "css-orientation-lock.js", | ||
"metadata": { | ||
"impact": "serious", | ||
"messages": { | ||
"pass": "Display is operable, and orientation lock does not exist", | ||
"fail": "CSS Orientation lock is applied, and makes display inoperable" | ||
} | ||
} | ||
} |
This file contains 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 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,20 @@ | ||
{ | ||
"id": "css-orientation-lock", | ||
"selector": "html", | ||
"tags": [ | ||
"cat.structure", | ||
"wcag262", | ||
"wcag21aa", | ||
"experimental" | ||
], | ||
"metadata": { | ||
"description": "Ensures content is not locked to any specific display orientation, and the content is operable in all display orientations", | ||
"help": "CSS Media queries are not used to lock display orientation" | ||
}, | ||
"all": [ | ||
"css-orientation-lock" | ||
], | ||
"any": [], | ||
"none": [], | ||
"preload": true | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not take priority into consideration:
The second rule has higher priority, and so it shouldn't fail. We need to take priority into consideration in order to avoid false positives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue created: #1078