|
7 | 7 |
|
8 | 8 | import { html, TemplateResult } from 'lit'; |
9 | 9 | import { property, state } from 'lit/decorators.js'; |
| 10 | +import { ifDefined } from 'lit/directives/if-defined.js'; |
10 | 11 | import { MgtTemplatedComponent, mgtHtml, customElement } from '@microsoft/mgt-element'; |
11 | 12 | import { strings } from './strings'; |
12 | 13 | import { fluentCombobox, fluentOption } from '@fluentui/web-components'; |
@@ -146,6 +147,19 @@ export class MgtPicker extends MgtTemplatedComponent { |
146 | 147 | }) |
147 | 148 | public cacheInvalidationPeriod = 0; |
148 | 149 |
|
| 150 | + /** |
| 151 | + * Sets the currently selected value for the picker |
| 152 | + * Must be present as an option in the supplied data returned from the the underlying graph query |
| 153 | + * |
| 154 | + * @type {string} |
| 155 | + * @memberof MgtPicker |
| 156 | + */ |
| 157 | + @property({ |
| 158 | + attribute: 'selected-value', |
| 159 | + type: String |
| 160 | + }) |
| 161 | + public selectedValue: string; |
| 162 | + |
149 | 163 | private isRefreshing: boolean; |
150 | 164 |
|
151 | 165 | @state() private response: Entity[]; |
@@ -212,7 +226,9 @@ export class MgtPicker extends MgtTemplatedComponent { |
212 | 226 | */ |
213 | 227 | protected renderPicker(): TemplateResult { |
214 | 228 | return mgtHtml` |
215 | | - <fluent-combobox part="picker" class="picker" id="combobox" autocomplete="list" placeholder=${this.placeholder}> |
| 229 | + <fluent-combobox current-value=${ifDefined( |
| 230 | + this.selectedValue |
| 231 | + )} part="picker" class="picker" id="combobox" autocomplete="list" placeholder=${this.placeholder}> |
216 | 232 | ${this.response.map( |
217 | 233 | item => html` |
218 | 234 | <fluent-option value=${item.id} @click=${(e: MouseEvent) => this.handleClick(e, item)}> ${ |
|
0 commit comments