@elvia/elvis-toolbox
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -6,2 +6,14 @@ { | ||
"date": "28.09.22", | ||
"version": "4.0.1", | ||
"changelog": [ | ||
{ | ||
"type": "bug_fix", | ||
"changes": [ | ||
"Fixed a bug that caused the <span class=\"code-text\">useFocusTrap</span> hook to not work properly when a custom element was passed as content in the <span class=\"code-text\">elvia-modal</span> component." | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"date": "28.09.22", | ||
"version": "4.0.0", | ||
@@ -8,0 +20,0 @@ "changelog": [ |
@@ -5,44 +5,47 @@ "use strict"; | ||
const useFocusTrap = (focusTrapContainer, removeEventListener) => { | ||
if (!focusTrapContainer.current) { | ||
return; | ||
} | ||
const focusableItems = Array.from(focusTrapContainer.current.querySelectorAll('a[href], button, textarea, input, select, details, [tabindex]:not([tabindex="-1"]')).filter((element) => { | ||
return (!element.hasAttribute('disabled') && | ||
!element.hasAttribute('aria-hidden') && | ||
element.getAttribute('tabindex') !== '-1'); | ||
}); | ||
const firstItem = focusableItems[0]; | ||
const lastItem = focusableItems[focusableItems.length - 1]; | ||
const handleFirstItemTab = (e) => { | ||
if (e.key === 'Tab' && e.shiftKey) { | ||
if (lastItem) { | ||
lastItem.focus(); | ||
} | ||
e.preventDefault(); | ||
setTimeout(() => { | ||
if (!focusTrapContainer.current) { | ||
return; | ||
} | ||
}; | ||
const handleLastItemTab = (e) => { | ||
if (e.key === 'Tab' && !e.shiftKey) { | ||
if (firstItem) { | ||
firstItem.focus(); | ||
const focusableItems = Array.from(focusTrapContainer.current.querySelectorAll('a[href], button, textarea, input, select, details, [tabindex]:not([tabindex="-1"]')).filter((element) => { | ||
var _a; | ||
return (!element.hasAttribute('disabled') && | ||
element.getAttribute('aria-hidden') !== 'true' && | ||
parseInt((_a = element.getAttribute('tabindex')) !== null && _a !== void 0 ? _a : '0') >= 0); | ||
}); | ||
const firstItem = focusableItems[0]; | ||
const lastItem = focusableItems[focusableItems.length - 1]; | ||
const handleFirstItemTab = (e) => { | ||
if (e.key === 'Tab' && e.shiftKey) { | ||
if (lastItem) { | ||
lastItem.focus(); | ||
} | ||
e.preventDefault(); | ||
} | ||
e.preventDefault(); | ||
} | ||
}; | ||
if (firstItem) { | ||
firstItem.focus(); | ||
firstItem.addEventListener('keydown', handleFirstItemTab); | ||
} | ||
if (lastItem) { | ||
lastItem.addEventListener('keydown', handleLastItemTab); | ||
} | ||
if (removeEventListener) { | ||
}; | ||
const handleLastItemTab = (e) => { | ||
if (e.key === 'Tab' && !e.shiftKey) { | ||
if (firstItem) { | ||
firstItem.focus(); | ||
} | ||
e.preventDefault(); | ||
} | ||
}; | ||
if (firstItem) { | ||
firstItem.removeEventListener('keydown', handleFirstItemTab); | ||
firstItem.focus(); | ||
firstItem.addEventListener('keydown', handleFirstItemTab); | ||
} | ||
if (lastItem) { | ||
lastItem.removeEventListener('keydown', handleLastItemTab); | ||
lastItem.addEventListener('keydown', handleLastItemTab); | ||
} | ||
} | ||
if (removeEventListener) { | ||
if (firstItem) { | ||
firstItem.removeEventListener('keydown', handleFirstItemTab); | ||
} | ||
if (lastItem) { | ||
lastItem.removeEventListener('keydown', handleLastItemTab); | ||
} | ||
} | ||
}); | ||
}; | ||
exports.useFocusTrap = useFocusTrap; |
{ | ||
"name": "@elvia/elvis-toolbox", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
# Toolbox |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ import { Dispatch, RefObject, SetStateAction, useEffect, useState } from 'react'; |
@@ -7,52 +7,54 @@ import { RefObject } from 'react'; | ||
): void => { | ||
if (!focusTrapContainer.current) { | ||
return; | ||
} | ||
const focusableItems = Array.from( | ||
focusTrapContainer.current.querySelectorAll( | ||
'a[href], button, textarea, input, select, details, [tabindex]:not([tabindex="-1"]', | ||
), | ||
).filter((element) => { | ||
return ( | ||
!element.hasAttribute('disabled') && | ||
!element.hasAttribute('aria-hidden') && | ||
element.getAttribute('tabindex') !== '-1' | ||
); | ||
}); | ||
setTimeout(() => { | ||
if (!focusTrapContainer.current) { | ||
return; | ||
} | ||
const focusableItems = Array.from( | ||
focusTrapContainer.current.querySelectorAll( | ||
'a[href], button, textarea, input, select, details, [tabindex]:not([tabindex="-1"]', | ||
), | ||
).filter((element) => { | ||
return ( | ||
!element.hasAttribute('disabled') && | ||
element.getAttribute('aria-hidden') !== 'true' && | ||
parseInt(element.getAttribute('tabindex') ?? '0') >= 0 | ||
); | ||
}); | ||
const firstItem = focusableItems[0]; | ||
const lastItem = focusableItems[focusableItems.length - 1]; | ||
const firstItem = focusableItems[0]; | ||
const lastItem = focusableItems[focusableItems.length - 1]; | ||
const handleFirstItemTab = (e: KeyboardEvent) => { | ||
if (e.key === 'Tab' && e.shiftKey) { | ||
if (lastItem) { | ||
(lastItem as HTMLElement).focus(); | ||
const handleFirstItemTab = (e: KeyboardEvent) => { | ||
if (e.key === 'Tab' && e.shiftKey) { | ||
if (lastItem) { | ||
(lastItem as HTMLElement).focus(); | ||
} | ||
e.preventDefault(); | ||
} | ||
e.preventDefault(); | ||
} | ||
}; | ||
const handleLastItemTab = (e: KeyboardEvent) => { | ||
if (e.key === 'Tab' && !e.shiftKey) { | ||
if (firstItem) { | ||
(firstItem as HTMLElement).focus(); | ||
}; | ||
const handleLastItemTab = (e: KeyboardEvent) => { | ||
if (e.key === 'Tab' && !e.shiftKey) { | ||
if (firstItem) { | ||
(firstItem as HTMLElement).focus(); | ||
} | ||
e.preventDefault(); | ||
} | ||
e.preventDefault(); | ||
} | ||
}; | ||
if (firstItem) { | ||
(firstItem as HTMLElement).focus(); | ||
firstItem.addEventListener('keydown', handleFirstItemTab); | ||
} | ||
if (lastItem) { | ||
lastItem.addEventListener('keydown', handleLastItemTab); | ||
} | ||
if (removeEventListener) { | ||
}; | ||
if (firstItem) { | ||
firstItem.removeEventListener('keydown', handleFirstItemTab); | ||
(firstItem as HTMLElement).focus(); | ||
firstItem.addEventListener('keydown', handleFirstItemTab); | ||
} | ||
if (lastItem) { | ||
lastItem.removeEventListener('keydown', handleLastItemTab); | ||
lastItem.addEventListener('keydown', handleLastItemTab); | ||
} | ||
} | ||
if (removeEventListener) { | ||
if (firstItem) { | ||
firstItem.removeEventListener('keydown', handleFirstItemTab); | ||
} | ||
if (lastItem) { | ||
lastItem.removeEventListener('keydown', handleLastItemTab); | ||
} | ||
} | ||
}); | ||
}; |
@@ -0,0 +0,0 @@ import { RefObject, useEffect, useState } from 'react'; |
@@ -0,0 +0,0 @@ export * from './elvis-toolbox'; |
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
42640
1089