首页 > 解决方案 > 单击外部后,ngx-color-picker 对话框关闭

问题描述

我在我们的项目中使用了 ngx-color-picker。但我遇到的问题是,每当我在对话框外单击时,它都会关闭。如果在对话框之外单击它,我不想关闭对话框。ngx-color-picker 中是否有任何内置事件可以解决这种情况?

我使用了这个包: https ://www.npmjs.com/package/ngx-color-picker

任何帮助都感激不尽。

标签: javascriptangular

解决方案


从源头根据这个函数

 public onMouseDown(event: MouseEvent): void {
    if (!this.isIE10 && this.cpDialogDisplay === 'popup' &&
        event.target !== this.directiveElementRef.nativeElement &&
        !this.isDescendant(this.elRef.nativeElement, event.target) &&
        !this.isDescendant(this.directiveElementRef.nativeElement, event.target) &&
        this.cpIgnoredElements.filter((item: any) => item === event.target).length === 0)
    {
      if (!this.cpSaveClickOutside) {
        this.setColorFromString(this.initialColor, false);

        this.directiveInstance.colorChanged(this.initialColor);
      }

      this.closeColorPicker();
    }
  }

您将不得不使用:

cpDialogDisplay = 'inline'

代替

cpDialogDisplay = 'popup'

然而,为了防止这种行为,这将禁用对话框

所以,你的问题的答案:

如果在对话框之外单击它,我不想关闭对话框。ngx-color-picker 中是否有任何内置事件可以解决这种情况?

是否。_

在我看来,与任何开源项目一样,您有几个选择:

1) 更改组件的源代码,将您的更改提交到 github 中的项目,如果维护人员同意您的实现,您的新功能将成为该组件未来版本的一部分;

2)您从头开始构建自己的组件,可能主要基于当前的ngx-color-picker,具有您想要的功能,也许还有其他功能。

3) 寻找可能具有您正在寻找的功能/行为的其他类似项目/组件。


推荐阅读