Skip to content

Commit 0712e77

Browse files
committed
feat(dev-app/listbox): added cdk listbox example to the dev-app.
1 parent 5790b14 commit 0712e77

File tree

9 files changed

+101
-1
lines changed

9 files changed

+101
-1
lines changed

src/cdk-experimental/listbox/listbox.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ let nextId = 0;
3737
'[attr.tabindex]': '_getTabIndex()',
3838
'[attr.aria-disabled]': '_isInteractionDisabled()',
3939
'[class.cdk-option-disabled]': '_isInteractionDisabled()',
40-
'[class.cdk-option-active]': '_active'
40+
'[class.cdk-option-active]': '_active',
41+
'[class.cdk-option-selected]': '_selected'
4142
}
4243
})
4344
export class CdkOption implements ListKeyManagerOption, Highlightable {
@@ -171,6 +172,7 @@ export class CdkOption implements ListKeyManagerOption, Highlightable {
171172
host: {
172173
'role': 'listbox',
173174
'(keydown)': '_keydown($event)',
175+
'[attr.tabindex]': 'tabIndex',
174176
'[attr.aria-disabled]': '_disabled',
175177
'[attr.aria-multiselectable]': '_multiple',
176178
'[attr.aria-activedescendant]': '_getAriaActiveDescendant()'
@@ -180,6 +182,7 @@ export class CdkListbox implements AfterContentInit, OnDestroy, OnInit {
180182

181183
_listKeyManager: ActiveDescendantKeyManager<CdkOption>;
182184
_selectionModel: SelectionModel<CdkOption>;
185+
tabIndex = 0;
183186

184187
readonly optionSelectionChanges: Observable<OptionSelectionChangeEvent> = defer(() => {
185188
const options = this._options;

src/dev-app/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ng_module(
2424
"//src/dev-app/button-toggle",
2525
"//src/dev-app/card",
2626
"//src/dev-app/cdk-experimental-menu",
27+
"//src/dev-app/cdk-experimental-listbox",
2728
"//src/dev-app/checkbox",
2829
"//src/dev-app/chips",
2930
"//src/dev-app/clipboard",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
load("//tools:defaults.bzl", "ng_module")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
ng_module(
6+
name = "cdk-experimental-listbox",
7+
srcs = glob(["**/*.ts"]),
8+
assets = [
9+
"cdk-listbox-demo.html",
10+
"cdk-listbox-demo.css",
11+
],
12+
deps = [
13+
"//src/cdk-experimental/listbox",
14+
"@npm//@angular/router",
15+
],
16+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {NgModule} from '@angular/core';
10+
import {CommonModule} from '@angular/common';
11+
import {RouterModule} from '@angular/router';
12+
import {CdkListboxModule} from "@angular/cdk-experimental/listbox";
13+
14+
import {CdkListboxDemo} from './cdk-listbox-demo';
15+
16+
@NgModule({
17+
imports: [
18+
CdkListboxModule,
19+
CommonModule,
20+
RouterModule.forChild([{path: '', component: CdkListboxDemo}]),
21+
],
22+
declarations: [CdkListboxDemo],
23+
})
24+
export class CdkListboxDemoModule {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.example-listbox {
2+
list-style-type: none;
3+
border: 1px solid black;
4+
width: fit-content;
5+
cursor: default;
6+
padding: 0px;
7+
}
8+
9+
.cdk-option-selected {
10+
background: cornflowerblue;
11+
}
12+
13+
.cdk-option-active {
14+
background: lightgrey;
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<ul cdkListbox class="example-listbox" [multiple]="multiSelectable" [useActiveDescendant]="activeDescendant">
2+
<li class="example-option" cdkOption>Apple</li>
3+
<li cdkOption>Orange</li>
4+
<li cdkOption>Grapefruit</li>
5+
<li cdkOption>Peach</li>
6+
</ul>
7+
8+
<button (click)="toggleMultiple()">Toggle Multiple</button>
9+
<br>
10+
<button (click)="toggleActiveDescendant()">Toggle Active Descendant</button>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Component} from '@angular/core';
10+
11+
@Component({
12+
templateUrl: 'cdk-listbox-demo.html',
13+
styleUrls: ['cdk-listbox-demo.css'],
14+
})
15+
export class CdkListboxDemo {
16+
multiSelectable = false;
17+
activeDescendant = true;
18+
19+
toggleMultiple() {
20+
this.multiSelectable = !this.multiSelectable;
21+
}
22+
23+
toggleActiveDescendant() {
24+
this.activeDescendant = !this.activeDescendant;
25+
}
26+
}

src/dev-app/dev-app/dev-app-layout.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class DevAppLayout {
2929
{name: 'Button Toggle', route: '/button-toggle'},
3030
{name: 'Button', route: '/button'},
3131
{name: 'Card', route: '/card'},
32+
{name: 'Cdk Experimental Listbox', route: '/cdk-experimental-listbox'},
3233
{name: 'Cdk Experimental Menu', route: '/cdk-experimental-menu'},
3334
{name: 'Checkbox', route: '/checkbox'},
3435
{name: 'Chips', route: '/chips'},

src/dev-app/dev-app/routes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const DEV_APP_ROUTES: Routes = [
2828
loadChildren: 'button-toggle/button-toggle-demo-module#ButtonToggleDemoModule'
2929
},
3030
{path: 'card', loadChildren: 'card/card-demo-module#CardDemoModule'},
31+
{
32+
path: 'cdk-experimental-listbox',
33+
loadChildren: 'cdk-experimental-listbox/cdk-listbox-demo-module#CdkListboxDemoModule'
34+
},
3135
{
3236
path: 'cdk-experimental-menu',
3337
loadChildren: 'cdk-experimental-menu/cdk-menu-demo-module#CdkMenuDemoModule'

0 commit comments

Comments
 (0)