Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

User mentions: add popover #24287

Merged
merged 9 commits into from
May 1, 2018
Merged

Conversation

bluefuton
Copy link
Contributor

@bluefuton bluefuton commented Apr 18, 2018

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.

screen shot 2018-04-27 at 3 36 45 pm

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

@bluefuton bluefuton added [Status] In Progress [Feature] Reader The reader site on Calypso. labels Apr 18, 2018
@bluefuton bluefuton self-assigned this Apr 18, 2018
@matticbot
Copy link
Contributor

@bluefuton
Copy link
Contributor Author

Lint build failures should be fixed by #24308.

@bluefuton bluefuton force-pushed the add/reader/user-mentions-block-popover branch from 793e4db to 47463f8 Compare April 19, 2018 02:54
@bluefuton
Copy link
Contributor Author

bluefuton commented Apr 19, 2018

Todo:

  • allow popover position to be manually specified (new PR: Popover: allow custom position to be specified聽#24346) and update this PR after it lands
  • adjust position on resize
  • handle end of line oddities (popup appears at the start of next line)
  • hide popover arrow (in CSS, not with prop)
  • browser test in IE, Safari, FF

Possible improvements

  • move example input forwardRef into the HOC
  • find caret position of @ rather than using current caret position, and use that for popup position (seen when starting a new line or resizing) - getCaretPosition() can accept this position as an argument rather than selectionEnd
  • sometimes suggestion popup is not fully visible when near the edge of the viewport and also edge of the text input
  • improve behaviour when prepending an @ to an existing word (currently inserts before it, even if the following word is the same)
  • cursor jumps to next line briefly during insertion when using enter
  • textbox loses focus during insertion when not picking with keyboard
  • add RTL support

@bluefuton bluefuton force-pushed the add/reader/user-mentions-block-popover branch from 300be0e to 21e4f09 Compare April 20, 2018 00:41
@bluefuton bluefuton added this to the Reader: add @mentions milestone Apr 20, 2018
@bluefuton bluefuton force-pushed the add/reader/user-mentions-block-popover branch from c02eb7b to 926023c Compare April 24, 2018 01:22
@bluefuton bluefuton force-pushed the add/reader/user-mentions-block-popover branch 2 times, most recently from 316e981 to 511c64e Compare April 26, 2018 01:01
@bluefuton bluefuton added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Apr 27, 2018
@bluefuton bluefuton requested review from westi and jsnmoon April 27, 2018 04:03
@bluefuton bluefuton force-pushed the add/reader/user-mentions-block-popover branch from 7548810 to 13b1fd5 Compare April 27, 2018 04:17
Copy link
Member

@jsnmoon jsnmoon left a 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 = [
Copy link
Member

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.

Copy link
Contributor Author

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 => {
Copy link
Member

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?

Copy link
Contributor Author

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 ) => (
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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();
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@jsnmoon jsnmoon Apr 30, 2018

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 :)

Copy link
Member

@jsnmoon jsnmoon left a 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:

2018-04-30 15_53_31

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
Copy link
Member

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 } ) => {
Copy link
Member

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?

Copy link
Contributor Author

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.

@bluefuton
Copy link
Contributor Author

Thanks for the 馃憖 @jsnmoon!

@bluefuton bluefuton force-pushed the add/reader/user-mentions-block-popover branch from 9232dfe to 76015dd Compare May 1, 2018 21:48
@bluefuton bluefuton merged commit b9a5e74 into master May 1, 2018
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 1, 2018
@bluefuton bluefuton deleted the add/reader/user-mentions-block-popover branch May 13, 2018 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Reader The reader site on Calypso.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants