如何在Angular 8中删除primeng p-editor工具栏中的tab?

问题描述 投票:0回答:1

这是我的代码,tabIndex ="-1 "对大多数标签都有效,但对select标签和 "ql-image "无效。我想删除所有标签,并希望焦点直接在编辑器框中,而不是在工具中。

 <p-editor #editor required [(ngModel)]="comment.comment" name="comment"  class="pEditor"
        [style]="{ height: '180px', 'font-size': '1.2em' }">

        <p-header>

          <span class="ql-formats">
            <select class="ql-header" tabindex="-1">
              <option value="1" tabindex="-1">Heading</option>
              <option value="2" tabindex="-1">Subheading</option>
              <option selected tabindex="-1">Normal</option>
            </select>
            <select class="ql-font" tabindex="-1">
              <option selected tabindex="-1">Sans Serif</option>
              <option value="serif" tabindex="-1">Serif</option>
              <option value="monospace" tabindex="-1">Monospace</option>
            </select>
          </span>
          <span class="ql-formats">
            <button class="ql-bold" aria-label="Bold" tabindex="-1"></button>
            <button class="ql-italic" aria-label="Italic" tabindex="-1"></button>
            <button class="ql-underline" aria-label="Underline" tabindex="-1"></button>
          </span>
          <span class="ql-formats">
            <select class="ql-color" tabindex="2"></select>
            <select class="ql-background" tabindex="2"></select>
          </span>
          <span class="ql-formats">
            <button class="ql-list" value="ordered" aria-label="Ordered List" tabindex="-1"></button>
            <button class="ql-list" value="bullet" aria-label="Unordered List" tabindex="-1"></button>
            <select class="ql-align">
              <option selected tabindex="-1"></option>
              <option value="center" tabindex="-1"></option>
              <option value="right" tabindex="-1"></option>
              <option value="justify" tabindex="-1"></option>
            </select>
          </span>
          <span class="ql-formats">
            <button class="ql-link" aria-label="Insert Link" tabindex="-1"></button>
            <button class="ql-image" aria-label="Insert Image" tabindex="-1"></button>
            <button class="ql-code-block" aria-label="Insert Code Block" tabindex="-1"></button>
          </span>
          <span class="ql-formats">
            <button class="ql-clean" aria-label="Remove Styles" tabindex="-1"></button>
          </span>
        </p-header> 
      </p-editor>
angular editor primeng quill
1个回答
3
投票

你几乎做到了,但是在选择框的错误位置添加了tabindex="-1"。

 <select class="ql-header" tabindex="-1">

<p-editor #editor required name="comment" class="pEditor" [style]="{ height: '180px', 'font-size': '1.2em' }">

  <p-header>

    <span class="ql-formats">
            <select class="ql-header" tabindex="-1">
              <option value="1" tabindex="-1">Heading</option>
              <option value="2" tabindex="-1">Subheading</option>
              <option selected tabindex="-1">Normal</option>
            </select>
            <select class="ql-font" tabindex="-1">
              <option selected tabindex="-1">Sans Serif</option>
              <option value="serif" tabindex="-1">Serif</option>
              <option value="monospace" tabindex="-1">Monospace</option>
            </select>
          </span>
    <span class="ql-formats">
            <button class="ql-bold" aria-label="Bold" tabindex="-1"></button>
            <button class="ql-italic" aria-label="Italic" tabindex="-1"></button>
            <button class="ql-underline" aria-label="Underline" tabindex="-1"></button>
          </span>
    <span class="ql-formats">
            <select class="ql-color" tabindex="-1"></select>
            <select class="ql-background" tabindex="-1"></select>
          </span>
    <span class="ql-formats">
            <button class="ql-list" value="ordered" aria-label="Ordered List" tabindex="-1"></button>
            <button class="ql-list" value="bullet" aria-label="Unordered List" tabindex="-1"></button>
            <select class="ql-align" tabindex="-1">
              <option selected tabindex="-1"></option>
              <option value="center" tabindex="-1"></option>
              <option value="right" tabindex="-1"></option>
              <option value="justify" tabindex="-1"></option>
            </select>
          </span>
    <span class="ql-formats">
            <button class="ql-link" aria-label="Insert Link" tabindex="-1"></button>
            <button class="ql-image" aria-label="Insert Image" tabindex="-1"></button>
            <button class="ql-code-block" aria-label="Insert Code Block" tabindex="-1"></button>
          </span>
    <span class="ql-formats">
            <button class="ql-clean" aria-label="Remove Styles" tabindex="-1"></button>
          </span>
  </p-header>
</p-editor>

更新1

primeng不会从选定的跨度中删除tabindex。

你必须在你的ngAfterViewInit方法中删除这个功能。

ngAfterViewInit() {
  const spans = document.getElementsByClassName('ql-picker-label');
  for (let i = 0; i < spans.length; i++) {
    spans[i].removeAttribute('tabindex');
  }
}

这里是stackblitz 联系.


0
投票

这对我来说,在Angular 9的工作。

  ngAfterViewInit() {
     const test = this.pEditor.el.nativeElement;
     const elements = test.querySelectorAll('.ql-picker-label');
     for (let i = 0; i < elements.length; i++) {
     elements[i].removeAttribute('tabindex');
    }
  }
© www.soinside.com 2019 - 2024. All rights reserved.