-
Notifications
You must be signed in to change notification settings - Fork 205
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
Conversation
76ceb7d
to
df31b8e
Compare
a837c71
to
ad7a4a7
Compare
4063d8f
to
9849083
Compare
06465be
to
86c6884
Compare
ad7a4a7
to
c6f5efd
Compare
86c6884
to
6ae6def
Compare
packages/shared/README.md
Outdated
### 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. |
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.
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'); |
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.
const assignedNodesList = Symbol('assinedNodes'); | |
const assignedNodesList = Symbol('assignedNodes'); |
packages/base/README.md
Outdated
@@ -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. |
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.
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. |
c6f5efd
to
cf19168
Compare
6ae6def
to
5e42cbe
Compare
cf19168
to
26c50f6
Compare
5e42cbe
to
309d17c
Compare
@@ -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. |
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.
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 🌈
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.
Looks good to me.
Description
main
and the keyboard helper work that is there.@spectrum-web-components/base
as the only entry tolit-element
andlit-html
.lit-html
/lit-element
lit-element
to power the below...Querying light DOM children to resolve template content is not reactive:
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 ofhasFooter
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 leveragequeryAssignedNodes
. I see the possibility of merging the two observer mixins in some way in the future, but for now the use ofSymbol()
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?
Types of changes
Checklist: