Skip to content

Commit

Permalink
fix(autocomplete): checkbox no longer appears in front of autocomplet…
Browse files Browse the repository at this point in the history
…e options (#1565)
  • Loading branch information
atlwendy authored and benjamincharity committed Jun 21, 2019
1 parent bdf3d46 commit cb3ca47
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
17 changes: 17 additions & 0 deletions terminus-ui/autocomplete/src/autocomplete.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,23 @@ describe(`TsAutocompleteComponent`, function() {

});

describe(`checkbox`, function() {

test(`should not have checkbox in front of an item list`, fakeAsync(() => {
const fixture = createComponent(testComponents.AutocompleteAllowMultipleNoReopen);
fixture.detectChanges();

const input = getAutocompleteInput(fixture);
typeInElement('al', input);
tick(1000);
fixture.detectChanges();
const opt = getOptionElement(fixture, 0, 1);
fixture.detectChanges();
expect(opt.querySelectorAll('ts-checkbox')).toHaveLength(0);

}));
});

});


Expand Down
5 changes: 5 additions & 0 deletions terminus-ui/autocomplete/src/autocomplete.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ export class TsAutocompleteComponent implements OnInit,
OnDestroy,
TsFormFieldControl<string> {

/**
* Give the component an explicit name
*/
public readonly componentName = 'TsAutocompleteComponent';

/**
* Define the FormControl
*/
Expand Down
16 changes: 5 additions & 11 deletions terminus-ui/option/src/option.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class TsOptionSelectionChange {
* Contains properties that the options can inherit. Used by {@link TS_OPTION_PARENT_COMPONENT}
*/
export interface TsOptionParentComponent {
componentName: string;
allowMultiple: boolean;
theme: TsStyleThemeTypes;
ngControl?: NgModel;
Expand Down Expand Up @@ -289,18 +290,11 @@ export class TsOptionComponent implements Highlightable, AfterContentInit, After
// Injecting via a provider helps us get around the circular dependency created by importing TsSelectComponent here.
@Optional() @Inject(TS_OPTION_PARENT_COMPONENT) private parent: TsOptionParentComponent,
@Optional() @Inject(TS_OPTGROUP_PARENT_COMPONENT) public readonly group: TsOptgroupParentComponent,
private viewContainerRef: ViewContainerRef,
) {
// From view container ref to decide the parent component. Possible refactoring with injector.
// eslint-disable-next-line dot-notation
if (this.viewContainerRef['_data'].componentView) {
// eslint-disable-next-line dot-notation
const parentComponent = this.viewContainerRef['_data'].componentView.parent.component.constructor.name.toLowerCase();
if (parentComponent.includes('autocomplete')) {
this.autocompleteComponent = true;
} else if (parentComponent.includes('select')) {
this.selectComponent = true;
}
if (parent.componentName.includes('Autocomplete')) {
this.autocompleteComponent = true;
} else if (parent.componentName.includes('Select')) {
this.selectComponent = true;
}
}

Expand Down
19 changes: 16 additions & 3 deletions terminus-ui/select/src/select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,19 @@ describe(`TsSelectComponent`, function() {

});

describe(`checkbox`, function() {

test(`should have checkbox in front of each option item`, fakeAsync(() => {
const fixture = createComponent(testComponents.OptgroupsMultiple);
fixture.detectChanges();

fixture.detectChanges();
const opt = getOptionElement(fixture, 0, 1);
expect(opt.querySelector('ts-checkbox')).toBeTruthy();

}));
});


describe(`handleKeydown`, function() {

Expand Down Expand Up @@ -992,7 +1005,7 @@ describe(`TsSelectComponent`, function() {
const event = createKeyboardEvent('keydown', KEYS.ENTER);
const instance = getSelectInstance(fixture);
option.selectViaInteraction = jest.fn();
instance.open = jest.fn()
instance.open = jest.fn();

instance.handleKeydown(event);
expect(option.selectViaInteraction).not.toHaveBeenCalled();
Expand All @@ -1005,11 +1018,11 @@ describe(`TsSelectComponent`, function() {
const event = createKeyboardEvent('keydown', KEYS.ENTER);
const instance = getSelectInstance(fixture);
option.selectViaInteraction = jest.fn();
instance.open = jest.fn()
instance.open = jest.fn();

instance.handleKeydown(event);
expect(instance.open).toHaveBeenCalled();
})
});
});


Expand Down
5 changes: 5 additions & 0 deletions terminus-ui/select/src/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ export class TsSelectComponent implements
OnDestroy,
TsFormFieldControl<unknown> {

/**
* Give the component an explicit name
*/
public readonly componentName = 'TsSelectComponent';

/**
* Store a reference to the document object
*/
Expand Down

0 comments on commit cb3ca47

Please sign in to comment.