Skip to content

Commit 630e5c7

Browse files
authored
feat: add ContextMenu animations API and global close-on-click-outside configuration mechanism (#3067)
1 parent 7914e51 commit 630e5c7

14 files changed

Lines changed: 726 additions & 106 deletions

File tree

src/components/ChannelListItem/ChannelListItemActionButtons.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { type ComponentProps, type ComponentType, type ReactNode } from '
22

33
import clsx from 'clsx';
44
import { ContextMenu, useDialogIsOpen, useDialogOnNearestManager } from '../Dialog';
5+
import { useComponentContext } from '../../context';
56
import {
67
defaultChannelActionSet,
78
useBaseChannelActionSetFilter,
@@ -18,6 +19,7 @@ interface ChannelListItemActionButtonsInterface {
1819
}
1920

2021
export const ChannelListItemActionButtons: ChannelListItemActionButtonsInterface = () => {
22+
const { ContextMenu: ContextMenuComponent = ContextMenu } = useComponentContext();
2123
const { channel } = useChannelListItemContext();
2224
const [referenceElement, setReferenceElement] =
2325
React.useState<HTMLButtonElement | null>(null);
@@ -49,7 +51,7 @@ export const ChannelListItemActionButtons: ChannelListItemActionButtonsInterface
4951
{quickActionSet.map(({ Component, type }) => (
5052
<Component key={type} />
5153
))}
52-
<ContextMenu
54+
<ContextMenuComponent
5355
className='str-chat__channel-list-item__action-buttons-context-menu'
5456
dialogManagerId={dialogManager?.id}
5557
id={dialog.id}
@@ -62,7 +64,7 @@ export const ChannelListItemActionButtons: ChannelListItemActionButtonsInterface
6264
{dropdownActionSet.map(({ Component, type }) => (
6365
<Component key={type} />
6466
))}
65-
</ContextMenu>
67+
</ContextMenuComponent>
6668
</div>
6769
);
6870
};

src/components/Dialog/__tests__/DialogManagerContext.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ describe('DialogManagerContext', () => {
173173

174174
it('creates different managers for different IDs', () => {
175175
render(
176-
<DialogManagerProvider id={MANAGER_1_ID}>
177-
<DialogManagerProvider id={MANAGER_2_ID}>
176+
<DialogManagerProvider closeOnClickOutside={false} id={MANAGER_1_ID}>
177+
<DialogManagerProvider closeOnClickOutside={false} id={MANAGER_2_ID}>
178178
<DialogTestComponent dialogId='dialog-1' managerId={MANAGER_1_ID} />
179179
<DialogTestComponent dialogId='dialog-2' managerId={MANAGER_2_ID} />
180180
<TestComponent dialogManagerId={MANAGER_1_ID} />

src/components/Dialog/__tests__/DialogsManager.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ describe('DialogManager', () => {
3636
expect(dialogManager.openDialogCount).toBe(0);
3737
});
3838

39+
it('defaults manager closeOnClickOutside to true', () => {
40+
const dialogManager = new DialogManager();
41+
expect(dialogManager.closeOnClickOutside).toBe(true);
42+
});
43+
44+
it('accepts manager closeOnClickOutside config', () => {
45+
const dialogManager = new DialogManager({ closeOnClickOutside: false });
46+
expect(dialogManager.closeOnClickOutside).toBe(false);
47+
});
48+
3949
it('retrieves an existing dialog', () => {
4050
const dialogManager = new DialogManager();
4151
dialogManager.state['next']((current: any) => ({

0 commit comments

Comments
 (0)