From 810d5fef64edd8b0c33c519463c6d26dc653f1df Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Wed, 27 Dec 2023 14:43:59 +0800 Subject: [PATCH] fix: disable top input when no access Signed-off-by: Lin Wang --- public/chat_header_button.test.tsx | 35 ++++++++++++++++++++++++++++++ public/chat_header_button.tsx | 6 ++++- 2 files changed, 40 insertions(+), 1 deletion(-) 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} />