Skip to content

Commit

Permalink
Fix: Bug - 6000: Changing the font size when inputting does not take … (
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelbyaj authored May 16, 2024
1 parent 5b0bb73 commit ca0a823
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
35 changes: 25 additions & 10 deletions packages/lexical-playground/src/plugins/ToolbarPlugin/fontSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function FontSize({
editor: LexicalEditor;
}) {
const [inputValue, setInputValue] = React.useState<string>(selectionFontSize);
const [inputChangeFlag, setInputChangeFlag] = React.useState<boolean>(false);

/**
* Calculates the new font size based on the update type.
Expand Down Expand Up @@ -140,18 +141,18 @@ export default function FontSize({
setInputValue('');
return;
}

if (e.key === 'Enter') {
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);
}
};

Expand All @@ -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]);
Expand Down Expand Up @@ -194,6 +208,7 @@ export default function FontSize({
max={MAX_ALLOWED_FONT_SIZE}
onChange={(e) => setInputValue(e.target.value)}
onKeyDown={handleKeyPress}
onBlur={handleInputBlur}
/>

<button
Expand Down
2 changes: 1 addition & 1 deletion scripts/__tests__/integration/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = async function (globalConfig, projectConfig) {
const cwd = process.cwd();
try {
process.chdir(pkg.resolve('npm'));
await exec(`npm pack --pack-destination '${packDest}'`);
await exec(`npm pack --pack-destination ${packDest}`);
} finally {
process.chdir(cwd);
}
Expand Down

0 comments on commit ca0a823

Please sign in to comment.