From 9a0eff131641ad00501f139f6589cda2d06d7120 Mon Sep 17 00:00:00 2001 From: Omar Faruk Date: Tue, 12 Mar 2024 06:26:05 +0000 Subject: [PATCH] Fixed font change --- demo/index.html | 1 + demo/src/index.js | 2 +- src/plugins/fontDropdown.js | 16 +++++++++++++--- src/plugins/toolbar.js | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/demo/index.html b/demo/index.html index 35df712..b432af7 100644 --- a/demo/index.html +++ b/demo/index.html @@ -1,6 +1,7 @@ + Urdu Web Editor diff --git a/demo/src/index.js b/demo/src/index.js index 34c49f9..429fb01 100644 --- a/demo/src/index.js +++ b/demo/src/index.js @@ -29,7 +29,7 @@ const urduFonts = [ ]; const Demo = () => { const [open, setOpen] = useState(false); - const [value, setValue] = useState(undefined); + const [value, setValue] = useState(null); const [configuration, setConfiguration] = useState({ richText: true, language: "ur", diff --git a/src/plugins/fontDropdown.js b/src/plugins/fontDropdown.js index 5125fda..c3d6412 100644 --- a/src/plugins/fontDropdown.js +++ b/src/plugins/fontDropdown.js @@ -24,16 +24,26 @@ export const defaultFont = ({ configuration }) => { // -------------------------------------------------- const FontDropDown = ({ fonts, value, onChange = () => {} }) => { const configuredFonts = (fonts && fonts.length > 0 ? fonts : FONT_FAMILY_OPTIONS); + const selected = () => value && configuredFonts.find(x => x.value === value) || configuredFonts[0]; + onFontSelect = (item) => { + onChange(item.key); + } const items = configuredFonts .map(i => ({ - onClick: () => onChange(i.value), + key: i.value, label: i.label, })); + return ( - + diff --git a/src/plugins/toolbar.js b/src/plugins/toolbar.js index 01b34d3..b9abddc 100644 --- a/src/plugins/toolbar.js +++ b/src/plugins/toolbar.js @@ -251,9 +251,9 @@ const ToolbarPlugin = ({ configuration, setIsLinkEditMode, locale }) => { const selection = $getSelection(); if ($isRangeSelection(selection)) { $patchStyleText(selection, { - "font-family": font.value, + "font-family": font, }); - } + } }); };