Skip to content
Draft
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
4 changes: 4 additions & 0 deletions examples/01-basic/04-default-blocks/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import { useCreateBlockNote } from "@blocknote/react";
import { Button, Popover, Text, TextInput } from "@mantine/core";
import { useRef } from "react";

export default function App() {
// Creates a new editor instance.
Expand Down Expand Up @@ -148,6 +150,8 @@ export default function App() {
],
});

const inputRef = useRef<HTMLInputElement | null>(null);

// Renders the editor instance using a React component.
return <BlockNoteView editor={editor} />;
}
2 changes: 2 additions & 0 deletions packages/ariakit/src/input/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const TextInput = forwardRef<
disabled,
onKeyDown,
onChange,
onClickCapture,
onSubmit,
autoComplete,
"aria-activedescendant": ariaActivedescendant,
Expand Down Expand Up @@ -51,6 +52,7 @@ export const TextInput = forwardRef<
disabled={disabled}
onKeyDown={onKeyDown}
onChange={onChange}
onClickCapture={onClickCapture}
onSubmit={onSubmit}
autoComplete={autoComplete}
aria-activedescendant={ariaActivedescendant}
Expand Down
2 changes: 2 additions & 0 deletions packages/mantine/src/form/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const TextInput = forwardRef<
disabled,
onKeyDown,
onChange,
onClickCapture,
onSubmit,
autoComplete,
"aria-activedescendant": ariaActivedescendant,
Expand Down Expand Up @@ -48,6 +49,7 @@ export const TextInput = forwardRef<
disabled={disabled}
onKeyDown={onKeyDown}
onChange={onChange}
onClickCapture={onClickCapture}
onSubmit={onSubmit}
autoComplete={autoComplete}
aria-activedescendant={ariaActivedescendant}
Expand Down
20 changes: 19 additions & 1 deletion packages/react/src/components/LinkToolbar/EditLinkMenuItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {
import {
ChangeEvent,
KeyboardEvent,
MouseEvent,
useCallback,
useEffect,
useState,
} from "react";
import { RiLink, RiText } from "react-icons/ri";
import { useComponentsContext } from "../../editor/ComponentsContext.js";
import { useBlockNoteEditor } from "../../hooks/useBlockNoteEditor.js";
import { useExtension } from "../../hooks/useExtension.js";
import { useDictionary } from "../../i18n/dictionary.js";
import { LinkToolbarProps } from "./LinkToolbarProps.js";
Expand All @@ -36,6 +38,7 @@ export const EditLinkMenuItems = (
) => {
const Components = useComponentsContext()!;
const dict = useDictionary();
const editor = useBlockNoteEditor();

// eslint-disable-next-line @typescript-eslint/unbound-method -- editLink is a plain object method, not a class method
const { editLink } = useExtension(LinkToolbarExtension);
Expand Down Expand Up @@ -80,18 +83,32 @@ export const EditLinkMenuItems = (
props.setToolbarPositionFrozen?.(false);
}, [editLink, currentUrl, currentText, props]);

// Scrolling the input into view works around an Android Chrome issue where
// the input is otherwise left hidden behind the on-screen keyboard. We then
// restore the scroll position to the editor selection.
const handleClickCapture = useCallback(
(event: MouseEvent<HTMLInputElement>) => {
event.currentTarget.scrollIntoView();
setTimeout(() => {
editor.transact((tr) => tr.scrollIntoView());
}, 1000);
},
[editor],
);

return (
<Components.Generic.Form.Root>
{/* // TODO: add labels? */}
<Components.Generic.Form.TextInput
className={"bn-text-input"}
name="url"
icon={<RiLink />}
autoFocus={true}
autoFocus={false}
placeholder={dict.link_toolbar.form.url_placeholder}
value={currentUrl}
onKeyDown={handleEnter}
onChange={handleUrlChange}
onClickCapture={handleClickCapture}
onSubmit={handleSubmit}
/>
{showTextField !== false && (
Expand All @@ -103,6 +120,7 @@ export const EditLinkMenuItems = (
value={currentText}
onKeyDown={handleEnter}
onChange={handleTextChange}
onClickCapture={handleClickCapture}
onSubmit={handleSubmit}
/>
)}
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/editor/ComponentsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export type ComponentProps = {
value: string;
onKeyDown: (event: KeyboardEvent<HTMLInputElement>) => void;
onChange: (event: ChangeEvent<HTMLInputElement>) => void;
onClickCapture?: (event: MouseEvent<HTMLInputElement>) => void;
onSubmit?: () => void;
autoComplete?: HTMLInputAutoCompleteAttribute;
"aria-activedescendant"?: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/shadcn/src/form/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const TextInput = forwardRef<
disabled,
onKeyDown,
onChange,
onClickCapture,
onSubmit,
autoComplete: _autoComplete,
"aria-activedescendant": ariaActivedescendant,
Expand Down Expand Up @@ -57,6 +58,7 @@ export const TextInput = forwardRef<
value={value}
onKeyDown={onKeyDown}
onChange={onChange}
onClickCapture={onClickCapture}
onSubmit={onSubmit}
ref={ref}
aria-activedescendant={ariaActivedescendant}
Expand Down
Loading