-
Notifications
You must be signed in to change notification settings - Fork 2k
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
User mentions: add popover #24287
User mentions: add popover #24287
Conversation
Lint build failures should be fixed by #24308. |
793e4db
to
47463f8
Compare
Todo:
Possible improvements
|
300be0e
to
21e4f09
Compare
c02eb7b
to
926023c
Compare
316e981
to
511c64e
Compare
7548810
to
13b1fd5
Compare
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.
I'm a bit out of my elements with this change, so I'll provide feedback where I can.
It's very convenient to have this be testable in /devdocs/blocks/user-mentions
👍
// ]; | ||
//const { siteId } = this.props; | ||
const { query, showPopover } = this.state; | ||
const suggestions = [ |
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.
It might be useful to specify this using defaultProp.suggestions
. That way, it'll be easy to swap out the placeholder suggestions in the future.
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.
That's a smart idea :)
}; | ||
|
||
handleKeyUp = event => { |
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.
I'm unfamiliar with how this works - why do we handle user input in both handleKeyDown
and handleKeyUp
? Would handling it all in handleKeyUp
lead to unexpected behavior?
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.
keyDown
can repeat on a long press, but keyUp
only ever fires once, after the key has been released:
https://javascript.info/keyboard-events
If you long press an up/down arrow, we'd want it to keep scrolling through the suggestions, hence it's handled by keyDown 🎹
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ExampleInput from './example-input'; | ||
import withUserMentions from '../with-user-mentions'; | ||
|
||
const UserMentionsExampleInput = ( { onKeyPress } ) => <textarea onKeyPress={ onKeyPress } />; | ||
// @todo Move ref forwarding to the HOC | ||
const UserMentionsExampleInput = React.forwardRef( ( props, ref ) => ( |
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.
Interesting, this is the first time I've seen someone use forwardRef
.
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.
It's handy! I need access to the DOM node in the child component. I'm hoping to move the forwardRef
into the higher-order component later: #24518.
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.
Ah, gotcha; I think I understand this better now.
constructor( props ) { | ||
super( props ); | ||
// create a ref to store the textarea DOM element | ||
this.textInput = React.createRef(); |
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.
Does createRef
mark the textInput variable as a React reference?
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.
It does indeed.
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.
Oh! It's a pattern to deprecate callback refs. Got it :)
0593bd9
to
9232dfe
Compare
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.
Looks like a good place to start iterating from; I left some comments inline that you might find useful.
Something worth pointing out: I noticed a bug where a random rectangle would render on top of the textarea upon clicking on the textarea for the first time:
I wouldn't consider it a blocker for this PR, but figured you'd like to keep track of it.
top: nodeRect.top + caretPosition.top + 28, | ||
}; | ||
|
||
console.log( position ); // eslint-disable-line no-console |
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.
Perhaps a good time to use debug( position );
?
return suggestions.slice( 0, 10 ); | ||
} | ||
|
||
insertSuggestion = ( { user_login: userLogin } ) => { |
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.
Maybe autocompleteSuggestion
would be easier to understand?
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.
I agree, but will stick with insertSuggestion
for the moment to be consistent with Editor mentions.
Thanks for the 👀 @jsnmoon! |
Add textarea-caret package User mentions changes Update shrinkwrap Add styles back to _components
9232dfe
to
76015dd
Compare
Follows on from #24194, which created the user mentions block.
This PR adds a popover for suggestions, based on the current TinyMCE implementation in
client/components/tinymce/mentions
.To test
We're not seeking perfection with this one - smaller bugfixes and improvements can be created as followup issues. It's still using test data to populate usernames. As long as its basically functional and inserts usernames as expected, let's 🚢 and keep iterating on it.
Give it a spin at:
http://calypso.localhost:3000/devdocs/blocks/user-mentions