chore: SlotRerenderObject aligned with reactive cycle (docs + changelog) (#1999)
This commit is contained in:
parent
d2de984f0b
commit
6893421779
6 changed files with 18 additions and 14 deletions
7
.changeset/slot-mixin-reactivity-align.md
Normal file
7
.changeset/slot-mixin-reactivity-align.md
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
'@lion/ui': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(ui): align light dom with internal [reactivity cycle of LitElement/ReactiveElement](https://lit.dev/docs/components/lifecycle/#reactive-update-cycle).
|
||||||
|
Since light dom render is now aligned inside `update` instead of `updated` (like it already was for shadow dom),
|
||||||
|
we can rely on the fact that all dom (light and shadow) has rendered inside our `updated` loop.
|
||||||
|
|
@ -74,7 +74,6 @@ class MyAccessibleControl extends SlotMixin(LitElement) {
|
||||||
'rerenderable-slot': () => {
|
'rerenderable-slot': () => {
|
||||||
return {
|
return {
|
||||||
template: html`<w-c>${this.litProperty}</w-c>`,
|
template: html`<w-c>${this.litProperty}</w-c>`,
|
||||||
afterRender: () => { /** sync some state */ },
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// undefined (conditional slot)
|
// undefined (conditional slot)
|
||||||
|
|
@ -105,14 +104,11 @@ A `SlotRerenderObject` looks like this:
|
||||||
```ts
|
```ts
|
||||||
{
|
{
|
||||||
template: TemplateResult;
|
template: TemplateResult;
|
||||||
afterRender?: Function;
|
}
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
It is meant for complex templates that need rerenders. Normally - when rendering into shadow dom via `LitElement.render` - we get rerenders
|
It is meant for complex templates that need rerenders and are bound to the [reactive update cycle](https://lit.dev/docs/components/lifecycle/#reactive-update-cycle). The same lifecycle hooks (for instance `updated`) can be used as with templates rendered to the shadow root (via the regular render function).
|
||||||
"for free" via [property effects](https://lit.dev/docs/components/properties/#when-properties-change).
|
For rerendering to work predictably (no focus and other interaction issues), the slot will be created within a wrapper div.
|
||||||
When we configure `SlotFunctionResult` to return a `SlotRerenderObject`, we get the same behavior for light dom.
|
|
||||||
For this rerendering to work predictably (no focus and other interaction issues), the slot will be created with a wrapper div.
|
|
||||||
|
|
||||||
### Undefined
|
### Undefined
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ const SlotMixinImplementation = superclass =>
|
||||||
slotName,
|
slotName,
|
||||||
shouldRerender: true,
|
shouldRerender: true,
|
||||||
});
|
});
|
||||||
|
// TODO: this is deprecated, remove later
|
||||||
slotFunctionResult.afterRender?.();
|
slotFunctionResult.afterRender?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -383,7 +383,7 @@ describe('SlotMixin', () => {
|
||||||
expect(slot.tagName).to.equal('SPAN');
|
expect(slot.tagName).to.equal('SPAN');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports afterRender logic (type "{ template:TemplateResults; afterRender: Function}" )', async () => {
|
it('supports (deprecated) afterRender logic (type "{ template:TemplateResults; afterRender: Function}" )', async () => {
|
||||||
let varThatProvesAfterRenderIsCalled = 'not called';
|
let varThatProvesAfterRenderIsCalled = 'not called';
|
||||||
|
|
||||||
const tag = defineCE(
|
const tag = defineCE(
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,10 @@ import { TemplateResult, LitElement } from 'lit';
|
||||||
*/
|
*/
|
||||||
export type SlotRerenderObject = {
|
export type SlotRerenderObject = {
|
||||||
template: TemplateResult;
|
template: TemplateResult;
|
||||||
/* Add logic that will be performed after the render */
|
/**
|
||||||
|
* Add logic that will be performed after the render
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
afterRender?: Function;
|
afterRender?: Function;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,6 @@ export class LionInputTelDropdown extends LionInputTel {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
template: templates.dropdown(this._templateDataDropdown),
|
template: templates.dropdown(this._templateDataDropdown),
|
||||||
afterRender: this.__syncRegionWithDropdown,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -274,9 +273,7 @@ export class LionInputTelDropdown extends LionInputTel {
|
||||||
updated(changedProperties) {
|
updated(changedProperties) {
|
||||||
super.updated(changedProperties);
|
super.updated(changedProperties);
|
||||||
|
|
||||||
if (changedProperties.has('activeRegion')) {
|
|
||||||
this.__syncRegionWithDropdown();
|
this.__syncRegionWithDropdown();
|
||||||
}
|
|
||||||
|
|
||||||
if (changedProperties.has('disabled') || changedProperties.has('readOnly')) {
|
if (changedProperties.has('disabled') || changedProperties.has('readOnly')) {
|
||||||
if (this.disabled || this.readOnly) {
|
if (this.disabled || this.readOnly) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue