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

feat(autocomplete): add autocomplete panel toggling #2452

Merged
merged 1 commit into from
Jan 7, 2017

Conversation

kara
Copy link
Contributor

@kara kara commented Dec 28, 2016

The autocomplete is a WIP. To keep PRs small, this PR only implements the panel toggling behavior. Future PRs will implement forms integration, positioning, and keyboard events.

r: @jelbourn

@kara kara requested a review from jelbourn December 28, 2016 20:46
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 28, 2016
@kara kara force-pushed the autocomplete-pr branch 4 times, most recently from 127d3a5 to 7e5ad05 Compare January 4, 2017 00:49
@kara kara force-pushed the autocomplete-pr branch 2 times, most recently from 5ca9cec to 3ab5fad Compare January 4, 2017 19:50
}

/** Destroys the autocomplete suggestion panel. */
destroyPanel(): void {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be an internal method? (Would the user ever have a reason to call it?)

Copy link
Contributor Author

@kara kara Jan 4, 2017

Choose a reason for hiding this comment

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

Hmm, someone could possibly call it if they knew that the autocomplete wouldn't be used anymore for some reason and they had a ton of options. But I don't really think it's that useful. Removing. We can always add to the API later if needed

private _overlayRef: OverlayRef;
private _portal: TemplatePortal;
private _panelOpen: boolean = false;
private _closeWatcher: Subscription;
Copy link
Member

Choose a reason for hiding this comment

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

_panelClosures? I'd like to avoid the term "watchers" to avoid confusion with the Angular 1 concept.

Also add a description comment for this since it's not immediately obvious what it's for.

* This method will close the panel if it receives a selection event from any of the options
* or a click on the backdrop.
*/
private _watchForClose() {
Copy link
Member

Choose a reason for hiding this comment

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

Different name that doesn't use watch?

* the backdrop click into one observable.
*/
private _getOptionObs(): Observable<any>[] {
return this.autocomplete.options.map((option) => option.onSelect);
Copy link
Member

Choose a reason for hiding this comment

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

Don't need parens around option

* of their selection events. This map will be used to merge the option events and
* the backdrop click into one observable.
*/
private _getOptionObs(): Observable<any>[] {
Copy link
Member

Choose a reason for hiding this comment

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

Make this a getter called optionSelections? Then the description is just something like

/** Stream of autocomplete option selections. */

*/
private _watchForClose() {
// TODO(kara): add tab event watcher when adding keyboard events
this._closeWatcher = Observable.merge(...this._getOptionObs(), this._overlayRef.backdropClick())
Copy link
Member

Choose a reason for hiding this comment

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

Won't this get stale is more options are added while the panel is open?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is addressed in the next PR, #2516, when filtering is added (and the options are often changing)

@Input('mdAutocomplete') autocomplete: MdAutocomplete;

constructor(private _element: ElementRef, private _overlay: Overlay,
private _vcr: ViewContainerRef) {}
Copy link
Member

Choose a reason for hiding this comment

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

_viewContainerRef

@kara
Copy link
Contributor Author

kara commented Jan 4, 2017

@jelbourn Comments addressed!

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

Just a last few things I noticed


if (!this._overlayRef.hasAttached()) {
this._overlayRef.attach(this._portal);
this._panelClosingSub = this.panelClosingActions.subscribe(() => this.closePanel());
Copy link
Member

Choose a reason for hiding this comment

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

_closingActionsSubscription?


// remove body padding to keep consistent cross-browser
document.body.style.padding = '0';
document.body.style.margin = '0';
Copy link
Member

Choose a reason for hiding this comment

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

I don't think these styles are necessary any more since 38700e0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right! Forgot to update.

dispatchEvent('focus', trigger);
fixture.detectChanges();

const backdrop = <HTMLElement>overlayContainerElement.querySelector('.cdk-overlay-backdrop');
Copy link
Member

Choose a reason for hiding this comment

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

Prefer as HTMLElement
(here and elsewhere)

@import '../style/menu-common';
@import '../a11y/a11y';

@mixin md-option() {
Copy link
Member

Choose a reason for hiding this comment

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

Add comment explaining what this mixin is for (i.e., used by both select and autocomplete)

@kara
Copy link
Contributor Author

kara commented Jan 4, 2017

@jelbourn Updated

@jelbourn
Copy link
Member

jelbourn commented Jan 5, 2017

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Jan 5, 2017
@kara kara force-pushed the autocomplete-pr branch 5 times, most recently from 17d809d to 5e42f71 Compare January 6, 2017 19:55
@kara kara merged commit d4ab3d3 into angular:master Jan 7, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants