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:
Shivam Mishra
2023-06-25 18:49:49 +05:30
committed by GitHub
parent 4f8ce7b597
commit 996325f35b
16 changed files with 485 additions and 20 deletions

View File

@@ -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')
);
};