-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix: intercept mouse selection when out of input field #42823
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
40aaf0f
progress..
dragnoir 3f7fb92
fix mouse leave
dragnoir d1409fd
Merge branch 'main' into 41803-fix
dragnoir bb768a4
lint
dragnoir fd90ced
fix ts
dragnoir c0701b3
remove console.log
dragnoir f715455
removce comments
dragnoir af76e42
remove comment
dragnoir 01f3ae8
fix code
dragnoir cdea07c
Merge branch 'Expensify:main' into 41803-fix
dragnoir f66765b
Merge branch 'Expensify:main' into 41803-fix
dragnoir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ import * as Expensicons from '@components/Icon/Expensicons'; | |||||
import OfflineWithFeedback from '@components/OfflineWithFeedback'; | ||||||
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback'; | ||||||
import useHover from '@hooks/useHover'; | ||||||
import {useMouseContext} from '@hooks/useMouseContext'; | ||||||
import useSyncFocus from '@hooks/useSyncFocus'; | ||||||
import useTheme from '@hooks/useTheme'; | ||||||
import useThemeStyles from '@hooks/useThemeStyles'; | ||||||
|
@@ -36,12 +37,19 @@ function BaseListItem<TItem extends ListItem>({ | |||||
const theme = useTheme(); | ||||||
const styles = useThemeStyles(); | ||||||
const {hovered, bind} = useHover(); | ||||||
const {isMouseDownOnInput} = useMouseContext(); | ||||||
|
||||||
const pressableRef = useRef<View>(null); | ||||||
|
||||||
// Sync focus on an item | ||||||
useSyncFocus(pressableRef, Boolean(isFocused), shouldSyncFocus); | ||||||
|
||||||
const {setMouseUp} = useMouseContext(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const handleMouseUp = (e: React.MouseEvent<Element, MouseEvent>) => { | ||||||
e.stopPropagation(); | ||||||
setMouseUp(); | ||||||
}; | ||||||
|
||||||
const rightHandSideComponentRender = () => { | ||||||
if (canSelectMultiple || !rightHandSideComponent) { | ||||||
return null; | ||||||
|
@@ -67,6 +75,10 @@ function BaseListItem<TItem extends ListItem>({ | |||||
{...bind} | ||||||
ref={pressableRef} | ||||||
onPress={(e) => { | ||||||
if (isMouseDownOnInput) { | ||||||
e?.stopPropagation(); // Preventing the click action | ||||||
return; | ||||||
} | ||||||
if (shouldPreventEnterKeySubmit && e && 'key' in e && e.key === CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey) { | ||||||
return; | ||||||
} | ||||||
|
@@ -82,6 +94,8 @@ function BaseListItem<TItem extends ListItem>({ | |||||
id={keyForList ?? ''} | ||||||
style={pressableStyle} | ||||||
onFocus={onFocus} | ||||||
onMouseUp={handleMouseUp} | ||||||
onMouseLeave={handleMouseUp} | ||||||
tabIndex={item.tabIndex} | ||||||
> | ||||||
<View style={wrapperStyle}> | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||
import type {ReactNode} from 'react'; | ||||
import React, {createContext, useContext, useMemo, useState} from 'react'; | ||||
|
||||
type MouseContextProps = { | ||||
isMouseDownOnInput: boolean; | ||||
setMouseDown: () => void; | ||||
setMouseUp: () => void; | ||||
}; | ||||
|
||||
// Create a context with default values and handlers | ||||
dragnoir marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
const MouseContext = createContext<MouseContextProps>({ | ||||
isMouseDownOnInput: false, | ||||
setMouseDown: () => {}, | ||||
setMouseUp: () => {}, | ||||
}); | ||||
|
||||
type MouseProviderProps = { | ||||
children: ReactNode; | ||||
}; | ||||
|
||||
// Context provider component | ||||
dragnoir marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
function MouseProvider({children}: MouseProviderProps) { | ||||
const [isMouseDownOnInput, setIsMouseDownOnInput] = useState(false); | ||||
|
||||
const setMouseDown = () => setIsMouseDownOnInput(true); | ||||
const setMouseUp = () => setIsMouseDownOnInput(false); | ||||
|
||||
const value = useMemo(() => ({isMouseDownOnInput, setMouseDown, setMouseUp}), [isMouseDownOnInput]); | ||||
|
||||
return <MouseContext.Provider value={value}>{children}</MouseContext.Provider>; | ||||
} | ||||
|
||||
// Custom hook to use the mouse context | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
const useMouseContext = () => useContext(MouseContext); | ||||
|
||||
export {MouseProvider, useMouseContext}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.