Skip to content

Commit

Permalink
manage tabIndex of overflow container overflow menu (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
heswell authored Oct 16, 2023
1 parent 7849d49 commit bd48952
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const WrapContainer = React.memo(
icon={overflowIcon}
menuBuilder={menuBuilder}
menuActionHandler={menuActionHandler}
tabIndex={-1}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export const useOverflowContainer = ({
// Drag drop needs a ref to container
const containerRef = useRef<HTMLDivElement | null>(null);

const setOverflowTabIndex = useCallback((tabIndex: "0" | "-1") => {
if (containerRef.current) {
containerRef.current
.querySelector(".vuuOverflowContainer-OverflowIndicator button")
?.setAttribute("tabindex", tabIndex);
}
}, []);

const handleResize = useCallback(async () => {
if (container) {
let [nonWrapped, wrapped] = getNonWrappedAndWrappedItems(
Expand All @@ -62,9 +70,16 @@ export const useOverflowContainer = ({
wrapped = NO_WRAPPED_ITEMS;
}
}

if (wrappedItemsRef.current.length === 0 && wrapped.length > 0) {
setOverflowTabIndex("0");
} else if (wrappedItemsRef.current.length > 0 && wrapped.length === 0) {
setOverflowTabIndex("-1");
}

wrappedItemsRef.current = wrapped;
}
}, [container, orientation]);
}, [container, orientation, setOverflowTabIndex]);

const hasOverflowItem = (
opt: unknown
Expand Down

0 comments on commit bd48952

Please sign in to comment.