Skip to content

Commit

Permalink
feat: allow to customise clear icon
Browse files Browse the repository at this point in the history
fixes #835
  • Loading branch information
varnastadeus committed Nov 6, 2018
1 parent 75f614a commit 3e8ad77
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 44 deletions.
1 change: 1 addition & 0 deletions src/ng-select/ng-select.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
display: inline-block;
font-size: 18px;
line-height: 1;
pointer-events: none;
}
}
.ng-spinner-loader {
Expand Down
40 changes: 9 additions & 31 deletions src/ng-select/ng-select.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
import {
async,
ComponentFixture,
discardPeriodicTasks,
fakeAsync,
TestBed,
tick
} from '@angular/core/testing';
import { async, ComponentFixture, discardPeriodicTasks, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import {
Component,
DebugElement,
ErrorHandler,
NgZone,
Type,
ViewChild, ViewEncapsulation
} from '@angular/core';
import { Component, DebugElement, ErrorHandler, NgZone, Type, ViewChild, ViewEncapsulation } from '@angular/core';
import { ConsoleService } from './console.service';
import { FormsModule } from '@angular/forms';
import {
getNgSelectElement,
selectOption,
TestsErrorHandler,
tickAndDetectChanges,
triggerKeyDownEvent
} from '../testing/helpers';
import { getNgSelectElement, selectOption, TestsErrorHandler, tickAndDetectChanges, triggerKeyDownEvent } from '../testing/helpers';
import { KeyCode, NgOption } from './ng-select.types';
import { MockConsole, MockNgWindow, MockNgZone } from '../testing/mocks';
import { NgSelectComponent } from './ng-select.component';
import { NgSelectModule } from './ng-select.module';
import { Subject } from 'rxjs';
import { WindowService } from './window.service';



describe('NgSelectComponent', function () {

describe('Data source', () => {
Expand Down Expand Up @@ -1057,7 +1035,7 @@ describe('NgSelectComponent', function () {

it('should not open dropdown when isOpen is false', () => {
const open = spyOn(select, 'open');
select.ngOnChanges(<any>{ isOpen: { currentValue: false }});
select.ngOnChanges(<any>{ isOpen: { currentValue: false } });
triggerKeyDownEvent(getNgSelectElement(fixture), KeyCode.Space);
expect(select.isOpen).toBeFalsy();
expect(open).not.toHaveBeenCalled();
Expand Down Expand Up @@ -1995,7 +1973,7 @@ describe('NgSelectComponent', function () {
});

it('should be false when term exists among selected items', fakeAsync(() => {
fixture.componentInstance.selectedCities = [{name: 'Palanga', id: 9}];
fixture.componentInstance.selectedCities = [{ name: 'Palanga', id: 9 }];
select.filterValue = 'Palanga';
select.hideSelected = true;
select.isOpen = true;
Expand All @@ -2004,7 +1982,7 @@ describe('NgSelectComponent', function () {
}));

it('should be false when term exists among selected items and select is closed', fakeAsync(() => {
fixture.componentInstance.selectedCities = [{name: 'Palanga', id: 9}];
fixture.componentInstance.selectedCities = [{ name: 'Palanga', id: 9 }];
select.filterValue = 'Palanga';
select.hideSelected = false;
select.isOpen = false;
Expand Down Expand Up @@ -2781,7 +2759,7 @@ describe('NgSelectComponent', function () {
tickAndDetectChanges(fixture);
triggerMousedown = () => {
const control = fixture.debugElement.query(By.css('.ng-select-container'));
control.triggerEventHandler('mousedown', createEvent({ className: 'ng-clear' }));
control.triggerEventHandler('mousedown', createEvent({ className: 'ng-clear-wrapper' }));
};
}));

Expand Down Expand Up @@ -2864,7 +2842,7 @@ describe('NgSelectComponent', function () {
tickAndDetectChanges(fixture);
triggerMousedown = () => {
const control = fixture.debugElement.query(By.css('.ng-select-container'));
control.triggerEventHandler('mousedown', createEvent({className: 'ng-arrow-wrapper' }));
control.triggerEventHandler('mousedown', createEvent({ className: 'ng-arrow-wrapper' }));
};
}));

Expand Down Expand Up @@ -3209,7 +3187,7 @@ class NgSelectGroupingTestCmp {
selectedAccountName = 'Adam';
selectedAccount = null;
groupByFn = (item) => item.child.name;
groupValueFn = (key, _) => ({ group: key});
groupValueFn = (key, _) => ({ group: key });
accounts = [
{ name: 'Adam', email: 'adam@email.com', age: 12, country: 'United States', child: { name: 'c1' } },
{ name: 'Samantha', email: 'samantha@email.com', age: 30, country: 'United States', child: { name: 'c1' } },
Expand Down
3 changes: 1 addition & 2 deletions src/ng-select/ng-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
}
$event.stopPropagation();

if (target.className === 'ng-clear') {
if (target.className === 'ng-clear-wrapper') {
this.handleClearClick();
return;
}
Expand Down Expand Up @@ -603,7 +603,6 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
const select = (val: any) => {
let item = this.itemsList.findItem(val);
if (item) {
item.mapped = true;
this.itemsList.select(item);
} else {
const isValObject = isObject(val);
Expand Down
18 changes: 8 additions & 10 deletions src/themes/default.theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$color-selected: #f5faff;
.ng-select {
&.ng-select-opened {
>.ng-select-container {
> .ng-select-container {
background: #fff;
border-color: #b3b3b3 #ccc #d9d9d9;
&:hover {
Expand All @@ -19,26 +19,26 @@ $color-selected: #f5faff;
}
}
&.ng-select-bottom {
>.ng-select-container {
> .ng-select-container {
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
}
&.ng-select-top {
>.ng-select-container {
> .ng-select-container {
border-top-right-radius: 0;
border-top-left-radius: 0;
}
}
}
&.ng-select-focused {
&:not(.ng-select-opened)>.ng-select-container {
&:not(.ng-select-opened) > .ng-select-container {
border-color: #007eff;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 0 3px rgba(0, 126, 255, 0.1);
}
}
&.ng-select-disabled {
>.ng-select-container {
> .ng-select-container {
background-color: #f9f9f9;
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ $color-selected: #f5faff;
}
&.ng-select-multiple {
&.ng-select-disabled {
>.ng-select-container .ng-value-container .ng-value {
> .ng-select-container .ng-value-container .ng-value {
background-color: #f9f9f9;
border: 1px solid #e3e3e3;
.ng-value-label {
Expand Down Expand Up @@ -169,10 +169,8 @@ $color-selected: #f5faff;
}
.ng-clear-wrapper {
color: #999;
.ng-clear {
&:hover {
color: #D0021B;
}
&:hover .ng-clear {
color: #D0021B;
}
}
.ng-spinner-zone {
Expand Down
3 changes: 2 additions & 1 deletion src/themes/material.theme.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "mixins";

$highlight-color: #3f51b5;
$highlight-color: #3f51b5 !default;

.ng-select {
padding-bottom: 1.25em;
&.ng-select-disabled {
Expand Down

0 comments on commit 3e8ad77

Please sign in to comment.