Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent the addition of a quote breaking the widget css in playground #248

Merged
merged 2 commits into from
May 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { ExpandableCard } from '../../../Card';
import { Alert, Autocomplete, StyledPopper } from '../DesignControls.style';
import { allFonts, defaultFont } from './fontDefinitions';

const santiseInputString = (value: string) => value.replace(/['"`]/g, '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is a typo 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fixed :-)


const getCompleteFontFamily = (font: Font) =>
font.fallbackFonts
? [font.family, font.fallbackFonts].join(', ')
Expand All @@ -37,8 +39,9 @@ export const FontsControl = () => {
value: Font | string | null,
) => {
if (typeof value === 'string') {
setSelectedFont({ family: value, source: 'Custom fonts' });
setFontFamily(value);
const cleanValue = santiseInputString(value);
setSelectedFont({ family: cleanValue, source: 'Custom fonts' });
setFontFamily(cleanValue);
} else {
const font = value ? value : defaultFont;
setAndLoadFont(font);
Expand All @@ -48,7 +51,7 @@ export const FontsControl = () => {
const handleAutocompleteBlur: FocusEventHandler<HTMLInputElement> = (
event,
) => {
const inputValue = event.target.value.trim();
const inputValue = santiseInputString(event.target.value.trim());

if (!selectedFont || inputValue !== getCompleteFontFamily(selectedFont)) {
if (inputValue) {
Expand Down