Skip to content

Commit 5360c5a

Browse files
authored
fix: improve rendering for lion-select-rich by lit cache (#2566)
1 parent 07f7ea6 commit 5360c5a

File tree

4 files changed

+400
-4
lines changed

4 files changed

+400
-4
lines changed

.changeset/plenty-deers-clean.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lion/ui': patch
3+
---
4+
5+
[select-rich] improve rendering by the `lit` `cache` function

docs/components/select-rich/use-cases.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,24 @@ import '@lion/ui/define/lion-option.js';
2020

2121
## Model value
2222

23+
### Setting model by the `modelValue` property
24+
2325
You can set the full `modelValue` for each option, which includes the checked property for whether it is checked or not.
2426

2527
```html
26-
<lion-option .modelValue="${{ value: 'red', checked: false }}">Red</lion-option>
28+
<lion-option .modelValue="${ value: 'red', checked: false }">Red</lion-option>
29+
```
30+
31+
Note, when rendering with the help of the `cache` function imported from `lit/directives/cache.js`, setting model by
32+
the `modelValue` property is not fully supported. Consider setting the model by the `choiceValue` property instead. See [Setting model by `choiceValue` property](#setting-model-by-the-choicevalue-property) for more details.
33+
34+
### Setting model by the `choiceValue` property
35+
36+
You can set the model for each option, providing the value and the checked status as follows:
37+
38+
```html
39+
<lion-option .choiceValue="${'red'}" checked>Red</lion-option>
40+
<lion-option .choiceValue="${'blue'}">Blue</lion-option>
2741
```
2842

2943
## Options with HTML

packages/ui/components/select-rich/src/LionSelectRich.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ export class LionSelectRich extends SlotMixin(ScopedElementsMixin(OverlayMixin(L
146146

147147
connectedCallback() {
148148
super.connectedCallback();
149-
this._invokerNode.selectedElement =
150-
this.formElements[/** @type {number} */ (this.checkedIndex)];
149+
this.registrationComplete.then(() => {
150+
this._invokerNode.selectedElement =
151+
this.formElements[/** @type {number} */ (this.checkedIndex)];
152+
});
151153

152154
this._invokerNode.hostElement = this;
153155

0 commit comments

Comments
 (0)