From 1931dc7a29259d47dd12ed427f79b30260b9dbd4 Mon Sep 17 00:00:00 2001 From: pixelbyaj Date: Tue, 14 May 2024 17:52:36 +0200 Subject: [PATCH 1/3] Fix: Bug - 6000: Changing the font size when inputting does not take effect --- .../lexical-playground/src/plugins/ToolbarPlugin/fontSize.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lexical-playground/src/plugins/ToolbarPlugin/fontSize.tsx b/packages/lexical-playground/src/plugins/ToolbarPlugin/fontSize.tsx index 60e86401509..09c9a67843e 100644 --- a/packages/lexical-playground/src/plugins/ToolbarPlugin/fontSize.tsx +++ b/packages/lexical-playground/src/plugins/ToolbarPlugin/fontSize.tsx @@ -141,7 +141,7 @@ export default function FontSize({ return; } - if (e.key === 'Enter') { + if (e.key === 'Enter' || e.key === 'Tab' || e.key === 'Escape') { e.preventDefault(); let updatedFontSize = inputValueNumber; From 57a5d251ab5e56e9e16bf86f474f3b99b7ed5f0a Mon Sep 17 00:00:00 2001 From: pixelbyaj Date: Tue, 14 May 2024 19:40:24 +0200 Subject: [PATCH 2/3] Bug: Changing the font size when inputting does not take effect #6000. This will also handle the blur event --- .../src/plugins/ToolbarPlugin/fontSize.tsx | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/lexical-playground/src/plugins/ToolbarPlugin/fontSize.tsx b/packages/lexical-playground/src/plugins/ToolbarPlugin/fontSize.tsx index 09c9a67843e..877826d920d 100644 --- a/packages/lexical-playground/src/plugins/ToolbarPlugin/fontSize.tsx +++ b/packages/lexical-playground/src/plugins/ToolbarPlugin/fontSize.tsx @@ -32,6 +32,7 @@ export default function FontSize({ editor: LexicalEditor; }) { const [inputValue, setInputValue] = React.useState(selectionFontSize); + const [inputChangeFlag, setInputChangeFlag] = React.useState(false); /** * Calculates the new font size based on the update type. @@ -140,18 +141,18 @@ export default function FontSize({ setInputValue(''); return; } - + setInputChangeFlag(true); if (e.key === 'Enter' || e.key === 'Tab' || e.key === 'Escape') { e.preventDefault(); - let updatedFontSize = inputValueNumber; - if (inputValueNumber > MAX_ALLOWED_FONT_SIZE) { - updatedFontSize = MAX_ALLOWED_FONT_SIZE; - } else if (inputValueNumber < MIN_ALLOWED_FONT_SIZE) { - updatedFontSize = MIN_ALLOWED_FONT_SIZE; - } - setInputValue(String(updatedFontSize)); - updateFontSizeInSelection(String(updatedFontSize) + 'px', null); + updateFontSizeByInputValue(inputValueNumber); + } + }; + + const handleInputBlur = () => { + if (inputValue !== '' && inputChangeFlag) { + const inputValueNumber = Number(inputValue); + updateFontSizeByInputValue(inputValueNumber); } }; @@ -167,6 +168,19 @@ export default function FontSize({ } }; + const updateFontSizeByInputValue = (inputValueNumber: number) => { + let updatedFontSize = inputValueNumber; + if (inputValueNumber > MAX_ALLOWED_FONT_SIZE) { + updatedFontSize = MAX_ALLOWED_FONT_SIZE; + } else if (inputValueNumber < MIN_ALLOWED_FONT_SIZE) { + updatedFontSize = MIN_ALLOWED_FONT_SIZE; + } + + setInputValue(String(updatedFontSize)); + updateFontSizeInSelection(String(updatedFontSize) + 'px', null); + setInputChangeFlag(false); + }; + React.useEffect(() => { setInputValue(selectionFontSize); }, [selectionFontSize]); @@ -194,6 +208,7 @@ export default function FontSize({ max={MAX_ALLOWED_FONT_SIZE} onChange={(e) => setInputValue(e.target.value)} onKeyDown={handleKeyPress} + onBlur={handleInputBlur} />