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

fix(Autocomplete): fix for bug when clicking another instance #1722

Merged
merged 2 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import {
Component,
OnInit,
AfterViewInit,
ViewChild,
} from '@angular/core';
import {
FormControl,
Validators,
} from '@angular/forms';
import { TsChipCollectionComponent } from '@terminus/ui/chip';
import {
BehaviorSubject,
Observable,
} from 'rxjs';
import { map } from 'rxjs/operators';
import { TsChipCollectionComponent } from '@terminus/ui/chip';


export interface State {
Expand All @@ -29,7 +27,6 @@ export interface State {
export class AutocompleteComponent {
@ViewChild(TsChipCollectionComponent, { static: false })
public list!: TsChipCollectionComponent;

states: State[] = [
{
name: 'Arkansas',
Expand Down Expand Up @@ -124,7 +121,6 @@ export class AutocompleteComponent {
singleStateCtrl = new FormControl([this.states[4]], [Validators.required]);

constructor() {

this.filteredStates = this.myQuery$
.pipe(
map(state => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ export class TsAutocompleteTriggerDirective<ValueType = string> implements Contr
this.optionSelections,
this.autocompletePanel.keyManager.tabOut.pipe(filter(() => this.overlayAttached)),
this.closeKeyEventStream,
this.getOutsideClickStream(),
this.overlayRef ? this.overlayRef.detachments().pipe(filter(() => this.overlayAttached)) : of(),
this.overlayRef.backdropClick(),
).pipe(
// Normalize the output so we return a consistent type.
map(event => (event instanceof TsOptionSelectionChange ? event : null)),
Expand Down Expand Up @@ -471,33 +470,6 @@ export class TsAutocompleteTriggerDirective<ValueType = string> implements Contr
public openPanel(): void {
this.attachOverlay();
this.floatLabel();
this.overlayClickOutside(this.overlayRef, this.elementRef.nativeElement).subscribe(() => this.closePanel());
}

/**
* Generate document’s click event stream,
* when a click meets two conditions:
* 1) The click target isn’t the origin.
* 2) The click target isn’t the panel or any one of its children.
* @param overlayRef
* @param origin
* @return observable
*/

public overlayClickOutside(overlayRef: OverlayRef | null | undefined, origin: HTMLElement) {
if (!overlayRef) {
return of();
}
return fromEvent<MouseEvent>(document, 'click')
.pipe(
filter(event => {
const clickTarget = event.target as HTMLElement;
const notOrigin = clickTarget !== origin;
const notOverlay = !!overlayRef && (!overlayRef.overlayElement.contains(clickTarget));
return notOrigin && notOverlay;
}),
takeUntil(overlayRef.detachments())
);
}


Expand Down Expand Up @@ -679,10 +651,12 @@ export class TsAutocompleteTriggerDirective<ValueType = string> implements Contr
*/
private getOverlayConfig(): OverlayConfig {
return new OverlayConfig({
backdropClass: 'ts-autocomplete__backdrop',
direction: 'ltr',
hasBackdrop: true,
positionStrategy: this.getOverlayPosition(),
scrollStrategy: this.scrollStrategy(),
width: this.getPanelWidth(),
direction: 'ltr',
});
}

Expand Down
6 changes: 6 additions & 0 deletions terminus-ui/autocomplete/src/autocomplete.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ $chip-font-size: 14px;
box-shadow: none;
}
}

.cdk-overlay-container {
.ts-autocomplete__backdrop {
background: transparent;
}
}