Skip to content

Commit

Permalink
Merge pull request #563 from prezly/fix/dev-13267-dont-use-null-as-a-…
Browse files Browse the repository at this point in the history
…possible-value-for-fallback

Remove fallback when changing the type instead of using an effect
  • Loading branch information
kudlajz authored Aug 8, 2024
2 parents acdf6b3 + ef83231 commit 8a453e4
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/slate-editor/src/extensions/variables/VariableMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { VariableNode } from '@prezly/slate-types';
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import { useSlateStatic } from 'slate-react';

import { Button, Input, Menu as BaseMenu, Toolbox, VStack, TooltipV2 } from '#components';
Expand Down Expand Up @@ -35,7 +35,12 @@ export function VariableMenu({ container, element, onClose, variables }: Props)
const option = options.find(({ value }) => value === element.key);

function handleChangeType(newType: string) {
updateVariable(editor, { key: newType });
const newOption = options.find(({ value }) => value === newType);
if (newOption && !newOption.withFallback) {
updateVariable(editor, { fallback: '' });
} else {
updateVariable(editor, { key: newType });
}
}

function handleSave() {
Expand All @@ -46,12 +51,6 @@ export function VariableMenu({ container, element, onClose, variables }: Props)
removeVariable(editor);
}

useEffect(() => {
if (!option?.withFallback) {
updateVariable(editor, { fallback: '' });
}
}, [option?.withFallback]);

return (
<Menu
popperOptions={{ ...popperOptions, modifiers: { arrow: { padding: 0 } } }}
Expand Down

0 comments on commit 8a453e4

Please sign in to comment.