Skip to content

Instantly share code, notes, and snippets.

View moaaz-bhnas's full-sized avatar
🏠
Working remotely

Moaaz Bhnas moaaz-bhnas

🏠
Working remotely
View GitHub Profile
@moaaz-bhnas
moaaz-bhnas / withoutEdgesAndNodes.ts
Last active June 11, 2023 17:04
A function that removes edges and nodes from Shopify Storefront data
function isArray(data: any): Boolean {
return data && data.constructor === Array;
}
function isObject(data: any): Boolean {
return data && data.constructor === Object;
}
function withoutEdgesAndNodes(data: any): any {
let result = Array.isArray(data) ? [] : {};
@moaaz-bhnas
moaaz-bhnas / trapFocus
Created August 9, 2021 19:05
Trap focus
const handleKeyDown = useCallback(
(event, firstInteractive, lastInteractive, close, handleSubmit) => {
const { target, key, shiftKey } = event;
if (key === "Tab" && shiftKey && target === firstInteractive) {
event.preventDefault();
lastInteractive.focus();
}
if (key === "Tab" && !shiftKey && target === lastInteractive) {