From 032f56143e0a33ffe2155a98eeeab382e42b0fae Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Thu, 20 Jul 2023 15:58:24 +0200 Subject: [PATCH] Disable selection throughout the UI (#3487) --- src/components/common/Audio.tsx | 2 +- src/components/common/ChatExtra.tsx | 2 +- src/components/common/CustomEmojiPicker.tsx | 3 +- .../left/search/ChatMessageResults.tsx | 2 +- src/components/left/search/ChatResults.tsx | 4 +-- src/components/left/search/RecentContacts.tsx | 2 +- .../left/settings/SettingsPerformance.tsx | 2 +- src/components/mediaViewer/MediaViewer.tsx | 5 ---- .../mediaViewer/MediaViewerFooter.tsx | 4 ++- .../middle/composer/EmojiPicker.tsx | 2 +- .../middle/composer/StickerPicker.tsx | 4 +-- src/components/middle/message/Message.tsx | 2 +- .../middle/message/MessageContextMenu.scss | 1 + .../middle/message/ReactionPickerLimited.tsx | 2 +- src/components/right/Profile.scss | 5 ---- .../right/management/ManageChannel.tsx | 2 +- .../right/management/ManageGroup.tsx | 2 +- .../management/ManageGroupAdminRights.tsx | 22 +++++++------- .../management/ManageGroupPermissions.tsx | 30 +++++++++---------- .../management/ManageGroupUserPermissions.tsx | 30 +++++++++---------- .../right/management/ManageReactions.tsx | 2 +- .../right/management/ManageUser.tsx | 2 +- src/components/ui/ListItem.tsx | 2 +- src/components/ui/Menu.tsx | 2 +- src/components/ui/RangeSlider.tsx | 2 +- src/components/ui/TabList.tsx | 2 +- src/hooks/useContextMenuHandlers.ts | 4 +-- src/styles/index.scss | 7 +++-- 28 files changed, 72 insertions(+), 79 deletions(-) diff --git a/src/components/common/Audio.tsx b/src/components/common/Audio.tsx index 1bc9b8dc9..5045e4314 100644 --- a/src/components/common/Audio.tsx +++ b/src/components/common/Audio.tsx @@ -597,7 +597,7 @@ function renderSeekline( ) { return (
} > {bufferedRanges.map(({ start, end }) => ( diff --git a/src/components/common/ChatExtra.tsx b/src/components/common/ChatExtra.tsx index 4726795e5..e6e33dcbd 100644 --- a/src/components/common/ChatExtra.tsx +++ b/src/components/common/ChatExtra.tsx @@ -223,7 +223,7 @@ const ChatExtra: FC = ({ narrow isStatic > - + {renderText(description, ['br', 'links', 'emoji'])} {lang(userId ? 'UserBio' : 'Info')} diff --git a/src/components/common/CustomEmojiPicker.tsx b/src/components/common/CustomEmojiPicker.tsx index 7d548eff4..124fe9a1f 100644 --- a/src/components/common/CustomEmojiPicker.tsx +++ b/src/components/common/CustomEmojiPicker.tsx @@ -364,13 +364,12 @@ const CustomEmojiPicker: FC = ({ const headerClassName = buildClassName( pickerStyles.header, - 'no-selection no-scrollbar', + 'no-scrollbar', !shouldHideTopBorder && pickerStyles.headerWithBorder, ); const listClassName = buildClassName( pickerStyles.main, pickerStyles.main_customEmoji, - 'no-selection', IS_TOUCH_ENV ? 'no-scrollbar' : 'custom-scroll', pickerListClassName, ); diff --git a/src/components/left/search/ChatMessageResults.tsx b/src/components/left/search/ChatMessageResults.tsx index 64a84569e..f24a2123d 100644 --- a/src/components/left/search/ChatMessageResults.tsx +++ b/src/components/left/search/ChatMessageResults.tsx @@ -121,7 +121,7 @@ const ChatMessageResults: FC = ({ noFastList > {dateSearchQuery && ( -
+
= ({ noFastList > {dateSearchQuery && ( -
+
= ({ )} {Boolean(localResults.length) && (
diff --git a/src/components/left/search/RecentContacts.tsx b/src/components/left/search/RecentContacts.tsx index ae18d97e9..395b9e764 100644 --- a/src/components/left/search/RecentContacts.tsx +++ b/src/components/left/search/RecentContacts.tsx @@ -76,7 +76,7 @@ const RecentContacts: FC = ({
{topUserIds && (
-
+
{topUserIds.map((userId) => (
-
+
= ({ if (isMobile) { document.body.classList.toggle('is-media-viewer-open', isOpen); } - // Disable user selection if media viewer is open, to prevent accidental text selection - if (IS_TOUCH_ENV) { - document.body.classList.toggle('no-selection', isOpen); - } }, [isMobile, isOpen]); // eslint-disable-next-line no-null/no-null diff --git a/src/components/mediaViewer/MediaViewerFooter.tsx b/src/components/mediaViewer/MediaViewerFooter.tsx index 7735f1b8e..c0e5b369b 100644 --- a/src/components/mediaViewer/MediaViewerFooter.tsx +++ b/src/components/mediaViewer/MediaViewerFooter.tsx @@ -70,7 +70,9 @@ const MediaViewerFooter: FC = ({
{Boolean(text) && (
-

{text}

+

+ {text} +

)}
diff --git a/src/components/middle/composer/EmojiPicker.tsx b/src/components/middle/composer/EmojiPicker.tsx index ae6ab1a72..58d76d373 100644 --- a/src/components/middle/composer/EmojiPicker.tsx +++ b/src/components/middle/composer/EmojiPicker.tsx @@ -225,7 +225,7 @@ const EmojiPicker: FC = ({
{allCategories.map((category, i) => ( = ({ const headerClassName = buildClassName( styles.header, - 'no-selection no-scrollbar', + 'no-scrollbar', !shouldHideTopBorder && styles.headerWithBorder, ); @@ -348,7 +348,7 @@ const StickerPicker: FC = ({ ref={containerRef} onMouseMove={handleMouseMove} onScroll={handleContentScroll} - className={buildClassName(styles.main, 'no-selection', IS_TOUCH_ENV ? 'no-scrollbar' : 'custom-scroll')} + className={buildClassName(styles.main, IS_TOUCH_ENV ? 'no-scrollbar' : 'custom-scroll')} > {allSets.map((stickerSet, i) => ( = ({ }, [focusLastMessage, isLastInList, transcribedText, withVoiceTranscription]); const containerClassName = buildClassName( - 'Message message-list-item', + 'Message message-list-item text-selection', isFirstInGroup && 'first-in-group', isProtected && 'is-protected', isLastInGroup && 'last-in-group', diff --git a/src/components/middle/message/MessageContextMenu.scss b/src/components/middle/message/MessageContextMenu.scss index 2674da427..be0764739 100644 --- a/src/components/middle/message/MessageContextMenu.scss +++ b/src/components/middle/message/MessageContextMenu.scss @@ -1,6 +1,7 @@ .MessageContextMenu { position: absolute; font-size: 1rem; + user-select: none; &_items { overflow: auto; diff --git a/src/components/middle/message/ReactionPickerLimited.tsx b/src/components/middle/message/ReactionPickerLimited.tsx index b5185c2d4..ac114c4fb 100644 --- a/src/components/middle/message/ReactionPickerLimited.tsx +++ b/src/components/middle/message/ReactionPickerLimited.tsx @@ -82,7 +82,7 @@ const ReactionPickerLimited: FC = ({ return (
-
+
diff --git a/src/components/right/Profile.scss b/src/components/right/Profile.scss index 377c5b7b2..8c929d335 100644 --- a/src/components/right/Profile.scss +++ b/src/components/right/Profile.scss @@ -23,11 +23,6 @@ margin-bottom: 0; } - .inactive.no-selection { - user-select: auto; - -webkit-user-select: auto !important; - } - [dir="rtl"] { .Switcher { margin-left: 0; diff --git a/src/components/right/management/ManageChannel.tsx b/src/components/right/management/ManageChannel.tsx index 4f75d8a25..947ade4e8 100644 --- a/src/components/right/management/ManageChannel.tsx +++ b/src/components/right/management/ManageChannel.tsx @@ -294,7 +294,7 @@ const ManageChannel: FC = ({ {chatReactionsDescription} -
+
= ({ {!isPublicGroup && !hasLinkedChannel && Boolean(chatFullInfo) && ( -
+
= ({

{lang('EditAdminWhatCanDo')}

-
+
= ({ />
{isChannel && ( -
+
= ({
)} {isChannel && ( -
+
= ({ />
)} -
+
= ({ />
{!isChannel && ( -
+
= ({ />
)} -
+
= ({ />
{!isChannel && ( -
+
= ({ />
)} -
+
= ({ onChange={handlePermissionChange} />
-
+
= ({ />
{isForum && ( -
+
= ({
)} {!isChannel && ( -
+
= ({

{lang('ChannelPermissionsHeader')}

-
+
= ({ onChange={handlePermissionChange} />
-
+
= ({ isMediaDropdownOpen && 'DropdownList--open', )} > -
+
= ({ />
-
+
= ({ />
-
+
= ({ />
-
+
= ({ />
-
+
= ({ />
-
+
= ({ />
-
+
= ({ />
-
+
= ({ />
-
+
= ({
-
+
= ({ />
= ({ />
= ({ />
{isForum && ( -
+
= ({

{lang('UserRestrictionsCanDo')}

-
+
= ({ />
-
+
= ({ isMediaDropdownOpen && 'DropdownList--open', )} > -
+
= ({ />
-
+
= ({ />
-
+
= ({ />
-
+
= ({ />
-
+
= ({ />
-
+
= ({ />
-
+
= ({ />
-
+
= ({ />
-
+
= ({
-
+
= ({ onChange={handlePermissionChange} />
-
+
= ({ onChange={handlePermissionChange} />
-
+
= ({ />
{isForum && ( -
+
= ({ {lang('AvailableReactions')} {availableActiveReactions?.map(({ reaction, title }) => ( -
+
isSameReaction(reaction, r))} diff --git a/src/components/right/management/ManageUser.tsx b/src/components/right/management/ManageUser.tsx index 4b3008ede..eec6c4524 100644 --- a/src/components/right/management/ManageUser.tsx +++ b/src/components/right/management/ManageUser.tsx @@ -205,7 +205,7 @@ const ManageUser: FC = ({ onChange={handleLastNameChange} value={lastName} /> -
+
= ({ const fullClassName = buildClassName( 'ListItem', className, - !isStatic && 'no-selection', + isStatic && 'text-selection', ripple && 'has-ripple', narrow && 'narrow', disabled && 'disabled', diff --git a/src/components/ui/Menu.tsx b/src/components/ui/Menu.tsx index 4d29dc979..da3aa8596 100644 --- a/src/components/ui/Menu.tsx +++ b/src/components/ui/Menu.tsx @@ -143,7 +143,7 @@ const Menu: FC = ({
= ({
{options.map((option, index) => (
onChange(index)} > {option} diff --git a/src/components/ui/TabList.tsx b/src/components/ui/TabList.tsx index 6f5576b46..5217ff917 100644 --- a/src/components/ui/TabList.tsx +++ b/src/components/ui/TabList.tsx @@ -75,7 +75,7 @@ const TabList: FC = ({ return (
diff --git a/src/hooks/useContextMenuHandlers.ts b/src/hooks/useContextMenuHandlers.ts index 14b7acb3c..ca4c9b3a3 100644 --- a/src/hooks/useContextMenuHandlers.ts +++ b/src/hooks/useContextMenuHandlers.ts @@ -31,14 +31,14 @@ const useContextMenuHandlers = ( const handleBeforeContextMenu = useLastCallback((e: React.MouseEvent) => { if (!isMenuDisabled && e.button === 2) { requestMutation(() => { - addExtraClass(e.target as HTMLElement, 'no-selection'); + removeExtraClass(e.target as HTMLElement, 'text-selection'); }); } }); const handleContextMenu = useLastCallback((e: React.MouseEvent) => { requestMutation(() => { - removeExtraClass(e.target as HTMLElement, 'no-selection'); + addExtraClass(e.target as HTMLElement, 'text-selection'); }); if (isMenuDisabled || (shouldDisableOnLink && (e.target as HTMLElement).matches('a[href]'))) { diff --git a/src/styles/index.scss b/src/styles/index.scss index 9dd9f9daa..a324d00b7 100644 --- a/src/styles/index.scss +++ b/src/styles/index.scss @@ -111,9 +111,8 @@ body.cursor-ew-resize { visibility: hidden; } -.no-selection { - user-select: none; - -webkit-user-select: none !important; +.text-selection { + user-select: text !important; } .clearfix::after { @@ -164,6 +163,8 @@ body.cursor-ew-resize { } body:not(.is-ios) { + user-select: none; // On iOS, disallowing user selection breaks focus in text input fields + .custom-scroll { &::-webkit-scrollbar { width: 0.375rem;