File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
src/cdk-experimental/listbox Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 77 */
88
99import {
10+ AfterViewInit ,
1011 booleanAttribute ,
1112 computed ,
1213 contentChildren ,
@@ -29,9 +30,9 @@ import {_IdGenerator} from '@angular/cdk/a11y';
2930 *
3031 * ```html
3132 * <ul cdkListbox>
32- * <li cdkOption>Item 1</li>
33- * <li cdkOption>Item 2</li>
34- * <li cdkOption>Item 3</li>
33+ * <li [value]="1" cdkOption>Item 1</li>
34+ * <li [value]="2" cdkOption>Item 2</li>
35+ * <li [value]="3" cdkOption>Item 3</li>
3536 * </ul>
3637 * ```
3738 */
@@ -50,7 +51,7 @@ import {_IdGenerator} from '@angular/cdk/a11y';
5051 '(pointerdown)' : 'pattern.onPointerdown($event)' ,
5152 } ,
5253} )
53- export class CdkListbox < V > {
54+ export class CdkListbox < V > implements AfterViewInit {
5455 /** The directionality (LTR / RTL) context for the application (or a subtree of it). */
5556 private readonly _directionality = inject ( Directionality ) ;
5657
@@ -101,6 +102,16 @@ export class CdkListbox<V> {
101102 items : this . items ,
102103 textDirection : this . textDirection ,
103104 } ) ;
105+
106+ ngAfterViewInit ( ) {
107+ if ( this . value ( ) . length ) {
108+ // TODO(wagnermaciel): Write a test case specifically for this.
109+ const item = this . items ( ) . find ( item => this . value ( ) . includes ( item . value ( ) ) ) ;
110+ if ( item ) {
111+ this . activeIndex . set ( item . index ( ) ) ;
112+ }
113+ }
114+ }
104115}
105116
106117/** A selectable option in a CdkListbox. */
You can’t perform that action at this time.
0 commit comments