Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Made reverted offset parent, but added overall design improvesments
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackbaud-StacyCarlos committed Apr 23, 2018
1 parent 23b6796 commit b5f0db0
Show file tree
Hide file tree
Showing 12 changed files with 358 additions and 102 deletions.
2 changes: 1 addition & 1 deletion src/modules/autocomplete/autocomplete-input.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class SkyAutocompleteInputDirective
private _value: any;

constructor(
private elementRef: ElementRef,
public elementRef: ElementRef,
private renderer: Renderer2
) { }

Expand Down
18 changes: 9 additions & 9 deletions src/modules/autocomplete/autocomplete.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
<ng-content>
</ng-content>
<div class="sky-autocomplete-results">

<sky-dropdown
<sky-popover
placement="below"
[alignment]="alignment"
(popoverOpened)="onPopoverOpened()"
[dismissOnBlur]="false"
[messageStream]="dropdownController">

<sky-dropdown-button>
</sky-dropdown-button>

[@.disabled]="true"
#popover>
<sky-dropdown-menu
[useNativeFocus]="false"
[skyHighlight]="highlightText"
(menuChanges)="onMenuChanges($event)">
(menuChanges)="onMenuChanges($event)"
#dropdownMenu>

<sky-dropdown-item
*ngFor="let result of searchResults; let i = index">
Expand All @@ -27,7 +27,7 @@

</sky-dropdown-item>
</sky-dropdown-menu>
</sky-dropdown>
</sky-popover>
</div>
<ng-template
let-item="item"
Expand Down
27 changes: 16 additions & 11 deletions src/modules/autocomplete/autocomplete.component.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
.sky-autocomplete {
position: relative;
::ng-deep .sky-popover-container {
padding: 0;
min-width: auto;
max-width: none;

::ng-deep
.sky-dropdown-button {
visibility: hidden;
overflow: hidden;
width: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
.sky-popover {
border-radius: 0 !important;
border: 0 !important;
}

.sky-popover-body {
padding: 0;
}

.sky-popover-arrow {
display: none;
}
}
}
20 changes: 11 additions & 9 deletions src/modules/autocomplete/autocomplete.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('Autocomplete component', () => {
fixture.detectChanges();

const inputElement = getInputElement();
const messageSpy = spyOn(autocomplete as any, 'sendDropdownMessage')
const messageSpy = spyOn(autocomplete as any, 'sendMessage')
.and.callThrough();

inputElement.value = 'r';
Expand All @@ -207,20 +207,22 @@ describe('Autocomplete component', () => {
fixture.detectChanges();

const inputElement = getInputElement();
const messageSpy = spyOn(autocomplete as any, 'sendDropdownMessage')
const messageSpy = spyOn(autocomplete as any, 'sendMessage')
.and.callThrough();

inputElement.value = 'r';
SkyAppTestUtility.fireDomEvent(inputElement, 'keyup');
tick();

fixture.detectChanges();

inputElement.value = 're';
SkyAppTestUtility.fireDomEvent(inputElement, 'keyup');
tick();

expect(messageSpy)
.toHaveBeenCalledWith(SkyDropdownMessageType.Open);
expect(messageSpy.calls.count()).toEqual(1);
expect(messageSpy.calls.count()).toEqual(2);
})
);

Expand Down Expand Up @@ -395,7 +397,7 @@ describe('Autocomplete component', () => {
});
tick();

const messageSpy = spyOn(autocomplete as any, 'sendDropdownMessage')
const messageSpy = spyOn(autocomplete as any, 'sendMessage')
.and.callThrough();
const notifySpy = spyOn(autocomplete.selectionChange, 'emit')
.and.callThrough();
Expand All @@ -422,7 +424,7 @@ describe('Autocomplete component', () => {
SkyAppTestUtility.fireDomEvent(inputElement, 'keyup');
tick();

const messageSpy = spyOn(autocomplete as any, 'sendDropdownMessage')
const messageSpy = spyOn(autocomplete as any, 'sendMessage')
.and.callThrough();
const notifySpy = spyOn(autocomplete.selectionChange, 'emit')
.and.callThrough();
Expand All @@ -448,7 +450,7 @@ describe('Autocomplete component', () => {
tick();
fixture.detectChanges();

const spy = spyOn(autocomplete as any, 'sendDropdownMessage')
const spy = spyOn(autocomplete as any, 'sendMessage')
.and.callThrough();
const autocompleteElement = getAutocompleteElement();
const dropdownElement = autocompleteElement
Expand Down Expand Up @@ -506,7 +508,7 @@ describe('Autocomplete component', () => {
SkyAppTestUtility.fireDomEvent(inputElement, 'keyup');
tick();

const spy = spyOn(autocomplete as any, 'sendDropdownMessage').and.callThrough();
const spy = spyOn(autocomplete as any, 'sendMessage').and.callThrough();
const autocompleteElement = getAutocompleteElement();

SkyAppTestUtility.fireDomEvent(autocompleteElement, 'keydown', {
Expand Down Expand Up @@ -603,7 +605,7 @@ describe('Autocomplete component', () => {
tick();
fixture.detectChanges();

const messageSpy = spyOn(autocomplete as any, 'sendDropdownMessage')
const messageSpy = spyOn(autocomplete as any, 'sendMessage')
.and.callThrough();
const notifySpy = spyOn(autocomplete.selectionChange, 'emit')
.and.callThrough();
Expand Down Expand Up @@ -632,7 +634,7 @@ describe('Autocomplete component', () => {
fixture.detectChanges();
tick();

const spy = spyOn(autocomplete as any, 'sendDropdownMessage').and.callThrough();
const spy = spyOn(autocomplete as any, 'sendMessage').and.callThrough();

SkyAppTestUtility.fireDomEvent(inputElement, 'mouseenter');
tick();
Expand Down
75 changes: 64 additions & 11 deletions src/modules/autocomplete/autocomplete.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import 'rxjs/add/observable/fromEvent';
import {
SkyDropdownMenuChange,
SkyDropdownMessageType,
SkyDropdownMessage
SkyDropdownMessage,
SkyDropdownMenuComponent
} from '../dropdown';

import {
Expand All @@ -34,6 +35,7 @@ import {
import { SkyAutocompleteAdapterService } from './autocomplete-adapter.service';
import { SkyAutocompleteInputDirective } from './autocomplete-input.directive';
import { skyAutocompleteDefaultSearchFunction } from './autocomplete-default-search-function';
import { SkyPopoverComponent, SkyPopoverAlignment } from '../popover';

@Component({
selector: 'sky-autocomplete',
Expand Down Expand Up @@ -115,8 +117,8 @@ export class SkyAutocompleteComponent
return this._selectionChange;
}

public get dropdownController(): Subject<SkyDropdownMessage> {
return this._dropdownController;
public get messageStream(): Subject<SkyDropdownMessage> {
return this._messageStream;
}

public get searchResults(): any[] {
Expand All @@ -127,9 +129,17 @@ export class SkyAutocompleteComponent
return this._highlightText || '';
}

public alignment: SkyPopoverAlignment = 'left';

@ViewChild('defaultSearchResultTemplate')
private defaultSearchResultTemplate: TemplateRef<any>;

@ViewChild(SkyPopoverComponent)
private popover: SkyPopoverComponent;

@ViewChild('dropdownMenu')
private dropdownMenu: SkyDropdownMenuComponent;

@ContentChild(SkyAutocompleteInputDirective)
private inputDirective: SkyAutocompleteInputDirective;

Expand All @@ -140,7 +150,7 @@ export class SkyAutocompleteComponent

private _data: any[];
private _descriptorProperty: string;
private _dropdownController = new Subject<SkyDropdownMessage>();
private _messageStream = new Subject<SkyDropdownMessage>();
private _highlightText: string;
private _propertiesToSearch: string[];
private _search: SkyAutocompleteSearchFunction;
Expand Down Expand Up @@ -178,6 +188,12 @@ export class SkyAutocompleteComponent
.subscribe(() => {
this.isMouseEnter = false;
});

this.messageStream
.takeUntil(this.ngUnsubscribe)
.subscribe((message: SkyDropdownMessage) => {
this.handleIncomingMessages(message);
});
}

public ngAfterContentInit(): void {
Expand Down Expand Up @@ -224,17 +240,21 @@ export class SkyAutocompleteComponent
}

if (change.items) {
this.sendDropdownMessage(SkyDropdownMessageType.FocusFirstItem);
this.sendMessage(SkyDropdownMessageType.FocusFirstItem);
}
}

public onPopoverOpened() {
this.sendMessage(SkyDropdownMessageType.Open);
}

private handleKeyDown(event: KeyboardEvent): void {
const key = event.key.toLowerCase();

/* tslint:disable-next-line:switch-default */
switch (key) {
case 'arrowup':
this.sendDropdownMessage(SkyDropdownMessageType.FocusPreviousItem);
this.sendMessage(SkyDropdownMessageType.FocusPreviousItem);
event.preventDefault();
break;

Expand All @@ -246,7 +266,7 @@ export class SkyAutocompleteComponent
this.searchTextChanged(text);
event.preventDefault();
} else {
this.sendDropdownMessage(SkyDropdownMessageType.FocusNextItem);
this.sendMessage(SkyDropdownMessageType.FocusNextItem);
event.preventDefault();
}
break;
Expand Down Expand Up @@ -285,7 +305,7 @@ export class SkyAutocompleteComponent
if (isLongEnough && isDifferent) {
this.performSearch().then((results: any[]) => {
if (!this.hasSearchResults()) {
this.sendDropdownMessage(SkyDropdownMessageType.Open);
this.positionPopover();
}

this._searchResults = results;
Expand Down Expand Up @@ -317,15 +337,48 @@ export class SkyAutocompleteComponent
this.closeDropdown();
}

private handleIncomingMessages(message: SkyDropdownMessage) {
/* tslint:disable-next-line:switch-default */
switch (message.type) {
case SkyDropdownMessageType.Open:
this.dropdownMenu.focusFirstItem();
break;

case SkyDropdownMessageType.FocusNextItem:
this.dropdownMenu.focusNextItem();
break;

case SkyDropdownMessageType.FocusPreviousItem:
this.dropdownMenu.focusPreviousItem();
break;

case SkyDropdownMessageType.Close:
this.popover.close();
break;

case SkyDropdownMessageType.FocusTriggerButton:
this.inputDirective.elementRef.nativeElement.focus();
break;
}
}

private positionPopover() {
this.popover.positionNextTo(
this.elementRef,
'below',
this.alignment
);
}

private closeDropdown(): void {
this._searchResults = [];
this._highlightText = '';
this.changeDetector.markForCheck();
this.sendDropdownMessage(SkyDropdownMessageType.Close);
this.sendMessage(SkyDropdownMessageType.Close);
}

private sendDropdownMessage(type: SkyDropdownMessageType): void {
this.dropdownController.next({ type });
private sendMessage(type: SkyDropdownMessageType): void {
this.messageStream.next({ type });
}

private hasSearchResults(): boolean {
Expand Down
4 changes: 3 additions & 1 deletion src/modules/autocomplete/autocomplete.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SkyTextHighlightModule } from '../text-highlight';

import { SkyAutocompleteComponent } from './autocomplete.component';
import { SkyAutocompleteInputDirective } from './autocomplete-input.directive';
import { SkyPopoverModule } from '../popover';

@NgModule({
declarations: [
Expand All @@ -17,7 +18,8 @@ import { SkyAutocompleteInputDirective } from './autocomplete-input.directive';
CommonModule,
FormsModule,
SkyTextHighlightModule,
SkyDropdownModule
SkyDropdownModule,
SkyPopoverModule
],
exports: [
SkyAutocompleteComponent,
Expand Down
Loading

0 comments on commit b5f0db0

Please sign in to comment.