diff --git a/packages/core/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts b/packages/core/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts index 5a04c3a39d..a60f1cb398 100644 --- a/packages/core/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +++ b/packages/core/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts @@ -3,8 +3,8 @@ import { EditorState, Plugin, PluginKey } from "prosemirror-state"; import { EditorView } from "prosemirror-view"; import type { BlockNoteEditor } from "../../editor/BlockNoteEditor"; -import { BlockSchema, InlineContentSchema, StyleSchema } from "../../schema"; import { UiElementPosition } from "../../extensions-shared/UiElementPosition"; +import { BlockSchema, InlineContentSchema, StyleSchema } from "../../schema"; import { EventEmitter } from "../../util/EventEmitter"; export type FormattingToolbarState = UiElementPosition; diff --git a/packages/core/src/util/browser.ts b/packages/core/src/util/browser.ts index d32090c334..e5fcf8ac71 100644 --- a/packages/core/src/util/browser.ts +++ b/packages/core/src/util/browser.ts @@ -1,8 +1,8 @@ export const isAppleOS = () => - typeof navigator !== "undefined" && - (/Mac/.test(navigator.platform) || - (/AppleWebKit/.test(navigator.userAgent) && - /Mobile\/\w+/.test(navigator.userAgent))); + typeof navigator !== "undefined" && + (/Mac/.test(navigator.platform) || + (/AppleWebKit/.test(navigator.userAgent) && + /Mobile\/\w+/.test(navigator.userAgent))); export function formatKeyboardShortcut(shortcut: string) { if (isAppleOS()) { @@ -16,3 +16,5 @@ export function mergeCSSClasses(...classes: string[]) { return classes.filter((c) => c).join(" "); } +export const isSafari = () => + /^((?!chrome|android).)*safari/i.test(navigator.userAgent); diff --git a/packages/react/src/components/mantine-shared/Toolbar/ToolbarButton.tsx b/packages/react/src/components/mantine-shared/Toolbar/ToolbarButton.tsx index eb427dd0ff..81feed73fa 100644 --- a/packages/react/src/components/mantine-shared/Toolbar/ToolbarButton.tsx +++ b/packages/react/src/components/mantine-shared/Toolbar/ToolbarButton.tsx @@ -1,7 +1,8 @@ import { ActionIcon, Button, Tooltip } from "@mantine/core"; -import { ForwardedRef, MouseEvent, forwardRef } from "react"; +import { MouseEvent, forwardRef } from "react"; import type { IconType } from "react-icons"; +import { isSafari } from "@blocknote/core"; import { TooltipContent } from "../Tooltip/TooltipContent"; export type ToolbarButtonProps = { @@ -17,8 +18,8 @@ export type ToolbarButtonProps = { /** * Helper for basic buttons that show in the formatting toolbar. */ -export const ToolbarButton = forwardRef( - (props: ToolbarButtonProps, ref: ForwardedRef) => { +export const ToolbarButton = forwardRef( + (props, ref) => { const ButtonIcon = props.icon; return ( @@ -33,6 +34,13 @@ export const ToolbarButton = forwardRef( {/*Creates an ActionIcon instead of a Button if only an icon is provided as content.*/} {props.children ? ( ) : ( { + if (isSafari()) { + (e.currentTarget as HTMLButtonElement).focus(); + } + }} onClick={props.onClick} data-selected={props.isSelected ? "true" : undefined} data-test={ diff --git a/packages/react/src/components/mantine-shared/Toolbar/ToolbarDropdownTarget.tsx b/packages/react/src/components/mantine-shared/Toolbar/ToolbarDropdownTarget.tsx index 39cf54a779..cd8a25b9b8 100644 --- a/packages/react/src/components/mantine-shared/Toolbar/ToolbarDropdownTarget.tsx +++ b/packages/react/src/components/mantine-shared/Toolbar/ToolbarDropdownTarget.tsx @@ -1,3 +1,4 @@ +import { isSafari } from "@blocknote/core"; import { Button } from "@mantine/core"; import { MouseEventHandler, forwardRef } from "react"; import type { IconType } from "react-icons"; @@ -15,8 +16,16 @@ export const ToolbarDropdownTarget = forwardRef< ToolbarDropdownTargetProps >((props: ToolbarDropdownTargetProps, ref) => { const TargetIcon = props.icon; + return (