Close settings and search with escape key #1

Merged
NotAlexNoyle merged 1 commits from dev into dev 2024-05-03 13:27:24 -04:00
7 changed files with 31 additions and 5 deletions

No files matched your search

+1 -1
View File
@@ -27,7 +27,7 @@ function RawModal({
}
useEffect(() => {
navigation.setIsRawModalVisible(isOpen);
navigation.isRawModalVisible = isOpen;
}, [isOpen]);
const modalOverlayClass = (overlayClassName !== null) ? `${overlayClassName} ` : '';
+8
View File
@@ -44,6 +44,7 @@ function useVisiblityToggle(setResult) {
}, [isOpen]);
const requestClose = () => setIsOpen(false);
navigation.on(cons.events.navigation.REQUEST_CLOSE, requestClose);
return [isOpen, requestClose];
}
@@ -154,6 +155,12 @@ function Search() {
}
};
const handleKeyPress = (e) => {
if (e.key === 'Backspace' && searchRef.current.value.length === 0) {
requestClose();
}
};
const openItem = (roomId, type) => {
if (type === 'space') selectTab(roomId);
else selectRoom(roomId);
@@ -210,6 +217,7 @@ function Search() {
onChange={handleOnChange}
forwardRef={searchRef}
placeholder="Search"
onKeyDown={handleKeyPress}
/>
<IconButton size="small" src={CrossIC} type="reset" onClick={handleCross} tabIndex={-1} />
</form>
+2
View File
@@ -317,6 +317,8 @@ function useWindowToggle(setSelectedTab) {
const requestClose = () => setIsOpen(false);
navigation.on(cons.events.navigation.REQUEST_CLOSE, requestClose);
return [isOpen, requestClose];
}
+6
View File
@@ -181,3 +181,9 @@ export function openEmojiVerification(request, targetDevice) {
targetDevice,
});
}
export function requestClose() {
appDispatcher.dispatch({
type: cons.actions.navigation.REQUEST_CLOSE,
});
}
+7 -3
View File
@@ -1,4 +1,4 @@
import { openSearch, toggleRoomSettings } from '../action/navigation';
import { openSearch, toggleRoomSettings, requestClose } from '../action/navigation';
import navigation from '../state/navigation';
import { markAsRead } from '../action/notifications';
@@ -50,9 +50,12 @@ function listenKeyboard(event) {
}
if (!event.ctrlKey && !event.altKey && !event.metaKey) {
if (navigation.isRawModalVisible) return;
if (event.key === 'Escape') {
if (navigation.isRawModalVisible) {
requestClose();
return;
}
if (navigation.isRoomSettings) {
toggleRoomSettings();
return;
@@ -62,6 +65,7 @@ function listenKeyboard(event) {
return;
}
}
if (navigation.isRawModalVisible) return;
if (['input', 'textarea'].includes(document.activeElement.tagName.toLowerCase())) {
return;
+1
View File
@@ -90,6 +90,7 @@ const cons = {
JOIN_ALIAS_OPENED: 'JOIN_ALIAS_OPENED',
INVITE_USER_OPENED: 'INVITE_USER_OPENED',
SETTINGS_OPENED: 'SETTINGS_OPENED',
REQUEST_CLOSE: 'REQUEST_CLOSE',
PROFILE_VIEWER_OPENED: 'PROFILE_VIEWER_OPENED',
EMOJIBOARD_OPENED: 'EMOJIBOARD_OPENED',
READRECEIPTS_OPENED: 'READRECEIPTS_OPENED',
+6 -1
View File
@@ -276,7 +276,7 @@ class Navigation extends EventEmitter {
return this.rawModelStack.length > 0;
}
setIsRawModalVisible(visible) {
set isRawModalVisible(visible) {
if (visible) this.rawModelStack.push(true);
else this.rawModelStack.pop();
}
@@ -383,6 +383,11 @@ class Navigation extends EventEmitter {
action.term,
);
},
[cons.actions.navigation.REQUEST_CLOSE]: () => {
this.emit(
cons.events.navigation.REQUEST_CLOSE,
);
},
[cons.actions.navigation.OPEN_REUSABLE_CONTEXT_MENU]: () => {
this.emit(
cons.events.navigation.REUSABLE_CONTEXT_MENU_OPENED,