Skip to content

Commit cecd197

Browse files
committed
feat(combobox): added combobox popup directive to handle registering panel content with panel.
1 parent 311b317 commit cecd197

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import {NgModule} from '@angular/core';
1010
import {OverlayModule} from '@angular/cdk/overlay';
1111
import {CdkCombobox} from './combobox';
1212
import {CdkComboboxPanel} from './combobox-panel';
13+
import {CdkComboboxPopup} from "./combobox-popup";
1314

14-
const EXPORTED_DECLARATIONS = [CdkCombobox, CdkComboboxPanel];
15+
const EXPORTED_DECLARATIONS = [CdkCombobox, CdkComboboxPanel, CdkComboboxPopup];
1516
@NgModule({
1617
imports: [OverlayModule],
1718
exports: EXPORTED_DECLARATIONS,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 nextId = 0;
15+
16+
@Directive({
17+
selector: '[cdkComboboxPopup]',
18+
exportAs: 'cdkComboboxPopup',
19+
host: {
20+
'class': 'cdk-combobox-popup',
21+
'[attr.role]': 'role',
22+
'[id]': 'id',
23+
'tabindex': '-1'
24+
}
25+
})
26+
export class CdkComboboxPopup<T = unknown> implements OnInit {
27+
@Input()
28+
get role(): AriaHasPopupValue {
29+
return this._role;
30+
}
31+
set role(value: AriaHasPopupValue) {
32+
this._role = value;
33+
}
34+
private _role: AriaHasPopupValue = 'dialog';
35+
36+
@Input() id = `cdk-combobox-popup-${nextId++}`;
37+
38+
@Input('parentPanel') private readonly _explicitPanel: CdkComboboxPanel;
39+
40+
constructor(
41+
@Optional() @Inject(PANEL) readonly _parentPanel?: CdkComboboxPanel<T>,
42+
) { }
43+
44+
ngOnInit() {
45+
this.registerWithPanel();
46+
}
47+
48+
registerWithPanel(): void {
49+
if (this._parentPanel === null || this._parentPanel === undefined) {
50+
this._explicitPanel._registerContent(this.id, this._role);
51+
} else {
52+
this._parentPanel._registerContent(this.id, this._role);
53+
}
54+
}
55+
}

src/cdk-experimental/combobox/combobox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class CdkCombobox<T = unknown> implements OnDestroy, AfterContentInit {
116116
const {keyCode} = event;
117117

118118
if (keyCode === DOWN_ARROW && this._openActions.indexOf('downKey') !== -1) {
119-
this.toggle();
119+
this.open();
120120
} else if (keyCode === ESCAPE) {
121121
event.preventDefault();
122122
this.close();

src/cdk-experimental/combobox/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
export * from './combobox-module';
1010
export * from './combobox';
1111
export * from './combobox-panel';
12+
export * from './combobox-popup';

0 commit comments

Comments
 (0)