Browse Source

Focus search input by pressing Escape

master
Eduard Kuzmenko 3 years ago
parent
commit
af3a7ee341
  1. 2
      src/components/appNavigationController.ts
  2. 21
      src/components/sidebarLeft/index.ts

2
src/components/appNavigationController.ts

@ -15,7 +15,7 @@ import indexOfAndSplice from "../helpers/array/indexOfAndSplice"; @@ -15,7 +15,7 @@ import indexOfAndSplice from "../helpers/array/indexOfAndSplice";
export type NavigationItem = {
type: 'left' | 'right' | 'im' | 'chat' | 'popup' | 'media' | 'menu' |
'esg' | 'multiselect' | 'input-helper' | 'autocomplete-helper' | 'markup' |
'global-search' | 'voice' | 'mobile-search' | 'filters',
'global-search' | 'voice' | 'mobile-search' | 'filters' | 'global-search-focus',
onPop: (canAnimate: boolean) => boolean | void,
onEscape?: () => boolean,
noHistory?: boolean,

21
src/components/sidebarLeft/index.ts

@ -29,7 +29,7 @@ import AppPeopleNearbyTab from "./tabs/peopleNearby"; @@ -29,7 +29,7 @@ import AppPeopleNearbyTab from "./tabs/peopleNearby";
import { ButtonMenuItemOptions } from "../buttonMenu";
import CheckboxField from "../checkboxField";
import { IS_MOBILE_SAFARI } from "../../environment/userAgent";
import appNavigationController from "../appNavigationController";
import appNavigationController, { NavigationItem } from "../appNavigationController";
import findUpClassName from "../../helpers/dom/findUpClassName";
import findUpTag from "../../helpers/dom/findUpTag";
import PeerTitle from "../peerTitle";
@ -311,6 +311,20 @@ export class AppSidebarLeft extends SidebarSlider { @@ -311,6 +311,20 @@ export class AppSidebarLeft extends SidebarSlider {
appUsersManager.getTopPeers('correspondents');
// Focus search input by pressing Escape
const navigationItem: NavigationItem = {
type: 'global-search-focus',
onPop: () => {
setTimeout(() => {
this.inputSearch.input.focus();
}, 0);
return false;
},
noHistory: true
};
appNavigationController.pushItem(navigationItem);
appStateManager.getState().then(state => {
const recentSearch = state.recentSearch || [];
for(let i = 0, length = recentSearch.length; i < length; ++i) {
@ -613,12 +627,13 @@ export class AppSidebarLeft extends SidebarSlider { @@ -613,12 +627,13 @@ export class AppSidebarLeft extends SidebarSlider {
this.updateBtn.classList.add('is-hidden');
this.toolsBtn.parentElement.firstElementChild.classList.toggle('state-back', true);
if(!IS_MOBILE_SAFARI && !appNavigationController.findItemByType('global-search')) {
const navigationType: NavigationItem['type'] = 'global-search';
if(!IS_MOBILE_SAFARI && !appNavigationController.findItemByType(navigationType)) {
appNavigationController.pushItem({
onPop: () => {
close();
},
type: 'global-search'
type: navigationType
});
}

Loading…
Cancel
Save