Skip to content

Commit

Permalink
Merge pull request #3251 from udecode/fix/floatingt
Browse files Browse the repository at this point in the history
fix: turn-into-dropdown-menu losing focus
  • Loading branch information
zbeyens authored Jun 7, 2024
2 parents 9a5405e + 77e568b commit b195c05
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-onions-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-floating": patch
---

fix: can't open dropdown menu
5 changes: 5 additions & 0 deletions .changeset/fluffy-rabbits-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-mention": patch
---

fix: import types form `@udecode/common` instead of `@udecode/common/server`
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ export function PlaygroundTurnIntoDropdownMenu(props: DropdownMenuProps) {
items.find((item) => item.value === value) ?? defaultItem;
const { icon: SelectedItemIcon, label: selectedItemLabel } = selectedItem;

const onCloseAutoFocus = React.useCallback((e: Event) => {
focusEditor(editor);

return e.preventDefault();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<DropdownMenu modal={false} {...openState} {...props}>
<DropdownMenuTrigger asChild>
Expand All @@ -146,7 +153,11 @@ export function PlaygroundTurnIntoDropdownMenu(props: DropdownMenuProps) {
</ToolbarButton>
</DropdownMenuTrigger>

<DropdownMenuContent align="start" className="min-w-0">
<DropdownMenuContent
align="start"
className="min-w-0"
onCloseAutoFocus={onCloseAutoFocus}
>
<DropdownMenuLabel>Turn into</DropdownMenuLabel>

<DropdownMenuRadioGroup
Expand Down
7 changes: 1 addition & 6 deletions packages/floating/src/hooks/useFloatingToolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,7 @@ export const useFloatingToolbar = ({
}, [selectionText, selectionExpanded, setMouseupped]);

React.useEffect(() => {
if (
!selectionExpanded ||
!selectionText ||
// (!(editorId === focusedEditorId || ignoreReadOnly) && hideToolbar)
!(editorId === focusedEditorId)
) {
if (!selectionExpanded || !selectionText) {
setOpen(false);
setMouseupped(false);
} else if (
Expand Down
2 changes: 1 addition & 1 deletion packages/mention/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TriggerComboboxPlugin } from '@udecode/plate-combobox';
import type { TElement, TNodeProps } from '@udecode/plate-common/server';
import type { TElement, TNodeProps } from '@udecode/plate-common';

export interface TMentionItemBase {
text: string;
Expand Down

0 comments on commit b195c05

Please sign in to comment.