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: OPL separators on hidden items and edge cases #3136

Merged
merged 5 commits into from
Jan 20, 2023

Conversation

eKoopmans
Copy link
Contributor

@eKoopmans eKoopmans commented Jan 6, 2023

This PR is a follow-up to #3134. It changes how separators are rendered in object-property-lists to fix an edge case with status indicators, and also adds hidden support! The hidden support should make backporting to Polymer projects a lot easier/more possible in the future.

Opening as a draft targeting #3134's branch until it is merged.

Rally: https://rally1.rallydev.com/#/?detail=/userstory/674102762601&fdp=true

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2023

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://pr-3136-brightspace-ui-core.d2l.dev/

Note
The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2023

Could not generate new goldens - your code changes will update golden files that you do not have the latest version of. Please rebase or merge ekoopmans/opl-status-indicator into your branch.

Base automatically changed from ekoopmans/opl-status-indicator to main January 19, 2023 18:52
@github-actions
Copy link
Contributor

Visual diff tests failed - pull request #3185 has been opened with the updated goldens.

eKoopmans and others added 2 commits January 19, 2023 16:41
Co-authored-by: github-actions <github-actions@github.com>
@eKoopmans eKoopmans marked this pull request as ready for review January 19, 2023 21:56
@eKoopmans eKoopmans requested a review from a team as a code owner January 19, 2023 21:56
Copy link
Member

@dlockhart dlockhart left a comment

Choose a reason for hiding this comment

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

Cool, looks good. It's unfortunate that we need to jump through these kinds of hoops just to handle hidden items, but I can't think of a cleaner way, so 🤷 !

@github-actions
Copy link
Contributor

Visual diff tests failed - pull request #3187 has been opened with the updated goldens.

}

_setItemSeparatorVisibility() {
const slottedElements = this._slot.assignedElements();
Copy link
Contributor

@dbatiste dbatiste Jan 20, 2023

Choose a reason for hiding this comment

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

It looks like we're assuming that the slot element will never change. To avoid the assumption, we could query for the slot when needed, but in this particular case, we can have it passed in...

_onItemsChanged(e) {
	this._setItemSeparatorVisibility(e.target); //e.target of slotchange is the slot element
}

_setItemSeparatorVisibility(slot) {
	...
}

firstUpdated() {
this._slot = this.shadowRoot.querySelector('slot:not([name])');
this.addEventListener('d2l-object-property-list-item-visibility-change', this._onItemsChanged);
if (this._slot.childElementCount) this._onItemsChanged();
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting... I never knew the slot had this property. Seems Mozilla isn't forthcoming in these dets.

Copy link
Contributor

Choose a reason for hiding this comment

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

Though, are you sure this call is needed in firstUpdated? I think the slotchange event will be dispatched when the nodes are first distributed to it.

Copy link
Contributor Author

@eKoopmans eKoopmans Jan 20, 2023

Choose a reason for hiding this comment

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

This is specifically for the skeleton scenario, when nothing is slotted. childElementCount is to detect if there is any default content (e.g. skeleton) being rendered. So it's not anything specific to slots, rather just a default element attribute property:
https://developer.mozilla.org/en-US/docs/Web/API/Element/childElementCount

In my testing this was necessary, otherwise the visual-diff for skeleton was rendering a separator on the final item.

@dbatiste
Copy link
Contributor

Cool, looks good. It's unfortunate that we need to jump through these kinds of hoops just to handle hidden items, but I can't think of a cleaner way, so 🤷 !

I am hopeful that eventually we will be able to do this sort of thing, for example to select an element that has a hidden sibling (or doesn't have a hidden sibling):

:host(:has(+ [hidden])) { ... }
:host(:not(:has(+ [hidden]))) { ... }

It works in Safari, but it does not work in Chrome. There appears to be some ongoing discussion regarding what types of selectors should be valid in :host(), and whether relative selectors used in :host() should operate on light-DOM siblings. w3c/csswg-drafts#7953.

@eKoopmans
Copy link
Contributor Author

select an element that has a hidden sibling

Yeah, it does still get messy here with the facts that:

  • an item should render a separator if there is any non-hidden item after it
  • but an "item" can be <d2l-object-property-list-item> or <d2l-object-property-list-item-link>
  • and we want to specifically not account for other elements, especially if they're slotted

@eKoopmans eKoopmans merged commit 2a78309 into main Jan 20, 2023
@eKoopmans eKoopmans deleted the ekoopmans/opl-separator-improvements branch January 20, 2023 16:42
@ghost
Copy link

ghost commented Jan 20, 2023

🎉 This PR is included in version 2.80.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ghost ghost added the released label Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants