-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[$1000] Clicking outside of the comment text won’t unselect the highlighted text #14402
Comments
Triggered auto assignment to @johncschuster ( |
I was able to reproduce this by following the reproduction steps above. 2023-01-19_08-30-57.mp4A few things to note, it seems that when you are clicking into the "user details" section of the chat (highlighted in orange in the screenshot below), it seems the highlighted text remains highlighted, but when you click into the "text" section of the chat (highlighted in pink in the screenshot below), the highlight goes away. |
Job added to Upwork: https://www.upwork.com/jobs/~01e5387a24edfdca63 |
Current assignee @johncschuster is eligible for the External assigner, not assigning anyone new. |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @rushatgabhane ( |
Current assignee @cead22 is eligible for the External assigner, not assigning anyone new. |
Proposalindex 581012838..b13c27a4c 100644
--- a/src/App.js
+++ b/src/App.js
@@ -16,6 +16,7 @@ import SafeArea from './components/SafeArea';
import * as Environment from './libs/Environment/Environment';
import {WindowDimensionsProvider} from './components/withWindowDimensions';
import {KeyboardStateProvider} from './components/withKeyboardState';
+import DomUtils from "./libs/DomUtils";
// For easier debugging and development, when we are in web we expose Onyx to the window, so you can more easily set data into Onyx
if (window && Environment.isDevelopment()) {
@@ -31,8 +32,17 @@ LogBox.ignoreLogs([
const fill = {flex: 1};
+/**
+ * We want to reset highlighted text range when user clicks outside of the text
+ * More details here: https://github.com/Expensify/App/issues/14402
+ * @param {Event} event
+ */
+const handleOnMouseDown = (event)=>{
+ DomUtils.removeSelectionRange(event)
+}
+
const App = () => (
- <GestureHandlerRootView style={fill}>
+ <GestureHandlerRootView onMouseDown={handleOnMouseDown} style={fill}>
<ComposeProviders
components={[
OnyxProvider, index 4e58ea3a0..08ce80b69 100644
--- a/src/libs/DomUtils/index.js
+++ b/src/libs/DomUtils/index.js
@@ -2,6 +2,12 @@ function blurActiveElement() {
document.activeElement.blur();
}
+function removeSelectionRange(e) {
+ if(e.button !== 0) return;
+ document.getSelection().removeAllRanges();
+}
+
export default {
blurActiveElement,
+ removeSelectionRange
}; index 0e796bc40..9fdab5f52 100644
--- a/src/libs/DomUtils/index.native.js
+++ b/src/libs/DomUtils/index.native.js
@@ -1,5 +1,7 @@
function blurActiveElement() {}
+function removeSelectionRange() {}
export default {
blurActiveElement,
+ removeSelectionRange
}; Result:Screen.Recording.2023-01-19.at.9.32.00.PM.movBy utilizing the there are multiple ways that we can implement my solution in
We can use all of these with the same output but i strongly recommend using It is strongly recommended to utilize the |
Content.
Root CauseIn the case explained in the issue above, the selected portion of text is still highlighted (i.e. selected) although elements outside the text are clicked. There are two screen recordings:
In the first case, the exact reason for the text still being highlighted is unknown. However, I suspect it has something to do with this explanation: https://developer.mozilla.org/en-US/docs/Web/API/Selection#behavior_of_selection_api_in_terms_of_editing_host_focus_changes. I'm assuming it is similar to the behavior of how text is still highlighted when we click on images or buttons in regular HTML. What this means is that there might be a need of altering possibly a lot of components in the already created components. In the second case, the exact reason for the text still being highlighted is exactly because of the same exact behavior of how text is still highlighted when we click on images or buttons in regular HTML. This is because the message box itself is a Pressable component. Initial Solutions with DrawbacksSolution 1Create a global Solution 2Let the sent text consume the press event, then make the Pressable message box to also have a handler in ProposalIn light of the previous solutions with drawbacks, I am proposing to create a wrapper for the text component. The wrapper will contain a handler for outside clicks deselecting text. This way, the selectable text component is standalone and the functionality of removing text selection is connected to the selectable text itself. |
@getusha @richard-here thank you both for the proposals, and @richard-here thanks for the explanation. Correct me if I'm wrong but it sounds like the text should be deselected whenever we click outside of it, and so long as we're not clicking a Pressable component, is that right, or is it more nuanced than that? In the example below, that seems to work well when I click on someone's avatar, but not so much when I click the X to close the dialog -- which is inside a Pressable component, or the semi-transparent overlay, which is also inside a Pressable component. That said, it looks like GH isn't very consistent with this either I think we probably want to define what we want our behavior to be before writing up the solution -- though one valid approach is to "deselect when you click/tap a non-Pressable component outside of the selected element" I'm going raise this in #expensify-open-source |
@cead22 interesting! but you can check that behavior doesn't exist on safari, so it shouldn't concern us? Screen.Recording.2023-01-20.at.1.32.35.PM.mov |
@cead22 i see, it's pretty inconsistent, FWIW keeping it focused on Pressable press? |
Hello 👋, I'm not a huge fan of any proposals here. Handling mouse or press events seems like a hack. We could find what's preventing the text being unselected, and fix that instead. What do you think? |
@richard-here you might be onto something with the root cause #14402 (comment) |
Proposaldiff --git a/src/styles/styles.js b/src/styles/styles.js
index 71fed02015..cf29954d03 100644
--- a/src/styles/styles.js
+++ b/src/styles/styles.js
@@ -1238,10 +1238,10 @@ const styles = {
overflow: 'hidden',
// Starting version 6.3.2 @react-navigation/drawer adds "user-select: none;" to its container.
- // We add user-select-auto to the inner component to prevent incorrect triple-click text selection.
- // For further explanation see - https://github.com/Expensify/App/pull/12730/files#r1022883823
- userSelect: 'auto',
- WebkitUserSelect: 'auto',
+ // We add "user-select: text;" to the inner component to prevent incorrect triple-click text selection.
+ // For further explanation see - https://github.com/Expensify/App/pull/12730/files#r1022883823 and https://github.com/Expensify/App/issues/14402
+ userSelect: 'text',
+ WebkitUserSelect: 'text',
},
appContentHeader: { RCABrowsers deselect the current text only if the mouse down target is an element that can be selected ( If you look into the source code you will see one of the main wrapper is using The thing is apparently we are aware of this as I have seen some comments confirming this, and to cover that issue we used The problem is that using
I think the best we can do and the easiest fix is to use ResultsKooha-2023-01-21-00-40-08.mp4 |
Looks like something related to As a reminder, please make sure that all proposals are not workarounds and that any and all attempt to fix the issue holistically have been made before proceeding with a solution. Proposals to change our Feel free to drop a note in #expensify-open-source with any questions. |
Proposal
Additional Explanation on Root CaseI have been doing further reading because it is interesting and I want to shed some light regarding the root cause. Here is what I have found.
This explains the root cause of the behavior we are seeing. Better ProposalBehavior ChangesAs mentioned here: #14402 (comment), altering the window's behavior on click is hack-ish. I think the best way to make it not hack-ish (i.e. altering the default browser's behavior when clicking), we should instead make all components selectable in the whole app, including Pressable components. I still think it's good UX. This also means that SolutionTo make a component selectable, we can use the CSS property
Here is a screenshot of what I meant by the parent's If we change the parent's With this, clicking on anywhere should collapse the existing range and make the screen-capture.2.mov |
@rushatgabhane the root cause is very complicated and wired and i tried to understand it fully and i present it as follows 😅 There was an issue #7462
I just wanted to comment this Just help prevent future issues related to this, because this looks related ProposalInteraction/index.js
index 7b971e7268..3881125e95 100644
--- a/src/components/PressableWithSecondaryInteraction/index.js
+++ b/src/components/PressableWithSecondaryInteraction/index.js
@@ -43,7 +43,7 @@ class PressableWithSecondaryInteraction extends Component {
// On Web, Text does not support LongPress events thus manage inline mode with styling instead of using Text.
return (
<Pressable
- style={this.props.inline && styles.dInline}
+ style={[this.props.inline && styles.dInline, styles.userSelectText]}
onPressIn={this.props.onPressIn}
onLongPress={(e) => {
if (DeviceCapabilities.hasHoverSupport()) { ResultScreen.Recording.2023-01-21.at.1.56.28.PM.mov |
discussion on slack |
Still discussing here https://expensify.slack.com/archives/C01GTK53T8Q/p1674580475813759?thread_ts=1674249705.438009&cid=C01GTK53T8Q, but I'm proposing we close this issue. I'm going to leave it open for now to let other chime in |
Closing per slack discussion |
If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
Action Performed:
Expected Result:
The text selected range should be reset / unselected
Actual Result:
The text selection range stays highlighted
Workaround:
unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Version Number: 1.2.56-0
Reproducible in staging?: y
Reproducible in production?: y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos:
Recording.1327.mp4
Screen.Recording.2023-01-18.at.10.55.11.AM.1.mov
Expensify/Expensify Issue URL:
Issue reported by: @getusha
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1674068409564519
View all open jobs on GitHub
Upwork Automation - Do Not Edit
The text was updated successfully, but these errors were encountered: