Skip to content

Commit 8f21507

Browse files
committed
MOBILE-3401 search: Show/hide search history checking focus
1 parent 206afd7 commit 8f21507

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/core/search/components/search-box/core-search-box.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ion-icon name="close"></ion-icon>
1010
</button>
1111
</ion-item>
12-
<ion-list class="core-search-history with-borders">
12+
<ion-list class="core-search-history with-borders" [hidden]="!historyShown">
1313
<a ion-item text-wrap *ngFor="let item of history" (click)="historyClicked($event, item.searchedtext)" class="core-clickable" tabindex="1">
1414
<core-icon name="fa-history" item-start></core-icon>
1515
{{item.searchedtext}}

src/core/search/components/search-box/search-box.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ ion-app.app-root core-search-box {
2323
}
2424

2525
.core-search-history {
26-
display: none;
2726
max-height: calc(-120px + 80vh);
2827
overflow-y: auto;
2928

@@ -35,10 +34,4 @@ ion-app.app-root core-search-box {
3534
border-bottom: 0;
3635
}
3736
}
38-
39-
form:focus-within {
40-
.core-search-history {
41-
display: block;
42-
}
43-
}
4437
}

src/core/search/components/search-box/search-box.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ export class CoreSearchBoxComponent implements OnInit {
7878
if (this.searchArea) {
7979
this.loadHistory();
8080
}
81+
82+
this.formElement.nativeElement.addEventListener('focus', () => {
83+
this.historyShown = true;
84+
}, true);
85+
86+
this.formElement.nativeElement.addEventListener('blur', () => {
87+
// Wait the new element to be focused.
88+
setTimeout(() => {
89+
if (document.activeElement.closest('form') != this.formElement.nativeElement) {
90+
this.historyShown = false;
91+
}
92+
});
93+
}, true);
8194
}
8295

8396
/**
@@ -100,6 +113,7 @@ export class CoreSearchBoxComponent implements OnInit {
100113

101114
this.domUtils.triggerFormSubmittedEvent(this.formElement, false, this.sitesProvider.getCurrentSiteId());
102115

116+
this.historyShown = false;
103117
this.searched = this.searchText;
104118
this.onSubmit.emit(this.searchText);
105119
}

0 commit comments

Comments
 (0)