You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to programmatically set the default font size for different Quill rte's on a page in my application, but each approach seems more and more of a hacky workaround than something that would seem pretty straightforward.
I'm using Quill (ngx-quill ^25.3.2/quill ^2.0.0) in my Angular v17 application and I've tried using Angular's various if statement syntax for the selected attribute on the <option> tag that I need to set as the default font size, but I've run into many dead ends with that approach.
The one thing I've gotten to work, though seemingly through hoops and ladders, is getting the correct font size to be selected in the dropdown. Here's the approach I've gotten to work:
exportclassQuillEditorimplementsOnInit{
@ViewChild("contextModel",{static: true})contextModel: ElementRef;
@ViewChild("toolbar",{static: true})toolbarElement: ElementRef;
@Input()isHeaderOrFooter=false;publicngOnInit(): void{this.initializeQuill()}privateinitializeQuill(): void{consteditorElement=this.contextModel.nativeElement;consttoolbarElement=this.toolbarElement.nativeElement;letfontSizeStyle=Quill.import("attributors/style/size");fontSizeStyle.whitelist=// array of px font sizes;Quill.register(fontSizeStyle,true);this.Quill=newQuill(editorElement,{theme: "snow",modules: {table: true,toolbar: toolbarElement,},placeholder: "Enter Text",});// other quill setupconstdefaultFontSize=this.isHeaderOrFooter ? "10px" : "14px";// this seems pretty hacky, but it worksconstquillLength=this.Quill.getLength();this.Quill.formatText(0,quillLength,'size',defaultFontSize);constsizeDropdown=toolbarElement.querySelector("select.ql-size");if(sizeDropdown){sizeDropdown.value=defaultFontSize;// Set default font size in dropdownsizeDropdown.dispatchEvent(newEvent("change"));}}}
The only thing I can't seem to get working is having the editor font size reflect the default selected font size. Any guidance would be much appreciated
The text was updated successfully, but these errors were encountered:
kgrove-ch
changed the title
Programmatically setting a default font size
Setting a default font size
Nov 13, 2024
I'm trying to programmatically set the default font size for different Quill rte's on a page in my application, but each approach seems more and more of a hacky workaround than something that would seem pretty straightforward.
I'm using Quill (ngx-quill ^25.3.2/quill ^2.0.0) in my Angular v17 application and I've tried using Angular's various if statement syntax for the
selected
attribute on the<option>
tag that I need to set as the default font size, but I've run into many dead ends with that approach.The one thing I've gotten to work, though seemingly through hoops and ladders, is getting the correct font size to be selected in the dropdown. Here's the approach I've gotten to work:
The only thing I can't seem to get working is having the editor font size reflect the default selected font size. Any guidance would be much appreciated
The text was updated successfully, but these errors were encountered: