Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/fix-floating-toolbar-mobile-placement-overlap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"www": patch
---

Fix `FloatingToolbar` overlapping with native mobile text selection context menus on mobile devices. Uses `useIsMobile` to set `placement: 'bottom'` on mobile viewports so custom floating toolbars render below selection instead of colliding with native mobile context menus.
23 changes: 16 additions & 7 deletions apps/www/src/registry/ui/floating-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
usePluginOption,
} from 'platejs/react';

import { useIsMobile } from '@/hooks/use-mobile';
import { cn } from '@/lib/utils';

import { Toolbar } from './toolbar';
Expand All @@ -29,6 +30,7 @@ export function FloatingToolbar({
}: React.ComponentProps<typeof Toolbar> & {
state?: FloatingToolbarState;
}) {
const isMobile = useIsMobile();
const editorId = useEditorId();
const focusedEditorId = useEventEditorValue('focus');
const isFloatingLinkOpen = !!usePluginOption({ key: KEYS.link }, 'mode');
Expand All @@ -43,16 +45,23 @@ export function FloatingToolbar({
middleware: [
offset(12),
flip({
fallbackPlacements: [
'top-start',
'top-end',
'bottom-start',
'bottom-end',
],
fallbackPlacements: isMobile
? [
'bottom-start',
'bottom-end',
'top-start',
'top-end',
]
: [
'top-start',
'top-end',
'bottom-start',
'bottom-end',
],
padding: 12,
}),
],
placement: 'top',
placement: isMobile ? 'bottom' : 'top',
...state?.floatingOptions,
},
});
Expand Down
Loading