[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>
Этот коммит содержится в:
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
Ссылка в новой задаче
Block a user