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";
export type NavigationItem = { export type NavigationItem = {
type: 'left' | 'right' | 'im' | 'chat' | 'popup' | 'media' | 'menu' | type: 'left' | 'right' | 'im' | 'chat' | 'popup' | 'media' | 'menu' |
'esg' | 'multiselect' | 'input-helper' | 'autocomplete-helper' | 'markup' | '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, onPop: (canAnimate: boolean) => boolean | void,
onEscape?: () => boolean, onEscape?: () => boolean,
noHistory?: boolean, noHistory?: boolean,

21
src/components/sidebarLeft/index.ts

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

Loading…
Cancel
Save