Skip to content

Commit 960c1f9

Browse files
authored
fix: keep the distance of command menus constant from the invoking button (#3049)
1 parent cdaf480 commit 960c1f9

File tree

2 files changed

+54
-23
lines changed

2 files changed

+54
-23
lines changed

src/components/MessageComposer/AttachmentSelector/AttachmentSelector.tsx

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,43 @@ import {
4949
CommandsSubmenuHeader,
5050
} from './CommandsMenu';
5151

52-
const AttachmentSelectorMenuInitButtonIcon = () => {
52+
const AttachmentSelectorMenuInitButtonIcon = ({ className }: { className?: string }) => {
5353
const { AttachmentSelectorInitiationButtonContents } = useComponentContext();
5454

5555
if (AttachmentSelectorInitiationButtonContents) {
56-
return <AttachmentSelectorInitiationButtonContents />;
56+
return (
57+
<span className={className}>
58+
<AttachmentSelectorInitiationButtonContents />
59+
</span>
60+
);
5761
}
5862

59-
return <IconPlusLarge className='str-chat__attachment-selector__menu-button__icon' />;
63+
return (
64+
<IconPlusLarge
65+
className={clsx('str-chat__attachment-selector__menu-button__icon', className)}
66+
/>
67+
);
6068
};
6169

62-
export const AttachmentSelectorButton = forwardRef<HTMLButtonElement, ButtonProps>(
63-
function AttachmentSelectorButton({ className, ...props }, ref) {
64-
return (
65-
<Button
66-
appearance='outline'
67-
circular
68-
className={clsx('str-chat__attachment-selector__menu-button', className)}
69-
data-testid='invoke-attachment-selector-button'
70-
size='lg'
71-
variant='secondary'
72-
{...props}
73-
ref={ref}
74-
>
75-
<AttachmentSelectorMenuInitButtonIcon />
76-
</Button>
77-
);
78-
},
79-
);
70+
export const AttachmentSelectorButton = forwardRef<
71+
HTMLButtonElement,
72+
ButtonProps & { iconClassName?: string }
73+
>(function AttachmentSelectorButton({ className, iconClassName, ...props }, ref) {
74+
return (
75+
<Button
76+
appearance='outline'
77+
circular
78+
className={clsx('str-chat__attachment-selector__menu-button', className)}
79+
data-testid='invoke-attachment-selector-button'
80+
size='lg'
81+
variant='secondary'
82+
{...props}
83+
ref={ref}
84+
>
85+
<AttachmentSelectorMenuInitButtonIcon className={iconClassName} />
86+
</Button>
87+
);
88+
});
8089

8190
export const SimpleAttachmentSelector = () => {
8291
const { channelCapabilities } = useChannelStateContext();
@@ -360,10 +369,10 @@ export const AttachmentSelector = ({
360369
aria-expanded={menuDialogIsOpen}
361370
aria-haspopup='true'
362371
aria-label={t('aria/Open Attachment Selector')}
363-
className={clsx('str-chat__prepare-rotate45', {
372+
disabled={isCooldownActive}
373+
iconClassName={clsx('str-chat__prepare-rotate45', {
364374
'str-chat__rotate45': menuDialogIsOpen,
365375
})}
366-
disabled={isCooldownActive}
367376
onClick={() => menuDialog?.toggle()}
368377
ref={menuButtonRef}
369378
/>

src/components/MessageComposer/__tests__/AttachmentSelector.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,28 @@ const renderComponent = async ({
130130
};
131131

132132
describe('AttachmentSelector', () => {
133+
it('applies rotate classes to icon content and not to the invoke button', async () => {
134+
await renderComponent();
135+
136+
const invokeButton = screen.getByTestId('invoke-attachment-selector-button');
137+
138+
expect(invokeButton).not.toHaveClass('str-chat__prepare-rotate45');
139+
expect(invokeButton).not.toHaveClass('str-chat__rotate45');
140+
141+
const icon = invokeButton.querySelector(
142+
'.str-chat__attachment-selector__menu-button__icon',
143+
);
144+
expect(icon).toHaveClass('str-chat__prepare-rotate45');
145+
expect(icon).not.toHaveClass('str-chat__rotate45');
146+
147+
await invokeMenu();
148+
149+
expect(invokeButton).not.toHaveClass('str-chat__prepare-rotate45');
150+
expect(invokeButton).not.toHaveClass('str-chat__rotate45');
151+
expect(icon).toHaveClass('str-chat__prepare-rotate45');
152+
expect(icon).toHaveClass('str-chat__rotate45');
153+
});
154+
133155
it('renders with all the buttons if all the permissions are granted', async () => {
134156
await renderComponent();
135157
await invokeMenu();

0 commit comments

Comments
 (0)