mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-03 12:37:56 +00:00
feat: multiple UX improvements to labels (#7358)
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com>
This commit is contained in:
@@ -106,6 +106,11 @@ export const hasPressedCommandPlusKKey = e => {
|
||||
return e.metaKey && e.keyCode === 75;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a string representation of the hotkey pattern based on the provided event object.
|
||||
* @param {KeyboardEvent} e - The keyboard event object.
|
||||
* @returns {string} - The hotkey pattern string.
|
||||
*/
|
||||
export const buildHotKeys = e => {
|
||||
const key = e.key.toLowerCase();
|
||||
if (['shift', 'meta', 'alt', 'control'].includes(key)) {
|
||||
@@ -127,3 +132,30 @@ export const buildHotKeys = e => {
|
||||
hotKeyPattern += key;
|
||||
return hotKeyPattern;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines whether the active element is typeable.
|
||||
*
|
||||
* @param {KeyboardEvent} e - The keyboard event object.
|
||||
* @returns {boolean} `true` if the active element is typeable, `false` otherwise.
|
||||
*
|
||||
* @example
|
||||
* document.addEventListener('keydown', e => {
|
||||
* if (isActiveElementTypeable(e)) {
|
||||
* handleTypeableElement(e);
|
||||
* }
|
||||
* });
|
||||
*/
|
||||
export const isActiveElementTypeable = e => {
|
||||
/** @type {HTMLElement | null} */
|
||||
// @ts-ignore
|
||||
const activeElement = e.target || document.activeElement;
|
||||
|
||||
return !!(
|
||||
activeElement?.tagName === 'INPUT' ||
|
||||
activeElement?.tagName === 'NINJA-KEYS' ||
|
||||
activeElement?.tagName === 'TEXTAREA' ||
|
||||
activeElement?.contentEditable === 'true' ||
|
||||
activeElement?.className?.includes('ProseMirror')
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user