Skip to content

Commit b9672fa

Browse files
Carousel: Fix focus capture (#33204)
1 parent 2a6ab96 commit b9672fa

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix: Ensure pointer events do not block future focus index changes",
4+
"packageName": "@fluentui/react-carousel",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-carousel/library/src/components/CarouselCard/useCarouselCard.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,28 @@ export const useCarouselCard_unstable = (
7373
containerRef?.current?.scrollTo(0, 0);
7474
selectPageByElement(e, e.currentTarget, false);
7575
}
76+
// Mouse focus event has been consumed
77+
isMouseEvent.current = false;
7678
},
7779
[selectPageByElement, containerRef],
7880
);
7981

80-
const handleMouseDown = (e: React.MouseEvent<HTMLDivElement>) => {
82+
const handlePointerDown = (e: React.MouseEvent<HTMLDivElement>) => {
8183
if (!e.defaultPrevented) {
8284
isMouseEvent.current = true;
8385
}
8486
};
85-
const handleMouseUp = (e: React.MouseEvent<HTMLDivElement>) => {
87+
88+
const handlePointerUp = (e: React.MouseEvent<HTMLDivElement>) => {
8689
if (!e.defaultPrevented) {
8790
isMouseEvent.current = false;
8891
}
8992
};
9093

91-
const onFocus = mergeCallbacks(props.onFocus, handleFocus);
92-
const onMouseUp = mergeCallbacks(props.onMouseUp, handleMouseUp);
93-
const onMouseDown = mergeCallbacks(props.onMouseDown, handleMouseDown);
94+
const onFocusCapture = mergeCallbacks(props.onFocusCapture, handleFocus);
95+
const onPointerUp = mergeCallbacks(props.onPointerUp, handlePointerUp);
96+
const onPointerDown = mergeCallbacks(props.onPointerDown, handlePointerDown);
97+
9498
const state: CarouselCardState = {
9599
autoSize,
96100
components: {
@@ -103,9 +107,9 @@ export const useCarouselCard_unstable = (
103107
tabIndex: cardFocus ? 0 : undefined,
104108
...props,
105109
id,
106-
onFocus,
107-
onMouseDown,
108-
onMouseUp,
110+
onFocusCapture,
111+
onPointerUp,
112+
onPointerDown,
109113
...focusAttrProps,
110114
}),
111115
{ elementType: 'div' },

0 commit comments

Comments
 (0)