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

refactor: use shared slot presence mixin for conditional element styling #824

Merged
merged 7 commits into from
Aug 28, 2020

Conversation

Westbrook
Copy link
Contributor

@Westbrook Westbrook commented Aug 12, 2020

Description

  • Catch up to main and the keyboard helper work that is there.
  • Move to using @spectrum-web-components/base as the only entry to lit-element and lit-html.
  • update to latest lit-html/lit-element
  • use new lit-element to power the below...

Querying light DOM children to resolve template content is not reactive:

private get hasFooter(): boolean {	
        return !!this.querySelector('[slot="footer"]');	
}

Meaning that changing the presence of this content dynamically will not inherently trigger a new render.

Relying on a MutationObserver instead will allow the value of hasFooter or the like to be dynamic to content changes and ensure a more correct delivery of the elements template across its lifecycle.

Refactors ObserveSlotText to better leverage queryAssignedNodes. I see the possibility of merging the two observer mixins in some way in the future, but for now the use of Symbol() based properties allows them to neatly avoid stepping on each other without further refactoring.

Related Issue

fixes #793

Motivation and Context

Templates should be correct. That's the tweet...oh, wait.

How Has This Been Tested?

  • existing tests
  • new tests

Types of changes

  • feature factor

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@Westbrook Westbrook force-pushed the westbrook/has branch 3 times, most recently from 76ceb7d to df31b8e Compare August 20, 2020 18:15
@Westbrook Westbrook changed the base branch from main to spectrum-css-3 August 20, 2020 23:28
@Westbrook Westbrook force-pushed the westbrook/has branch 4 times, most recently from 4063d8f to 9849083 Compare August 21, 2020 01:38
@Westbrook Westbrook changed the title [blocked] refactor: use shared slot presence mixin for conditional element styling refactor: use shared slot presence mixin for conditional element styling Aug 21, 2020
@Westbrook Westbrook force-pushed the westbrook/has branch 2 times, most recently from 06465be to 86c6884 Compare August 21, 2020 19:17
### ObserverSlotText
### ObserveSlotPresence

When working with styles that are driven by the conditional presence of `<slot>`s in a component's shadow DOM, you will need to track whether light DOM that is meant for that slot. Use the `ObserveSlotPresence` mixin to target specific light DOM to observe the presence of and trigger `this.requestUpdate()` calls when content fulfilling that selector comes in and out of availability.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you mean:

you will need to track whether light DOM that is meant for that slot exists?

const slotElementObserver = Symbol('slotElementObserver');
const assignedNodesList = Symbol('assinedNodes');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const assignedNodesList = Symbol('assinedNodes');
const assignedNodesList = Symbol('assignedNodes');

@@ -34,6 +34,8 @@ export MyElement extends SpectrumMixin(HTMLElement) {}

With powerful CSS selectors like `:host(:dir(rtl))` and `:host-content([dir=rtl])` not yet enjoying cross-browser support, reliably delivering content in both "left to right" and "right to left" while relying on Shadow DOM means certain trade offs need to be made. While every custom element build from `SpectrumMixin` could have its `dir` attribute applied to manage this, doing so is not only a pain for apply, it's a pain to maintain over time. To support the flexibility to devlier content in both of these directions, elements built from `SpectrumMixin` will observe the `dir` attribute of either the `document` or a containing `sp-theme`. This will allow your sites and applications to manage content direction in a single place while also opening the possibility of having multiple content directions on the same page by scoping those content sections with `sp-theme` elements.

When placing a `dir` attribute on an element built from `SpectrumMixin` before attaching it to the DOM, this will prevent it from resolving the text direction value to a parent `sp-theme` or `document` element. Elements applied to the page in this way will also NOT participate in observing any such elements, so their `dir` values will remain as initialized regardless of changes in other parts of your documents. If you choose to leverage this, be aware that any child (in both light DOM and shadow DOM) of this element will need to have a `dir` attribute applied as well if you do not want it resolving to a parent `sp-theme` or `document` element itself. In this way, it is likely that you would benefit from leveraging an `sp-theme` element to create scope in your document for managing this custom content direction section of your page.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
When placing a `dir` attribute on an element built from `SpectrumMixin` before attaching it to the DOM, this will prevent it from resolving the text direction value to a parent `sp-theme` or `document` element. Elements applied to the page in this way will also NOT participate in observing any such elements, so their `dir` values will remain as initialized regardless of changes in other parts of your documents. If you choose to leverage this, be aware that any child (in both light DOM and shadow DOM) of this element will need to have a `dir` attribute applied as well if you do not want it resolving to a parent `sp-theme` or `document` element itself. In this way, it is likely that you would benefit from leveraging an `sp-theme` element to create scope in your document for managing this custom content direction section of your page.
Placing a `dir` attribute on an element built from `SpectrumMixin` before attaching it to the DOM will prevent it from resolving the text direction value to a parent `sp-theme` or `document` element. Elements applied to the page in this way will also NOT participate in observing any such elements, so their `dir` values will remain as initialized regardless of changes in other parts of your documents. If you choose to leverage this, be aware that any child (in both light DOM and shadow DOM) of this element will need to have a `dir` attribute applied as well if you do not want it resolving to a parent `sp-theme` or `document` element itself. In this way, it is likely that you would benefit from leveraging an `sp-theme` element to create scope in your document for managing this custom content direction section of your page.

@@ -1,11 +1,11 @@
## Description

`sp-splitbutton` delivers a
An `sp-split-button` surfaces an immediately envokable action via it's main button, as well as a list of alternative actions in its toggleable menu overlay. By default, any actions envoked from the overlay will replace the main action button. When leveraging `[type="more"]` the action will be envoked, but the main button will remain the action initally persribed by the implementor.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest changing envoke to invoke since it's more common (and I know my spell check is really wanting to change it as I'm trying to give this feedback). I did learn today that envoke is a valid alternate spelling though 🌈

Copy link
Collaborator

@adixon-adobe adixon-adobe left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@Westbrook Westbrook merged commit 189948b into spectrum-css-3 Aug 28, 2020
@Westbrook Westbrook deleted the westbrook/has branch August 28, 2020 18:00
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.

Review has... testing for slot generation.
3 participants