Skip to content

Commit db884ad

Browse files
authored
Merge pull request #50 from edcarroll/develop
v0.6.0 into master
2 parents 7560e32 + 25cd5d7 commit db884ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+989
-209
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/tmp
66

77
## ngc logs
8-
98
*.ngfactory.ts
109
*.ngsummary.json
1110

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Now you're good to go!
4444

4545
## Dependencies
4646

47-
* [Angular 2](https://angular.io) (>=2.0.0)
47+
* [Angular 2](https://angular.io) (^4.0.0)
4848
* [Semantic UI CSS](http://semantic-ui.com/) (jQuery is **not** required)
4949

5050
## Components
@@ -62,6 +62,7 @@ The current list of available components with links to their docs is below:
6262
* [Rating](https://edcarroll.github.io/ng2-semantic-ui/#/components/rating)
6363
* [Search](https://edcarroll.github.io/ng2-semantic-ui/#/components/search)
6464
* [Select](https://edcarroll.github.io/ng2-semantic-ui/#/components/select)
65+
* [Sidebar](https://edcarroll.github.io/ng2-semantic-ui/#/components/sidebar)
6566
* [Tabs](https://edcarroll.github.io/ng2-semantic-ui/#/components/tabs)
6667
* [Transition](https://edcarroll.github.io/ng2-semantic-ui/#/components/transition)
6768

angular-cli.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
"tsconfig": "tsconfig.json",
1717
"prefix": "demo",
1818
"mobile": false,
19-
"styles": ["styles.css"],
19+
"styles": [
20+
"css/styles.css",
21+
"css/code.css"
22+
],
2023
"scripts": [],
2124
"environmentSource": "environments/environment.ts",
2225
"environments": {

components/dropdown/dropdown-menu.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import {SuiTransition, Transition} from '../transition/transition';
33
import {DropdownService, DropdownAutoCloseType} from './dropdown.service';
44
import {TransitionController} from '../transition/transition-controller';
55
import {KeyCode} from '../util/util';
6+
// Polyfill for IE
7+
import "element-closest";
8+
9+
interface AugmentedElement extends Element {
10+
closest(selector:string):AugmentedElement;
11+
}
612

713
@Directive({
814
// We must attach to every '.item' as Angular doesn't support > selectors.
@@ -137,7 +143,8 @@ export class SuiDropdownMenu extends SuiTransition implements AfterContentInit {
137143
e.stopPropagation();
138144

139145
if (this._service.autoCloseMode == DropdownAutoCloseType.ItemClick) {
140-
if (e.srcElement.classList.contains("item")) {
146+
const target = e.target as AugmentedElement;
147+
if (this.element.nativeElement.contains(target.closest(".item")) && !/input|textarea/i.test(target.tagName)) {
141148
// Once an item is selected, we can close the entire dropdown.
142149
this._service.setOpenState(false, true);
143150
}

components/dropdown/dropdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class SuiDropdown implements AfterContentInit {
5656

5757
@HostBinding('attr.tabindex')
5858
public get tabIndex() {
59-
return this.isDisabled ? -1 : 0;
59+
return (this.isDisabled || this.service.isNested) ? null : 0;
6060
}
6161

6262
@Input()

components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export * from "./progress/progress.module";
99
export * from "./rating/rating.module";
1010
export * from "./search/search.module";
1111
export * from "./select/select.module";
12+
export * from "./sidebar/sidebar.module";
1213
export * from "./tabs/tab.module";
1314
export * from "./transition/transition.module";
1415

components/popup/popup.directive.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ export class SuiPopupDirective {
123123
if (!this._popupComponentRef) {
124124
const factory = this._componentFactoryResolver.resolveComponentFactory(SuiPopup);
125125
this._popupComponentRef = this._viewContainerRef.createComponent(factory);
126+
127+
// Move the generated element to the body to avoid any positioning issues.
128+
document.querySelector("body").appendChild(this._popupComponentRef.location.nativeElement);
126129

127130
this._popup.onClose.subscribe(() => {
128131
this._popupComponentRef.destroy();

components/search/search.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {FormsModule} from "@angular/forms";
44
import {SuiDropdownModule} from "../dropdown/dropdown.module";
55
import {SuiTransitionModule} from "../transition/transition.module";
66
import {SuiSearch, SuiSearchValueAccessor} from './search';
7-
import {SearchService} from './search.service';
7+
import {SearchService, LookupFn} from './search.service';
88

99
@NgModule({
1010
imports: [
@@ -23,4 +23,4 @@ import {SearchService} from './search.service';
2323
})
2424
export class SuiSearchModule {}
2525

26-
export {SearchService};
26+
export {SearchService, LookupFn};

components/search/search.service.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import {readValue} from '../util/util';
22

33
// Define useful types to avoid any.
4-
export type LookupFn<T> = (query:string) => Promise<T[]>
4+
export type LookupFn<T> = (query:string) => Promise<T[]> | Promise<T>;
5+
export type QueryLookupFn<T> = (query:string) => Promise<T[]>;
6+
export type ItemLookupFn<T, U> = (query:string, initial:U) => Promise<T>;
7+
export type ItemsLookupFn<T, U> = (query:string, initial:U[]) => Promise<T[]>;
8+
59
type CachedArray<T> = { [query:string]:T[] };
610

7-
// T extends JavascriptObject so we can do a recursive search on the object.
811
export class SearchService<T> {
912
// Stores the available options.
1013
private _options:T[];
@@ -36,6 +39,22 @@ export class SearchService<T> {
3639
this.reset();
3740
}
3841

42+
public get queryLookup() {
43+
return this._optionsLookup as QueryLookupFn<T>;
44+
}
45+
46+
public get hasItemLookup() {
47+
return this.optionsLookup && this.optionsLookup.length == 2;
48+
}
49+
50+
public itemLookup<U>(initial:U) {
51+
return (this._optionsLookup as ItemLookupFn<T, U>)(undefined, initial);
52+
}
53+
54+
public itemsLookup<U>(initial:U[]) {
55+
return (this._optionsLookup as ItemsLookupFn<T, U>)(undefined, initial);
56+
}
57+
3958
public get optionsField() {
4059
return this._optionsField
4160
}
@@ -112,7 +131,7 @@ export class SearchService<T> {
112131
if (this._optionsLookup) {
113132
this._isSearching = true;
114133

115-
this._optionsLookup(this._query)
134+
this.queryLookup(this._query)
116135
.then(results => {
117136
// Unset 'loading' state, and display & cache the results.
118137
this._isSearching = false;
@@ -170,12 +189,9 @@ export class SearchService<T> {
170189

171190
// Resets the search back to a pristine state.
172191
private reset() {
173-
this._query = "";
174192
this._results = [];
175-
if (this.allowEmptyQuery) {
176-
this._results = this._options;
177-
}
178193
this._resultsCache = {};
179194
this._isSearching = false;
195+
this.updateQuery("");
180196
}
181197
}

components/search/search.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import {PositioningService, PositioningPlacement} from '../util/positioning.serv
3939
export class SuiSearch<T> implements AfterViewInit {
4040
public dropdownService:DropdownService;
4141
public searchService:SearchService<T>;
42-
public position:PositioningService;
4342

4443
@ViewChild(SuiDropdownMenu)
4544
private _menu:SuiDropdownMenu;
@@ -78,7 +77,7 @@ export class SuiSearch<T> implements AfterViewInit {
7877
// Sets local or remote options by determining whether a function is passed.
7978
@Input()
8079
public set options(options:T[] | LookupFn<T>) {
81-
if (typeof(options) == "function") {
80+
if (typeof options == "function") {
8281
this.searchService.optionsLookup = options;
8382
return;
8483
}
@@ -131,10 +130,6 @@ export class SuiSearch<T> implements AfterViewInit {
131130

132131
public ngAfterViewInit() {
133132
this._menu.service = this.dropdownService;
134-
135-
// Initialse the positioning service to correctly display the results.
136-
// This adds support for repositioning the results above the search when there isn't enough space below.
137-
this.position = new PositioningService(this._element, this._menu.element, PositioningPlacement.BottomLeft);
138133
}
139134

140135
// Selects an item.
@@ -160,10 +155,8 @@ export class SuiSearch<T> implements AfterViewInit {
160155

161156
// Sets a specific item to be selected, updating the query automatically.
162157
public writeValue(item:T) {
163-
if (item) {
164-
this.selectedItem = item;
165-
this.searchService.updateQuery(this.readValue(item) as string, () => {});
166-
}
158+
this.selectedItem = item;
159+
this.searchService.updateQuery(item ? this.readValue(item) as string : "");
167160
}
168161
}
169162

0 commit comments

Comments
 (0)