diff --git a/public/chat_header_button.test.tsx b/public/chat_header_button.test.tsx
index 5db80eda..820f4c53 100644
--- a/public/chat_header_button.test.tsx
+++ b/public/chat_header_button.test.tsx
@@ -159,4 +159,39 @@ describe('', () => {
});
expect(screen.getByLabelText('chat input')).toHaveFocus();
});
+
+ it('should disable chat input when no access', () => {
+ render(
+
+ );
+ expect(screen.getByLabelText('chat input')).toBeDisabled();
+ });
+
+ it('should not focus on chat input when no access and pressing global shortcut', () => {
+ render(
+
+ );
+ expect(screen.getByLabelText('chat input')).not.toHaveFocus();
+ fireEvent.keyDown(document.body, {
+ key: '/',
+ code: 'NumpadDivide',
+ charCode: 111,
+ metaKey: true,
+ });
+ expect(screen.getByLabelText('chat input')).not.toHaveFocus();
+ });
});
diff --git a/public/chat_header_button.tsx b/public/chat_header_button.tsx
index c08c2e97..54b37c2c 100644
--- a/public/chat_header_button.tsx
+++ b/public/chat_header_button.tsx
@@ -124,6 +124,9 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
};
useEffect(() => {
+ if (!props.userHasAccess) {
+ return;
+ }
const onGlobalMouseUp = (e: KeyboardEvent) => {
if (e.metaKey && e.key === '/') {
inputRef.current?.focus();
@@ -134,7 +137,7 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
return () => {
document.removeEventListener('keydown', onGlobalMouseUp);
};
- }, []);
+ }, [props.userHasAccess]);
return (
<>
@@ -179,6 +182,7 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
)}
}
+ disabled={!props.userHasAccess}
/>