Skip to content
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

fix(color-contrast): correctly handle flex and position #4086

Merged
merged 4 commits into from
Jul 13, 2023

Conversation

straker
Copy link
Contributor

@straker straker commented Jul 11, 2023

Mostly it's rearranging the order of the createStackingContext function to handle elements that created stacking context and needed to be positioned or floated. The code didn't handle elements that were both positioned with z-index: auto and another property that made it a stacking context (like display: flex).

Also changed how to handle adding the node index to every context by making it it's own property instead of combining it with the stacking context value. Made things simpler when creating / comparing the numbers. This was needed to allow sorting elements from different (but equal) stacking contexts correctly. Before they would be sorted as equal (stacking contexts were the same value) and then relied on the document order and positional sorting (based on float or inline), even when they belonged to different stacking context and shouldn't be sorted by position. Now the elements will only be positionally sorted when they belong to the same stacking context.

It should be noted that this fix doesn't actually result in resolving the incomplete in #4041. There is another element (.tmpl-header_searchBtnContainer) that is on top of the others (with a transparent background) and so the incomplete is correct that there is another element overlapping the links. I didn't realize this until after I made the stack correct.

Closes: #4041

@straker straker requested a review from a team as a code owner July 11, 2023 15:41
return stackingOrder;
}
// since many things can create a new stacking context without position or
Copy link
Contributor

@dbjorge dbjorge Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice change, I think your update including the nodeIndex in the comparator is much cleaner than the old way.

lib/commons/dom/create-grid.js Outdated Show resolved Hide resolved
if (index !== -1) {
stackingOrder.splice(index, stackingOrder.length - index);
if (isStackingContext(vNode, parentVNode)) {
const index = stackingOrder.findIndex(({ value }) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't have two variables with the same name in one function. This code is complicated enough 😁

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on a separate PR enabling the no-shadow eslint rule to catch this sort of issue proactively? (111 pre-existing issues, not trivial but manageable)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please

lib/commons/dom/create-grid.js Outdated Show resolved Hide resolved
lib/commons/dom/create-grid.js Outdated Show resolved Hide resolved
lib/commons/dom/create-grid.js Show resolved Hide resolved
lib/commons/dom/create-grid.js Outdated Show resolved Hide resolved
if (!isStackingContext(vNode, parentVNode)) {
if (vNode.getComputedStylePropertyValue('position') !== 'static') {
// Put positioned elements above floated elements
stackingOrder.push(createContext(POSITION_STATIC_ORDER, vNode));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, did we call the position for when something's NOT static the POSITION_STATIC_ORDER. Whoops! 🙄 That was my idea too wasn't it?

lib/commons/dom/create-grid.js Outdated Show resolved Hide resolved
lib/commons/dom/visually-sort.js Outdated Show resolved Hide resolved
Comment on lines +291 to +293
* @param {Number} stackLevel - The stack level of the stacking context
* @param {Number} treeOrder - The elements depth-first traversal order
* @param {VirtualNode} vNode - The virtual node that is the container for the stacking context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect element stack for flex and position absolute
3 participants