@mirohq/design-system-use-press
Advanced tools
Comparing version 0.1.0-use-press.2 to 0.1.0
@@ -154,3 +154,6 @@ 'use strict'; | ||
}; | ||
const shouldPreventDefault$1 = (target) => !(target instanceof HTMLElement) || !target.draggable; | ||
const shouldPreventDefault$1 = (target) => ( | ||
// We cannot prevent default if the target is a draggable element. | ||
!(target instanceof HTMLElement) || !target.draggable | ||
); | ||
@@ -252,3 +255,6 @@ const getEvents$2 = ({ | ||
const isHTMLAnchorLink = (target) => target.tagName === "A" && target.hasAttribute("href"); | ||
const isValidInputKey = (target, key) => target.type === "checkbox" || target.type === "radio" ? key === " " : nonTextInputTypes.has(target.type); | ||
const isValidInputKey = (target, key) => ( | ||
// Only space should toggle checkboxes and radios, not enter. | ||
target.type === "checkbox" || target.type === "radio" ? key === " " : nonTextInputTypes.has(target.type) | ||
); | ||
const isEnterOrSpaceEvent = (e) => e.key === "Enter" || e.key === " " || e.code === "Space"; | ||
@@ -259,3 +265,7 @@ const isValidKeyboardEvent = (event, currentTarget) => { | ||
const role = element.getAttribute("role"); | ||
return isEnterOrSpaceEvent(event) && !(element instanceof HTMLInputElement && !isValidInputKey(element, key) || element instanceof HTMLTextAreaElement || element.isContentEditable) && (!isHTMLAnchorLink(element) || role === "button" && key !== "Enter") && !(role === "link" && key !== "Enter"); | ||
return isEnterOrSpaceEvent(event) && // Inputs | ||
!(element instanceof HTMLInputElement && !isValidInputKey(element, key) || element instanceof HTMLTextAreaElement || element.isContentEditable) && // A link with a valid href should be handled natively, | ||
// unless it also has role='button' and was triggered using Space. | ||
(!isHTMLAnchorLink(element) || role === "button" && key !== "Enter") && // An element with role='link' should only trigger with Enter key | ||
!(role === "link" && key !== "Enter"); | ||
}; | ||
@@ -587,3 +597,6 @@ | ||
}; | ||
const shouldPreventDefault = (target) => !(target instanceof HTMLElement) || !target.draggable; | ||
const shouldPreventDefault = (target) => ( | ||
// We cannot prevent default if the target is a draggable element. | ||
!(target instanceof HTMLElement) || !target.draggable | ||
); | ||
@@ -590,0 +603,0 @@ const usePress = (props) => { |
@@ -150,3 +150,6 @@ import { useRef, useState, useEffect } from 'react'; | ||
}; | ||
const shouldPreventDefault$1 = (target) => !(target instanceof HTMLElement) || !target.draggable; | ||
const shouldPreventDefault$1 = (target) => ( | ||
// We cannot prevent default if the target is a draggable element. | ||
!(target instanceof HTMLElement) || !target.draggable | ||
); | ||
@@ -248,3 +251,6 @@ const getEvents$2 = ({ | ||
const isHTMLAnchorLink = (target) => target.tagName === "A" && target.hasAttribute("href"); | ||
const isValidInputKey = (target, key) => target.type === "checkbox" || target.type === "radio" ? key === " " : nonTextInputTypes.has(target.type); | ||
const isValidInputKey = (target, key) => ( | ||
// Only space should toggle checkboxes and radios, not enter. | ||
target.type === "checkbox" || target.type === "radio" ? key === " " : nonTextInputTypes.has(target.type) | ||
); | ||
const isEnterOrSpaceEvent = (e) => e.key === "Enter" || e.key === " " || e.code === "Space"; | ||
@@ -255,3 +261,7 @@ const isValidKeyboardEvent = (event, currentTarget) => { | ||
const role = element.getAttribute("role"); | ||
return isEnterOrSpaceEvent(event) && !(element instanceof HTMLInputElement && !isValidInputKey(element, key) || element instanceof HTMLTextAreaElement || element.isContentEditable) && (!isHTMLAnchorLink(element) || role === "button" && key !== "Enter") && !(role === "link" && key !== "Enter"); | ||
return isEnterOrSpaceEvent(event) && // Inputs | ||
!(element instanceof HTMLInputElement && !isValidInputKey(element, key) || element instanceof HTMLTextAreaElement || element.isContentEditable) && // A link with a valid href should be handled natively, | ||
// unless it also has role='button' and was triggered using Space. | ||
(!isHTMLAnchorLink(element) || role === "button" && key !== "Enter") && // An element with role='link' should only trigger with Enter key | ||
!(role === "link" && key !== "Enter"); | ||
}; | ||
@@ -583,3 +593,6 @@ | ||
}; | ||
const shouldPreventDefault = (target) => !(target instanceof HTMLElement) || !target.draggable; | ||
const shouldPreventDefault = (target) => ( | ||
// We cannot prevent default if the target is a draggable element. | ||
!(target instanceof HTMLElement) || !target.draggable | ||
); | ||
@@ -586,0 +599,0 @@ const usePress = (props) => { |
{ | ||
"name": "@mirohq/design-system-use-press", | ||
"version": "0.1.0-use-press.2", | ||
"version": "0.1.0", | ||
"description": "", | ||
@@ -29,5 +29,5 @@ "author": "Miro", | ||
"@react-aria/utils": "^3.14.2", | ||
"@mirohq/design-system-use-listeners": "^0.1.0-use-press.0", | ||
"@mirohq/design-system-utils": "^0.14.0-use-press.2", | ||
"@mirohq/design-system-use-logger": "^0.1.0-use-press.2" | ||
"@mirohq/design-system-use-listeners": "^0.1.0", | ||
"@mirohq/design-system-use-logger": "^0.1.0", | ||
"@mirohq/design-system-utils": "^0.14.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164166
1626