-
Notifications
You must be signed in to change notification settings - Fork 4k
prevent focus event when long press in emoji suggestion component #17788
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
Changes from all commits
05b7bcd
20a16f2
bd68abb
65c466e
7958b74
d8a0468
2e8f5ce
273b5b8
384698c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| const propTypes = { | ||
| /** The index of the highlighted emoji */ | ||
| highlightedEmojiIndex: PropTypes.number, | ||
|
|
||
| /** Array of suggested emoji */ | ||
| emojis: PropTypes.arrayOf(PropTypes.shape({ | ||
| /** The emoji code */ | ||
| code: PropTypes.string, | ||
|
|
||
| /** The name of the emoji */ | ||
| name: PropTypes.string, | ||
| })).isRequired, | ||
|
|
||
| /** Fired when the user selects an emoji */ | ||
| onSelect: PropTypes.func.isRequired, | ||
|
|
||
| /** Emoji prefix that follows the colon */ | ||
| prefix: PropTypes.string.isRequired, | ||
|
|
||
| /** Show that we can use large emoji picker. | ||
| * Depending on available space and whether the input is expanded, we can have a small or large emoji suggester. | ||
| * When this value is false, the suggester will have a height of 2.5 items. When this value is true, the height can be up to 5 items. */ | ||
| isEmojiPickerLarge: PropTypes.bool.isRequired, | ||
|
|
||
| /** Show that we should include ReportRecipientLocalTime view height */ | ||
| shouldIncludeReportRecipientLocalTimeHeight: PropTypes.bool.isRequired, | ||
|
|
||
| /** Stores user's preferred skin tone */ | ||
| preferredSkinToneIndex: PropTypes.number.isRequired, | ||
|
|
||
| /** A ref to forward to the suggestion container */ | ||
| forwardedRef: PropTypes.object, | ||
| }; | ||
|
|
||
| const defaultProps = { | ||
| highlightedEmojiIndex: 0, | ||
| }; | ||
|
|
||
| export {propTypes, defaultProps}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import React from 'react'; | ||
| import BaseEmojiSuggestions from './BaseEmojiSuggestions'; | ||
| import * as DeviceCapabilities from '../../libs/DeviceCapabilities'; | ||
| import {propTypes, defaultProps} from './emojiSuggestionsPropTypes'; | ||
|
|
||
| /** | ||
| * On the mobile-web platform, when long-pressing on emoji suggestions, | ||
| * we need to prevent focus shifting to avoid blurring the main input which makes the emoji picker close and adds the emoji to the composer. | ||
| * The desired pattern for all platforms is to do nothing on long-press. | ||
| * On the native platform, tapping on emoji suggestions will not blur the main input. | ||
| */ | ||
|
|
||
| const EmojiSuggestions = (props) => { | ||
| const containerRef = React.useRef(null); | ||
| React.useEffect(() => { | ||
| const container = containerRef.current; | ||
| if (!container) { | ||
| return; | ||
| } | ||
| container.onpointerdown = (e) => { | ||
|
tgolen marked this conversation as resolved.
|
||
| if (DeviceCapabilities.hasHoverSupport()) { | ||
|
Member
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. NAB: I'm curious - Does this mean this bug will occur on mWeb devices that support a stylus?? function hasHoverSupport() {
return !window.matchMedia('(hover: none)').matches;
}
Contributor
Author
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. The purpose here is that for desktop web platforms that support hover, we don't need to prevent its default behavior, otherwise the emoji will be placed in the main composer immediately after the long-press is released. |
||
| return; | ||
| } | ||
| e.preventDefault(); | ||
| }; | ||
| return () => container.onpointerdown = null; | ||
| }, []); | ||
|
|
||
| return ( | ||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| <BaseEmojiSuggestions {...props} ref={containerRef} /> | ||
| ); | ||
| }; | ||
|
|
||
| EmojiSuggestions.propTypes = propTypes; | ||
| EmojiSuggestions.defaultProps = defaultProps; | ||
| EmojiSuggestions.displayName = 'EmojiSuggestions'; | ||
|
|
||
| export default EmojiSuggestions; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import React from 'react'; | ||
| import BaseEmojiSuggestions from './BaseEmojiSuggestions'; | ||
| import {propTypes, defaultProps} from './emojiSuggestionsPropTypes'; | ||
|
|
||
| const EmojiSuggestions = props => ( | ||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| <BaseEmojiSuggestions {...props} /> | ||
| ); | ||
|
|
||
| EmojiSuggestions.propTypes = propTypes; | ||
| EmojiSuggestions.defaultProps = defaultProps; | ||
| EmojiSuggestions.displayName = 'EmojiSuggestions'; | ||
|
|
||
| export default EmojiSuggestions; |
Uh oh!
There was an error while loading. Please reload this page.