【问题标题】:Mention list and emoji top position (Draft.js)提及列表和表情符号顶部位置(Draft.js)
【发布时间】:2018-04-23 22:19:51
【问题描述】:

请您帮我如何将其位置从底部更改为顶部? 我想在文本顶部而不是底部显示提及列表。 关于表情符号列表的相同问题。

Example link.

【问题讨论】:

  • 我的解决方案适合您的问题吗?也许我不正确地理解你的问题。
  • 这是我使用的,顶部不显示列表 ` return { left: settings.decoratorRect.left + 'px', top: settings.decoratorRect.top - 40 + 'px', //更改此值 (40) 以管理光标和弹出框底部边缘之间的距离 display: 'block', transform: 'scale(1) translateY(-100%)', // 根据其高度值转换弹出框 transformOrigin: '1em 0% 0px', 过渡: '所有 0.25s 立方贝塞尔曲线(0.3, 1.2, 0.2, 1)', 位置: 'absolute' }; `

标签: reactjs emoji draftjs mention draft-js-plugins


【解决方案1】:

您可以使用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

【讨论】:

  • 我刚刚使用了你的 css 函数,但使用这个 css 它没有在顶部显示提及列表。我附上了图片,你可以检查它正在下降,我什至看不到
  • 奇怪。对我来说,它有效。检查此代码框 - codesandbox.io/s/x2r59zo4j4 我希望它会对您有所帮助。
  • 谢谢!就我而言,还需要一个position: 'fixed'
  • 谢谢!就我而言,还需要一个职位:“固定”。同样对于未来的人,请查看this,这是一个很好的解决方案
  • 感谢@HongboMiao 使用 position: 'fixed' 它现在终于可以使用了。感谢您的解决方案。
猜你喜欢
  • 2020-02-18
  • 2021-08-24
  • 1970-01-01
  • 1970-01-01
  • 2017-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-13
相关资源
最近更新 更多