diff --git a/components/core/Filter/Filters.js b/components/core/Filter/Filters.js index f5b218b0..2bf10d27 100644 --- a/components/core/Filter/Filters.js +++ b/components/core/Filter/Filters.js @@ -108,14 +108,18 @@ const FilterSection = React.forwardRef(({ title, children, ...props }, ref) => { )} {isExpanded ? ( - - {children} - + + + + {children} + + + ) : null} ); @@ -151,27 +155,23 @@ function Tags({ viewer, data, onAction, ...props }) { const [, { hidePopup }] = useFilterContext(); return ( - - - - {viewer.slates.map((slate, index) => ( -
  • - - - {slate.slatename} - - -
  • - ))} -
    -
    -
    + + {viewer.slates.map((slate, index) => ( +
  • + + + {slate.slatename} + + +
  • + ))} +
    ); } diff --git a/components/core/RovingTabIndex.js b/components/core/RovingTabIndex.js index 050fcaa6..ed81481e 100644 --- a/components/core/RovingTabIndex.js +++ b/components/core/RovingTabIndex.js @@ -1,7 +1,8 @@ import * as React from "react"; +import { jsx } from "@emotion/react"; import { mergeRefs } from "~/common/utilities"; -import { useEventListener, useMounted } from "~/common/hooks"; +import { useEventListener } from "~/common/hooks"; /* ------------------------------------------------------------------------------------------------- * RovingTabIndex Provider @@ -16,28 +17,37 @@ export function Provider({ axis, children }) { const [focusedIndex, setFocusedIndex] = React.useState(initialIndex); const registerItem = ({ index, ref }) => (focusedElementsRefs.current[index] = ref); - const cleanupItem = (index) => delete focusedElementsRefs.current[index]; + const cleanupItem = (index) => { + if (index === focusedIndex) { + setFocusedIndex(initialIndex); + } + delete focusedElementsRefs.current[index]; + }; + + const focusElement = (index) => { + const focusedElementRef = focusedElementsRefs.current[index]; + focusedElementRef?.current?.focus(); + }; const setIndexToNextElement = () => { const nextIndex = focusedIndex + 1; const elementsExists = focusedElementsRefs.current[nextIndex]; - setFocusedIndex(elementsExists ? nextIndex : initialIndex); + const nextFocusedIndex = elementsExists ? nextIndex : initialIndex; + setFocusedIndex(nextFocusedIndex); + focusElement(nextFocusedIndex); }; const setIndexPreviousElement = () => { const prevIndex = focusedIndex - 1; + let prevFocusedIndex = null; if (prevIndex >= initialIndex) { - setFocusedIndex(prevIndex); - return; + prevFocusedIndex = prevIndex; + } else { + prevFocusedIndex = Math.max(...Object.keys(focusedElementsRefs.current)); } - const lastIndex = Math.max(...Object.keys(focusedElementsRefs.current)); - setFocusedIndex(lastIndex); + setFocusedIndex(prevFocusedIndex); + focusElement(prevFocusedIndex); }; - useMounted(() => { - const focusedElementRef = focusedElementsRefs.current[focusedIndex]; - focusedElementRef?.current?.focus(); - }, [focusedIndex]); - const contextValue = React.useMemo( () => [ { focusedIndex, axis }, @@ -71,13 +81,11 @@ const useRovingHandler = ({ ref }) => { }); }; -export const List = React.forwardRef(({ children }, forwardedRef) => { +export const List = React.forwardRef(({ as = "div", children, ...props }, forwardedRef) => { const ref = React.useRef(); useRovingHandler({ ref }); - return React.cloneElement(React.Children.only(children), { - ref: mergeRefs([ref, children.ref, forwardedRef]), - }); + return jsx(as, { ...props, ref: mergeRefs([ref, forwardedRef]) }, children); }); /* ------------------------------------------------------------------------------------------------- diff --git a/components/system/components/GlobalCarousel/jumpers/EditChannels.js b/components/system/components/GlobalCarousel/jumpers/EditChannels.js index 978597b3..6d9b2a40 100644 --- a/components/system/components/GlobalCarousel/jumpers/EditChannels.js +++ b/components/system/components/GlobalCarousel/jumpers/EditChannels.js @@ -203,25 +203,25 @@ function Channels({ - -
    - {channels.map((channel, index) => ( - - - onAddFileToChannel(channel, channel.doesContainFile)} - title={channel.slatename} - style={{ maxWidth: "48ch" }} - > - {channel.slatename} - - - - ))} + + {channels.map((channel, index) => ( + + + onAddFileToChannel(channel, channel.doesContainFile)} + title={channel.slatename} + style={{ maxWidth: "48ch" }} + > + {channel.slatename} + + + + ))} - - + + + (e.stopPropagation(), onCreateChannel(searchQuery))} @@ -240,9 +240,9 @@ function Channels({ /> {searchQuery} - - -
    + + +