Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combobox open actions #20306

Merged
merged 33 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bfdb156
build: Added required files to listbox directory.
nielsr98 Jun 11, 2020
f8f6399
build: added listbox option directive and renamed listbox directive f…
nielsr98 Jun 11, 2020
b45c6df
build: Added required files to listbox directory.
nielsr98 Jun 11, 2020
966225f
build: added listbox option directive and renamed listbox directive f…
nielsr98 Jun 11, 2020
3ae5410
build: Added required files to listbox directory.
nielsr98 Jun 11, 2020
46f537e
build: added listbox option directive and renamed listbox directive f…
nielsr98 Jun 11, 2020
aa3abdb
build: Added required files to listbox directory.
nielsr98 Jun 11, 2020
6ea67c5
build: added listbox option directive and renamed listbox directive f…
nielsr98 Jun 11, 2020
db690d6
feat(dev-app/listbox): added cdk listbox example to the dev-app.
nielsr98 Jul 15, 2020
dea5915
fix(listbox): removed duplicate dep in dev-app build file.
nielsr98 Jul 22, 2020
97eee8b
fix(listbox): deleted unused files.
nielsr98 Aug 4, 2020
78bfc99
refactor(combobox): changed names and made coerceOpenActionProperty s…
nielsr98 Aug 10, 2020
3b955df
fix(combobox): updated syntax for casting.
nielsr98 Aug 10, 2020
2f31abf
refactor(combobox): changed casting syntax back.
nielsr98 Aug 10, 2020
ab86d96
fix(combobox): fixed trailing whitespace.
nielsr98 Aug 10, 2020
a3e6b05
refactor(combobox): improved coerceOpenActions function to handle whi…
nielsr98 Aug 12, 2020
9e06f83
fix(combobox): split the coerceOpenActions on comma or space.
nielsr98 Aug 12, 2020
7466008
feat(combobox): added aria-expanded and aria-owns traits.
nielsr98 Aug 12, 2020
ac7b942
refactor(combobox): minor refactor.
nielsr98 Aug 13, 2020
5d7f8d5
feat(combobox): added logic to close popup on click outside of combobox.
nielsr98 Aug 13, 2020
e0ddc23
test(combobox): added many tests for combobox open action features.
nielsr98 Aug 13, 2020
7c5b802
test(combobox): added back two failing tests, focus and sending input…
nielsr98 Aug 13, 2020
517b42b
refactor(combobox): further tests on focus.
nielsr98 Aug 13, 2020
60d0079
refactor(combobox): added tabindex to allow focusing on content, and …
nielsr98 Aug 13, 2020
64dd2f6
fix(combobox): removed separate coerceArray import.
nielsr98 Aug 13, 2020
7ffc07f
fix(combobox): lint errors.
nielsr98 Aug 13, 2020
1b28ca7
refactor(combobox): only throw error in coercing open action in dev m…
nielsr98 Aug 14, 2020
d04feb9
nit(combobox): removed whitespace.
nielsr98 Aug 14, 2020
4671b89
fix(combobox): removed unused imports.
nielsr98 Aug 14, 2020
75c7825
feat(combobox): added combobox popup directive to handle registering …
nielsr98 Aug 14, 2020
065adf1
nit(combobox): changed double quotes to single quotes.
nielsr98 Aug 14, 2020
ddff626
nit(combobox): changed class names and parameter types.
nielsr98 Aug 14, 2020
4ce24aa
fix(combobox): changed import to relative import.
nielsr98 Aug 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cdk-experimental/combobox/BUILD.bazel
Expand Up @@ -25,6 +25,7 @@ ng_test_library(
),
deps = [
":combobox",
"//src/cdk/keycodes",
"//src/cdk/testing/private",
"@npm//@angular/platform-browser",
],
Expand Down
3 changes: 2 additions & 1 deletion src/cdk-experimental/combobox/combobox-module.ts
Expand Up @@ -10,8 +10,9 @@ import {NgModule} from '@angular/core';
import {OverlayModule} from '@angular/cdk/overlay';
import {CdkCombobox} from './combobox';
import {CdkComboboxPanel} from './combobox-panel';
import {CdkComboboxPopup} from './combobox-popup';

const EXPORTED_DECLARATIONS = [CdkCombobox, CdkComboboxPanel];
const EXPORTED_DECLARATIONS = [CdkCombobox, CdkComboboxPanel, CdkComboboxPopup];
@NgModule({
imports: [OverlayModule],
exports: EXPORTED_DECLARATIONS,
Expand Down
15 changes: 13 additions & 2 deletions src/cdk-experimental/combobox/combobox-panel.ts
Expand Up @@ -12,6 +12,9 @@ import {Directive, TemplateRef} from '@angular/core';
import {Subject} from 'rxjs';

@Directive({
host: {
'class': 'cdk-combobox-panel'
},
selector: 'ng-template[cdkComboboxPanel]',
exportAs: 'cdkComboboxPanel',
})
Expand All @@ -24,13 +27,21 @@ export class CdkComboboxPanel<T = unknown> {
contentId: string = '';
contentType: AriaHasPopupValue;

constructor(readonly _templateRef: TemplateRef<unknown>) {}
constructor(
readonly _templateRef: TemplateRef<unknown>
) {}

/** Tells the parent combobox to closet he panel and sends back the content value. */
/** Tells the parent combobox to close the panel and sends back the content value. */
closePanel(data?: T) {
this.valueUpdated.next(data);
}

// TODO: instead of using a focus function, potentially use cdk/a11y focus trapping
focusContent() {
// TODO: Use an injected document here
document.getElementById(this.contentId)?.focus();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a TODO here to use an injected document and a separate TODO to potentially switch this to use focus trapping from cdk/a11y

}

/** Registers the content's id and the content type with the panel. */
_registerContent(contentId: string, contentType: AriaHasPopupValue) {
this.contentId = contentId;
Expand Down
55 changes: 55 additions & 0 deletions src/cdk-experimental/combobox/combobox-popup.ts
@@ -0,0 +1,55 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Directive, Inject, InjectionToken, Input, OnInit, Optional} from '@angular/core';
import {AriaHasPopupValue, CdkComboboxPanel} from './combobox-panel';

export const PANEL = new InjectionToken<CdkComboboxPanel>('CdkComboboxPanel');

let nextId = 0;

@Directive({
selector: '[cdkComboboxPopup]',
exportAs: 'cdkComboboxPopup',
host: {
'class': 'cdk-combobox-popup',
'[attr.role]': 'role',
'[id]': 'id',
'tabindex': '-1'
}
})
export class CdkComboboxPopup<T = unknown> implements OnInit {
@Input()
get role(): AriaHasPopupValue {
return this._role;
}
set role(value: AriaHasPopupValue) {
this._role = value;
}
private _role: AriaHasPopupValue = 'dialog';

@Input() id = `cdk-combobox-popup-${nextId++}`;

@Input('parentPanel') private readonly _explicitPanel: CdkComboboxPanel;

constructor(
@Optional() @Inject(PANEL) readonly _parentPanel?: CdkComboboxPanel<T>,
) { }

ngOnInit() {
this.registerWithPanel();
}

registerWithPanel(): void {
if (this._parentPanel === null || this._parentPanel === undefined) {
this._explicitPanel._registerContent(this.id, this._role);
} else {
this._parentPanel._registerContent(this.id, this._role);
}
}
}