mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-18 15:42:54 +00:00
fix: autofocus searchbar only when no default data is displayed
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
type="search"
|
||||
enterkeyhint="search"
|
||||
class="filterable"
|
||||
autofocus
|
||||
[autofocus]="!showDefaultData"
|
||||
>
|
||||
<ion-menu-button menu="context" auto-hide="false">
|
||||
<ion-icon name="tune"></ion-icon>
|
||||
|
||||
@@ -13,24 +13,24 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {AfterViewInit, Directive, ElementRef} from '@angular/core';
|
||||
import {AfterViewInit, Directive, ElementRef, Input} from '@angular/core';
|
||||
import {IonSearchbar} from '@ionic/angular';
|
||||
|
||||
@Directive({
|
||||
selector: 'ion-searchbar[autofocus]',
|
||||
})
|
||||
export class SearchbarAutofocusDirective implements AfterViewInit {
|
||||
@Input() autofocus = true;
|
||||
|
||||
constructor(private element: ElementRef) {}
|
||||
|
||||
ngAfterViewInit() {
|
||||
const label = `focus`;
|
||||
console.time(label);
|
||||
if (!this.autofocus) return;
|
||||
const interval = setInterval(() => {
|
||||
const searchbar = this.element.nativeElement as IonSearchbar;
|
||||
searchbar.setFocus();
|
||||
void searchbar.setFocus();
|
||||
});
|
||||
const onFocus = () => {
|
||||
console.timeEnd(label);
|
||||
clearInterval(interval);
|
||||
this.element.nativeElement.removeEventListener('ionFocus', onFocus);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user