mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[GH-23555] Do not block global backspace key press for contenteditable's (#23626)
* [GH-23555] Backspace is forbidden globally * [GH-23555] Backspace is forbidden globally (refactoring) --------- Co-authored-by: Andrey Karavashkin <akaravashkin@stsoft.ru>
This commit is contained in:
parent
19f33f332c
commit
c0ee02356e
@ -15,8 +15,8 @@ import WebSocketClient from 'client/web_websocket_client.jsx';
|
||||
import BrowserStore from 'stores/browser_store';
|
||||
import {UserProfile} from '@mattermost/types/users';
|
||||
import {Channel} from '@mattermost/types/channels';
|
||||
|
||||
const BACKSPACE_CHAR = 8;
|
||||
import {isKeyPressed} from 'utils/keyboard';
|
||||
import Constants from 'utils/constants';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@ -205,8 +205,20 @@ export default class LoggedIn extends React.PureComponent<Props> {
|
||||
|
||||
private handleBackSpace = (e: KeyboardEvent): void => {
|
||||
const excludedElements = ['input', 'textarea'];
|
||||
const targetElement = e.target as HTMLElement;
|
||||
|
||||
if (e.which === BACKSPACE_CHAR && !(excludedElements.includes((e.target as HTMLElement).tagName.toLowerCase()))) {
|
||||
if (!targetElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetsTagName = targetElement.tagName.toLowerCase();
|
||||
const isTargetNotContentEditable = targetElement.getAttribute?.('contenteditable') !== 'true';
|
||||
|
||||
if (
|
||||
isKeyPressed(e, Constants.KeyCodes.BACKSPACE) &&
|
||||
!(excludedElements.includes(targetsTagName)) &&
|
||||
isTargetNotContentEditable
|
||||
) {
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user