Skip to content

Commit d65c65b

Browse files
fix(registry): set floating toolbar placement to bottom on mobile to prevent overlap (#4619)
On mobile screens (iOS Safari / Android Chrome), native selection context menus pop up above text selection. FloatingToolbar defaulting to placement: 'top' caused direct overlap. Fix: - Use useIsMobile hook in FloatingToolbar (floating-toolbar.tsx) to set placement: 'bottom' on mobile viewports. - Update fallbackPlacements to prioritize bottom placements on mobile. - Add patch changeset for www registry UI. Closes #4619
1 parent 3add964 commit d65c65b

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"www": patch
3+
---
4+
5+
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.

apps/www/src/registry/ui/floating-toolbar.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
usePluginOption,
1818
} from 'platejs/react';
1919

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

2223
import { Toolbar } from './toolbar';
@@ -29,6 +30,7 @@ export function FloatingToolbar({
2930
}: React.ComponentProps<typeof Toolbar> & {
3031
state?: FloatingToolbarState;
3132
}) {
33+
const isMobile = useIsMobile();
3234
const editorId = useEditorId();
3335
const focusedEditorId = useEventEditorValue('focus');
3436
const isFloatingLinkOpen = !!usePluginOption({ key: KEYS.link }, 'mode');
@@ -43,16 +45,23 @@ export function FloatingToolbar({
4345
middleware: [
4446
offset(12),
4547
flip({
46-
fallbackPlacements: [
47-
'top-start',
48-
'top-end',
49-
'bottom-start',
50-
'bottom-end',
51-
],
48+
fallbackPlacements: isMobile
49+
? [
50+
'bottom-start',
51+
'bottom-end',
52+
'top-start',
53+
'top-end',
54+
]
55+
: [
56+
'top-start',
57+
'top-end',
58+
'bottom-start',
59+
'bottom-end',
60+
],
5261
padding: 12,
5362
}),
5463
],
55-
placement: 'top',
64+
placement: isMobile ? 'bottom' : 'top',
5665
...state?.floatingOptions,
5766
},
5867
});

0 commit comments

Comments
 (0)