3

请你帮我如何从下到上改变它的位置?我想在文本顶部而不是底部显示提及列表。关于表情符号列表的相同问题。

示例链接。

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

4

positionSuggestions您可以使用配置选项来实现它。此选项适用于插件mentionemoji插件。

文档摘录:

职位建议

该函数可用于操作包含建议的弹出框的位置。它接收一个对象作为参数,该对象包含包含@的修饰搜索字符串周围的可见矩形。此外,该对象还包含 prevProps、prevState、state 和 props。应该返回一个可以包含各种样式的对象。定义的属性将作为内联样式应用。

constructor您应该以这种方式创建插件:

constructor(props) {
  super(props);

  this.mentionPlugin = createMentionPlugin({
    positionSuggestions: (settings) => {
      return {
        left: settings.decoratorRect.left + 'px',
        top: settings.decoratorRect.top - 40 + 'px', // change this value (40) for manage the distance between cursor and bottom edge of popover
        display: 'block',
        transform: 'scale(1) translateY(-100%)', // transition popover on the value of its height
        transformOrigin: '1em 0% 0px',
        transition: 'all 0.25s cubic-bezier(0.3, 1.2, 0.2, 1)'
      };
    }
  });
}

render方法:

render() {
  const { MentionSuggestions } = this.mentionPlugin;
  const plugins = [this.mentionPlugin];

  return (
    <div className={editorStyles.editor} onClick={this.focus}>
      <Editor
        editorState={this.state.editorState}
        onChange={this.onChange}
        plugins={plugins}
        ref={(element) => { this.editor = element; }}
      />
      <div style={{ visibility: this.state.suggestions.length ? 'visible' : 'hidden'}}>
        <MentionSuggestions
          onSearchChange={this.onSearchChange}
          suggestions={this.state.suggestions}
          onAddMention={this.onAddMention}
        />
      </div>
    </div>
  );
}

在此处检查工作示例 - https://codesandbox.io/s/w62x3472k7

于 2017-11-10T21:19:48.373 回答