@sanity/ui
Advanced tools
Comparing version 2.8.5 to 2.8.6
{ | ||
"name": "@sanity/ui", | ||
"version": "2.8.5", | ||
"version": "2.8.6", | ||
"keywords": [ | ||
@@ -124,3 +124,3 @@ "sanity", | ||
"@juggle/resize-observer": "^3.4.0", | ||
"@sanity/pkg-utils": "^6.10.4", | ||
"@sanity/pkg-utils": "^6.10.6", | ||
"@sanity/prettier-config": "^1.0.2", | ||
@@ -127,0 +127,0 @@ "@sanity/semantic-release-preset": "^5.0.0", |
@@ -1,2 +0,2 @@ | ||
import {useCallback, useEffect, useRef, useState} from 'react' | ||
import {useCallback, useEffect, useMemo, useRef, useState} from 'react' | ||
import {_getFocusableElements, _sortElements} from './helpers' | ||
@@ -14,4 +14,2 @@ | ||
mount: (element: HTMLElement | null, selected?: boolean) => () => void | ||
rootElement: HTMLDivElement | null | ||
setRootElement: (el: HTMLDivElement | null) => void | ||
} | ||
@@ -28,10 +26,10 @@ | ||
shouldFocus: 'first' | 'last' | null | ||
rootElementRef: React.MutableRefObject<HTMLDivElement | null> | ||
}): MenuController { | ||
const {onKeyDown, originElement, shouldFocus} = props | ||
const {onKeyDown, originElement, shouldFocus, rootElementRef} = props | ||
const elementsRef = useRef<HTMLElement[]>([]) | ||
const [rootElement, setRootElement] = useState<HTMLDivElement | null>(null) | ||
const [activeIndex, _setActiveIndex] = useState(-1) | ||
const activeIndexRef = useRef(activeIndex) | ||
const activeElement = elementsRef.current[activeIndex] || null | ||
const mounted = Boolean(rootElement) | ||
const activeElement = useMemo(() => elementsRef.current[activeIndex] || null, [activeIndex]) | ||
const mounted = Boolean(rootElementRef.current) | ||
@@ -49,3 +47,3 @@ const setActiveIndex = useCallback((nextActiveIndex: number) => { | ||
elementsRef.current.push(element) | ||
_sortElements(rootElement, elementsRef.current) | ||
_sortElements(rootElementRef.current, elementsRef.current) | ||
} | ||
@@ -67,3 +65,3 @@ | ||
}, | ||
[rootElement, setActiveIndex], | ||
[rootElementRef, setActiveIndex], | ||
) | ||
@@ -186,4 +184,4 @@ | ||
setActiveIndex(-2) | ||
rootElement?.focus() | ||
}, [setActiveIndex, rootElement]) | ||
rootElementRef.current?.focus() | ||
}, [rootElementRef, setActiveIndex]) | ||
@@ -194,6 +192,4 @@ // Set focus on the currently active element | ||
const rafId = window.requestAnimationFrame(() => { | ||
const _activeIndex = activeIndexRef.current | ||
if (_activeIndex === -1) { | ||
const rafId = requestAnimationFrame(() => { | ||
if (activeIndex === -1) { | ||
if (shouldFocus === 'first') { | ||
@@ -207,3 +203,2 @@ const focusableElements = _getFocusableElements(elementsRef.current) | ||
setActiveIndex(currentIndex) | ||
activeIndexRef.current = currentIndex | ||
} | ||
@@ -220,3 +215,2 @@ } | ||
setActiveIndex(currentIndex) | ||
activeIndexRef.current = currentIndex | ||
} | ||
@@ -228,3 +222,3 @@ } | ||
const element = elementsRef.current[_activeIndex] || null | ||
const element = elementsRef.current[activeIndex] || null | ||
@@ -234,5 +228,3 @@ element?.focus() | ||
return () => { | ||
window.cancelAnimationFrame(rafId) | ||
} | ||
return () => cancelAnimationFrame(rafId) | ||
}, [activeIndex, mounted, setActiveIndex, shouldFocus]) | ||
@@ -247,5 +239,3 @@ | ||
mount, | ||
rootElement, | ||
setRootElement, | ||
} | ||
} |
@@ -17,3 +17,3 @@ import {styled, keyframes, css} from 'styled-components' | ||
width: 100%; | ||
} | ||
} | ||
` | ||
@@ -20,0 +20,0 @@ |
@@ -38,4 +38,3 @@ import {useDebugValue, useEffect} from 'react' | ||
const resolvedBoundaryElement = | ||
typeof boundaryElement === 'function' ? boundaryElement() : boundaryElement | ||
const resolvedBoundaryElement = boundaryElement?.() | ||
@@ -46,4 +45,3 @@ if (resolvedBoundaryElement && !resolvedBoundaryElement.contains(target)) { | ||
const resolvedElements = Array.isArray(elementsArg) ? elementsArg : elementsArg() | ||
const elements = resolvedElements.flat() | ||
const elements = elementsArg().flat() | ||
@@ -50,0 +48,0 @@ for (const el of elements) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
4556391
63655