简体   繁体   中英

PrimeNG Quill editor custom toolbar

I want to make a custom toolbar of quill editor with PrimeNG. I am using Angular 2.

    <p-editor [(ngModel)]="message" [style]="{'height':'320px'}">
        <p-header>
          <span class="ql-formats">
            <select class="ql-size">
              <option value="small">Petit</option>
              <option selected></option>
              <option value="large">Sous-titre</option>
              <option value="huge">Titre</option>
            </select>
          </span>
          <span class="ql-formats">
            <button class="ql-bold" aria-label="Bold"></button>
            <button class="ql-italic" aria-label="Italic"></button>
            <button class="ql-underline" aria-label="Underline"></button>
            <button class="ql-strike" aria-label="Strike"></button>
          </span>
          <span class="ql-formats">
            <select title="Text Color" class="ql-color" defaultValue="rgb(0, 0, 0)">
              <option value="rgb(0, 0, 0)" label="rgb(0, 0, 0)"></option>
              ...
              <option value="rgb(61, 20, 102)" label="rgb(61, 20, 102)"></option>
            </select>
            <span class="ql-format-separator"></span>
            <select title="Background Color" class="ql-background" defaultValue="rgb(255, 255, 255)">
              <option value="rgb(0, 0, 0)" label="rgb(0, 0, 0)"></option>
              ...
              <option value="rgb(61, 20, 102)" label="rgb(61, 20, 102)"></option>
            </select>
        </span>
          <span class="ql-formats">
            <button class="ql-list" title="List"></button>
            <button class="ql-bullet" title="Bullet"></button>
            <select title="Text Alignment" class="ql-align" >
              <option selected>Gauche</option>
              <option value="center" label="Center"></option>
              <option value="right" label="Right"></option>
              <option value="justify" label="Justify"></option>
            </select>            
          </span> 
          <span class="ql-formats">
            <button aria-label="Link" class="ql-link"></button>
            <button aria-label="Image" class="ql-image"></button>
          </span>
        </p-header>
      </p-editor>

Notice the difference between your code for those two buttons:

 <button class="ql-list" title="List"></button>
 <button class="ql-bullet" title="Bullet"></button>

and the actual code when the editor renders. All you have to do is to replace the title attribute for the value attribute that would do the trick:

<button class="ql-list" value="ordered"></button>
<button class="ql-list" value="bullet"></button>

All I did was to go back on the full feature toolbar that primeng has and did right click > inspect on the html tags of the buttons that weren't displaying correctly and I got the right code to display it.

You should also add value to buttons;

<span class="ql-formats">
<button type="button" class="ql-list" aria-label="List" value='ordered'></button>
<button type="button" class="ql-list" aria-label="Bullet" value='bullet'></button>
</span>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM