Skip to content

Commit f718821

Browse files
authored
feat(combobox): add to dev-app (#20276)
Combobox dev app * build: Added required files to listbox directory. * build: added listbox option directive and renamed listbox directive files. * build: Added required files to listbox directory. * build: added listbox option directive and renamed listbox directive files. * build: Added required files to listbox directory. * build: added listbox option directive and renamed listbox directive files. * build: Added required files to listbox directory. * build: added listbox option directive and renamed listbox directive files. * feat(dev-app/listbox): added cdk listbox example to the dev-app. * fix(listbox): removed duplicate dep in dev-app build file. * fix(listbox): deleted unused files. * feat(combobox): added all basic features to combobox and combobox panel, and some tests. * fix(combobox): fixed import path for combobox panel. * refactor(combobox): changed names and made coerceOpenActionProperty simpler for this PR. * fix(combobox): updated syntax for casting. * refactor(combobox): changed casting syntax back. * fix(combobox): fixed trailing whitespace. * feat(combobox): added combobox to dev app. * refactor(combobox): removed commented out import and fixed the name of an input reference in the combobox spec. * fix(combobox): removed duplicate import. * nit(combobox): removed console logs. * refactor(combobox): removed unused panel test file. * refactor(combobox): used lightweight injection token for grabbing parent panel. * nit(combobox): formatted build file. * refactor(combobox): removed unused imports and fixed long line length. * refactor(combobox): reduced the functions of the panel directive and fixed indent sizes.
1 parent df516c5 commit f718821

File tree

11 files changed

+130
-4
lines changed

11 files changed

+130
-4
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
/src/dev-app/mdc-autocomplete/** @crisbeto
148148
/src/dev-app/button/** @jelbourn
149149
/src/dev-app/card/** @jelbourn
150+
/src/dev-app/cdk-experimental-combobox/** @jelbourn @nielsr98
150151
/src/dev-app/cdk-experimental-listbox/** @jelbourn @nielsr98
151152
/src/dev-app/cdk-experimental-menu/** @jelbourn @andy9775
152153
/src/dev-app/checkbox/** @jelbourn @devversion

src/cdk-experimental/combobox/combobox.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Combobox', () => {
7777
template: `
7878
<button cdkCombobox #toggleCombobox class="example-combobox"
7979
[cdkComboboxTriggerFor]="panel"
80-
[openAction]="'focus'">
80+
[openActions]="'focus'">
8181
No Value
8282
</button>
8383

src/cdk-experimental/combobox/combobox.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ export class CdkCombobox<T = unknown> implements OnDestroy, AfterContentInit {
5858
private _disabled: boolean = false;
5959

6060
@Input()
61-
get openAction(): OpenAction[] {
61+
get openActions(): OpenAction[] {
6262
return this._openActions;
6363
}
64-
set openAction(action: OpenAction[]) {
64+
set openActions(action: OpenAction[]) {
6565
this._openActions = this._coerceOpenActionProperty(action);
6666
}
6767
private _openActions: OpenAction[] = ['click'];
@@ -143,6 +143,13 @@ export class CdkCombobox<T = unknown> implements OnDestroy, AfterContentInit {
143143

144144
if (valueChanged) {
145145
this.panelValueChanged.emit(value);
146+
this._setTextContent(value);
147+
}
148+
}
149+
150+
private _setTextContent(content: T) {
151+
if (typeof content === 'string') {
152+
this._elementRef.nativeElement.textContent = `${content}`;
146153
}
147154
}
148155

@@ -189,6 +196,6 @@ export class CdkCombobox<T = unknown> implements OnDestroy, AfterContentInit {
189196
return actions;
190197
}
191198

192-
static ngAcceptInputType_disabled: BooleanInput;
193199
static ngAcceptInputType_openActions: OpenActionInput;
200+
static ngAcceptInputType_disabled: BooleanInput;
194201
}

src/dev-app/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ng_module(
2323
"//src/dev-app/button",
2424
"//src/dev-app/button-toggle",
2525
"//src/dev-app/card",
26+
"//src/dev-app/cdk-experimental-combobox",
2627
"//src/dev-app/cdk-experimental-listbox",
2728
"//src/dev-app/cdk-experimental-menu",
2829
"//src/dev-app/checkbox",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("//tools:defaults.bzl", "ng_module")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
ng_module(
6+
name = "cdk-experimental-combobox",
7+
srcs = glob(["**/*.ts"]),
8+
assets = [
9+
"cdk-combobox-demo.html",
10+
],
11+
deps = [
12+
"//src/cdk-experimental/combobox",
13+
"@npm//@angular/router",
14+
],
15+
)
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 {CdkComboboxModule} from '@angular/cdk-experimental/combobox';
13+
import {CdkComboboxDemo} from './cdk-combobox-demo';
14+
import {PanelContent} from './panel-content';
15+
16+
@NgModule({
17+
imports: [
18+
CdkComboboxModule,
19+
CommonModule,
20+
RouterModule.forChild([{path: '', component: CdkComboboxDemo}]),
21+
],
22+
declarations: [CdkComboboxDemo, PanelContent],
23+
})
24+
export class CdkComboboxDemoModule {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Toggle Combobox!
2+
<br>
3+
<button cdkCombobox class="example-combobox" [cdkComboboxTriggerFor]="panel" [openActions]="'toggle'">
4+
No Value
5+
</button>
6+
7+
<ng-template cdkComboboxPanel #panel="cdkComboboxPanel">
8+
<div panelContent [parentPanel]="panel">
9+
<input #input>
10+
<button (click)="panel.closePanel(input.value)">Apply</button>
11+
</div>
12+
</ng-template>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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-combobox-demo.html',
13+
})
14+
export class CdkComboboxDemo {
15+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 {Directive, Inject, InjectionToken, Input, OnInit, Optional} from '@angular/core';
10+
import {AriaHasPopupValue, CdkComboboxPanel} from '@angular/cdk-experimental/combobox';
11+
12+
export const PANEL = new InjectionToken<CdkComboboxPanel>('CdkComboboxPanel');
13+
14+
let id = 0;
15+
16+
@Directive({
17+
selector: '[panelContent]',
18+
exportAs: 'panelContent',
19+
host: {
20+
'role': 'role',
21+
'[id]': 'dialogId'
22+
}
23+
})
24+
export class PanelContent<V> implements OnInit {
25+
26+
dialogId = `dialog-${id++}`;
27+
role = 'dialog';
28+
29+
@Input('parentPanel') private readonly _explicitPanel: CdkComboboxPanel;
30+
31+
constructor(
32+
@Optional() @Inject(PANEL) readonly _parentPanel?: CdkComboboxPanel<V>,
33+
) { }
34+
35+
ngOnInit() {
36+
this.registerWithPanel();
37+
}
38+
39+
registerWithPanel(): void {
40+
if (this._parentPanel === null || this._parentPanel === undefined) {
41+
this._explicitPanel._registerContent(this.dialogId, this.role as AriaHasPopupValue);
42+
} else {
43+
this._parentPanel._registerContent(this.dialogId, this.role as AriaHasPopupValue);
44+
}
45+
}
46+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class DevAppLayout {
3333
{name: 'Button Toggle', route: '/button-toggle'},
3434
{name: 'Button', route: '/button'},
3535
{name: 'Card', route: '/card'},
36+
{name: 'Cdk Experimental Combobox', route: '/cdk-experimental-combobox'},
3637
{name: 'Cdk Experimental Listbox', route: '/cdk-experimental-listbox'},
3738
{name: 'Cdk Experimental Menu', route: '/cdk-experimental-menu'},
3839
{name: 'Checkbox', route: '/checkbox'},

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-combobox',
33+
loadChildren: 'cdk-experimental-combobox/cdk-combobox-demo-module#CdkComboboxDemoModule'
34+
},
3135
{
3236
path: 'cdk-experimental-listbox',
3337
loadChildren: 'cdk-experimental-listbox/cdk-listbox-demo-module#CdkListboxDemoModule'

0 commit comments

Comments
 (0)