Skip to content

Commit

Permalink
Carousel: Fix focus capture (#33204)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitch-At-Work authored Nov 4, 2024
1 parent 2a6ab96 commit b9672fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: Ensure pointer events do not block future focus index changes",
"packageName": "@fluentui/react-carousel",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,28 @@ export const useCarouselCard_unstable = (
containerRef?.current?.scrollTo(0, 0);
selectPageByElement(e, e.currentTarget, false);
}
// Mouse focus event has been consumed
isMouseEvent.current = false;
},
[selectPageByElement, containerRef],
);

const handleMouseDown = (e: React.MouseEvent<HTMLDivElement>) => {
const handlePointerDown = (e: React.MouseEvent<HTMLDivElement>) => {
if (!e.defaultPrevented) {
isMouseEvent.current = true;
}
};
const handleMouseUp = (e: React.MouseEvent<HTMLDivElement>) => {

const handlePointerUp = (e: React.MouseEvent<HTMLDivElement>) => {
if (!e.defaultPrevented) {
isMouseEvent.current = false;
}
};

const onFocus = mergeCallbacks(props.onFocus, handleFocus);
const onMouseUp = mergeCallbacks(props.onMouseUp, handleMouseUp);
const onMouseDown = mergeCallbacks(props.onMouseDown, handleMouseDown);
const onFocusCapture = mergeCallbacks(props.onFocusCapture, handleFocus);
const onPointerUp = mergeCallbacks(props.onPointerUp, handlePointerUp);
const onPointerDown = mergeCallbacks(props.onPointerDown, handlePointerDown);

const state: CarouselCardState = {
autoSize,
components: {
Expand All @@ -103,9 +107,9 @@ export const useCarouselCard_unstable = (
tabIndex: cardFocus ? 0 : undefined,
...props,
id,
onFocus,
onMouseDown,
onMouseUp,
onFocusCapture,
onPointerUp,
onPointerDown,
...focusAttrProps,
}),
{ elementType: 'div' },
Expand Down

0 comments on commit b9672fa

Please sign in to comment.