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

Search results display #585

Merged
merged 15 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
f255b2d
feat/fix(search results): manage focus/unfocus and select action on s…
PhilippeLafreniere18 Feb 11, 2020
6903ce2
feat/fix(search results): manage focus/unfocus and select action on s…
PhilippeLafreniere18 Feb 11, 2020
c23ebf7
Merge branch 'searchResultsDisplay' of https://github.com/infra-geo-o…
PhilippeLafreniere18 Feb 12, 2020
ea4d53c
lasts modifs on focus/unfocus/select search results
PhilippeLafreniere18 Feb 12, 2020
80c4a2d
feat/fix(search results): manage focus/unfocus and select action on s…
PhilippeLafreniere18 Feb 11, 2020
140c4a6
lasts modifs on focus/unfocus/select search results
PhilippeLafreniere18 Feb 12, 2020
86225a3
Merge branch 'searchResultsDisplay' of https://github.com/infra-geo-o…
PhilippeLafreniere18 Feb 13, 2020
8f76337
search results display lasts modfis
PhilippeLafreniere18 Feb 13, 2020
e46300b
lasts modifs
PhilippeLafreniere18 Feb 14, 2020
36223ea
Merge remote-tracking branch 'origin/next' into searchResultsDisplay
PhilippeLafreniere18 Feb 20, 2020
2754b04
feat/fix(search-results): manage focus/unfocus/select event on search…
PhilippeLafreniere18 Feb 20, 2020
26b0df4
fix(search-results-tool): fix lint problem
PhilippeLafreniere18 Feb 20, 2020
0f2ec42
Merge remote-tracking branch 'origin/next' into searchResultsDisplay
PhilippeLafreniere18 Mar 4, 2020
b2dd8f4
fix(search-results): fix focused style and scroll with panel and disp…
PhilippeLafreniere18 Mar 10, 2020
e5d5214
Merge branch 'next' into searchResultsDisplay
mbarbeau Mar 25, 2020
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
18 changes: 15 additions & 3 deletions packages/common/src/lib/list/list-item.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
})
export class ListItemDirective {

static focusedCls = 'igo-list-item-focused';
static selectedCls = 'igo-list-item-selected';
static disabledCls = 'igo-list-item-disabled';

Expand Down Expand Up @@ -40,7 +41,9 @@ export class ListItemDirective {
value ? this.beforeFocus.emit(this) : this.beforeUnfocus.emit(this);

this._focused = value;
this.toggleSelectedClass();
if (this.selected !== true) {
this.toggleFocusedClass();
}

value ? this.focus.emit(this) : this.unfocus.emit(this);
}
Expand Down Expand Up @@ -108,17 +111,26 @@ export class ListItemDirective {
this.selected = true;
}

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

getOffsetTop(): number {
const padding = 5;

return this.el.nativeElement.offsetTop - padding;
}

private toggleFocusedClass() {
if (this.focused) {
this.addCls(ListItemDirective.focusedCls);
} else {
this.removeCls(ListItemDirective.focusedCls);
}
}

private toggleSelectedClass() {
if (this.focused || this.selected) {
if (this.selected) {
this.addCls(ListItemDirective.selectedCls);
this.removeCls(ListItemDirective.focusedCls);
} else {
this.removeCls(ListItemDirective.selectedCls);
}
Expand Down
35 changes: 33 additions & 2 deletions packages/common/src/lib/list/list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class ListComponent implements AfterViewInit, OnInit, OnDestroy {
listItems: QueryList<ListItemDirective>;

@HostListener('document:keydown', ['$event'])
@HostListener('document:enter', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
// It would be nice to be able to unsubscribe to the event
// completely but until ES7 this won't be possible because
Expand Down Expand Up @@ -121,6 +122,7 @@ export class ListComponent implements AfterViewInit, OnInit, OnDestroy {
focusNext() {
const items = this.listItems.toArray();
let item;
const igoList = this.el.nativeElement;
let disabled = true;
let index = this.getFocusedIndex();
if (index === undefined) {
Expand All @@ -136,11 +138,21 @@ export class ListComponent implements AfterViewInit, OnInit, OnDestroy {
if (item !== undefined) {
this.focus(item);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!items[index + 1]) {
igoList.scrollTop = igoList.scrollHeight - igoList.clientHeight;
return;
}

if (item !== undefined && !this.isScrolledIntoView(item.el.nativeElement)) {
igoList.scrollTop = item.el.nativeElement.offsetTop + item.el.nativeElement.children[0].offsetHeight - igoList.clientHeight;
}
}

focusPrevious() {
const items = this.listItems.toArray();
let item;
let item: ListItemDirective;
const igoList = this.el.nativeElement;
let disabled = true;
let index = this.getFocusedIndex();

Expand All @@ -153,6 +165,16 @@ export class ListComponent implements AfterViewInit, OnInit, OnDestroy {
if (item !== undefined) {
this.focus(item);
}

if (!items[index - 1]) {
igoList.scrollTop = 0;
return;
}

if (item !== undefined && !this.isScrolledIntoView(item.el.nativeElement)) {
const padding = 3;
igoList.scrollTop = item.el.nativeElement.offsetTop - padding;
}
}

select(item?: ListItemDirective) {
Expand Down Expand Up @@ -191,6 +213,15 @@ export class ListComponent implements AfterViewInit, OnInit, OnDestroy {
this.el.nativeElement.scrollTop = item.getOffsetTop();
}

isScrolledIntoView(elem) {
const docViewTop = this.el.nativeElement.scrollTop + this.el.nativeElement.offsetTop;
const docViewBottom = docViewTop + this.el.nativeElement.clientHeight;

const elemTop = elem.offsetTop;
const elemBottom = elemTop + elem.children[0].offsetHeight;
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}

private init() {
this.subscribe();

Expand Down Expand Up @@ -237,7 +268,7 @@ export class ListComponent implements AfterViewInit, OnInit, OnDestroy {

private handleItemBeforeFocus(item: ListItemDirective) {
if (item !== this.focusedItem) {
this.unselect();
this.unfocus();
}
}

Expand Down
6 changes: 4 additions & 2 deletions packages/common/src/lib/list/list.theming.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
color: rgba(0, 0, 0, 0.38);
}

igo-list [igolistitem][color="primary"]:not(.igo-list-item-disabled):hover > mat-list-item {
igo-list [igolistitem][color="primary"]:not(.igo-list-item-disabled):hover > mat-list-item,
igo-list [igolistitem][color="primary"].igo-list-item-focused > mat-list-item {
background-color: mat-color($primary, lighter);
color: mat-color($primary, default-contrast);
}

igo-list [igolistitem][color="accent"]:not(.igo-list-item-disabled):hover > mat-list-item {
igo-list [igolistitem][color="accent"]:not(.igo-list-item-disabled):hover > mat-list-item,
igo-list [igolistitem][color="accent"].igo-list-item-focused > mat-list-item {
background-color: mat-color($accent, lighter);
color: mat-color($accent, default-contrast);
}
Expand Down
25 changes: 5 additions & 20 deletions packages/geo/src/assets/icons/place_blue_36px.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 2 additions & 17 deletions packages/geo/src/assets/icons/place_green_36px.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading