Error when selecting custom font size tools

1 Answer 90 Views
Editor
Hoang
Top achievements
Rank 1
Hoang asked on 04 Jan 2023, 02:24 PM | edited on 05 Jan 2023, 02:24 AM

Hi,

I am trying to implement the custom tools for color and font size using dropdown list in the editor.

I have an issue when I select some text in the editor, and choose a color or a font size in the custom dropdown, the selected text becomes unselected, so I have to select them again if I want to change the option.

I don't see this issue when I use the default built-in tool like FontSize.

Here is my code:

import { Editor, EditorChangeEvent, EditorMountEvent, EditorPasteEvent, EditorTools, EditorToolsSettings, ProseMirror, } from'@progress/kendo-react-editor'; import { useEffect, useRef, useState } from'react'; import { Button } from'@progress/kendo-react-buttons'; const { EditorState, EditorView, Plugin, PluginKey, TextSelection } = ProseMirror; const { Bold, Italic, Underline, Strikethrough, Indent, Outdent, OrderedList, UnorderedList, FormatBlock } = EditorTools; const fontSizeToolSettings: EditorToolsSettings.StyleDropDownListSettings = { ...EditorToolsSettings.fontSize, items: [ { text: '10', value: '10pt' }, { text: '12', value: '12pt' }, { text: '14', value: '14pt' }, { text: '18', value: '18pt' }, { text: '22', value: '22pt' }, { text: '36', value: '36pt' }, ], }; const colorToolSettings = { style: 'color', defaultItem: { text: 'No Color', value: '' }, items: [ { text: 'White', value: '#fff' }, { text: 'Midnight', value: '#232437' }, { text: 'Sand', value: '#e6e4dc' }, { text: 'Slate', value: '#6a7885' }, { text: 'Mint', value: '#6ce3c8' }, { text: 'Green', value: '#20a786' }, { text: 'Yellow', value: '#f1c22e' }, { text: 'Orange', value: '#e79946' }, { text: 'Red', value: '#c64f27' }, ], }; const CustomColor = EditorTools.createStyleDropDownList(colorToolSettings); const MyColorTool = (props: any) => ( <CustomColor {...props} style={{ width: '100px', ...props.style, }} /> ); // Creates custom FontSize tool.const CustomFontSize = EditorTools.createStyleDropDownList(fontSizeToolSettings); // Styles the FontSize tool (DropDownList).const MyFontSizeTool = (props: any) => ( <CustomFontSize {...props} style={{ width: '110px', ...props.style, }} /> ); const CommonEditor = () => { return ( <Editor tools={[ MyColorTool, [Bold, Italic, Underline, Strikethrough], [Indent, Outdent], [OrderedList, UnorderedList], MyFontSizeTool, ]}

defaultEditMode="div" /> ); }; exportdefault CommonEditor;

Could you provide me the solution to keep the selected text like the default tool?

Thanks a lot!

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 06 Jan 2023, 04:23 PM

Hi, Hoang, 

I tested the provided setup, but the custom tool actions are applied multiple times successfully at my end once a string from the content is selected: 

Below is the sample page I used to record the video above:

Regards,
Vessy
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Editor
Asked by
Hoang
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Share this question
or