Skip to content

Commit 8734cea

Browse files
committed
feat: add group focus on click
1 parent 5a1fc8b commit 8734cea

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

packages/component/src/Middleware/ActivityGrouping/ui/PartGrouping/private/PartGroupingActivity.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { reactNode } from '@msinternal/botframework-webchat-react-valibot';
22
import { hooks } from 'botframework-webchat-api';
33
import { getOrgSchemaMessage, type WebChatActivity } from 'botframework-webchat-core';
4-
import React, { memo, useCallback, useMemo, useState } from 'react';
4+
import React, { memo, useCallback, useMemo, useState, type MouseEventHandler } from 'react';
55
import {
66
any,
77
array,
@@ -94,6 +94,11 @@ function FocusablePartGroupingActivity(props: FocusablePartGroupingActivityProps
9494
// When receive Escape key from descendant, focus back to the group.
9595
const handleLeaveFocusTrap = useCallback(() => focusSelf(), [focusSelf]);
9696

97+
// When the user press UP/DOWN arrow keys, we put a visual focus indicator around the focused group.
98+
// We should do the same for mouse, when the user click on the activity, we should also put a visual focus indicator around the activity.
99+
// We are doing it in event capture phase to prevent descendants from stopping event propagation to us.
100+
const handleMouseDownCapture: MouseEventHandler = useCallback(() => focusSelf(false), [focusSelf]);
101+
97102
const isActiveDescendant = groupingActivityDescendantId === activeDescendantId;
98103

99104
const activityElementMapRef = useActivityElementMapRef();
@@ -108,7 +113,11 @@ function FocusablePartGroupingActivity(props: FocusablePartGroupingActivityProps
108113
);
109114

110115
return (
111-
<TranscriptFocusContent focused={isActiveDescendant} ref={groupCallbackRef}>
116+
<TranscriptFocusContent
117+
focused={isActiveDescendant}
118+
onMouseDownCapture={handleMouseDownCapture}
119+
ref={groupCallbackRef}
120+
>
112121
<FocusTrap
113122
onFocus={handleDescendantFocus}
114123
onLeave={handleLeaveFocusTrap}

0 commit comments

Comments
 (0)