Skip to content

wip: misc accessibility fixes #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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: 4 additions & 1 deletion examples/03-theming/03-theming-css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
}

/* Makes slash menu hovered items blue */
.bn-container[data-theming-css-demo] .bn-slash-menu .mantine-Menu-item[data-hovered] {
.bn-container[data-theming-css-demo]
.bn-slash-menu
.mantine-Menu-item[aria-selected="true"],
.bn-container[data-theming-css-demo] .bn-slash-menu .mantine-Menu-item:hover {
background-color: blue;
}
110 changes: 106 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { InputRule } from "@tiptap/core";
import { getCurrentBlockContentType } from "../../../api/getCurrentBlockContentType";
import {
PropSchema,
createBlockSpecFromStronglyTypedTiptapNode,
Expand All @@ -7,7 +8,6 @@ import {
import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers";
import { defaultProps } from "../../defaultProps";
import { handleEnter } from "../ListItemKeyboardShortcuts";
import { getCurrentBlockContentType } from "../../../api/getCurrentBlockContentType";

export const bulletListItemPropSchema = {
...defaultProps,
Expand Down Expand Up @@ -124,6 +124,7 @@ const BulletListItemBlockContent = createStronglyTypedTiptapNode({
{
...(this.options.domAttributes?.blockContent || {}),
...HTMLAttributes,
role: "listitem",
},
this.options.domAttributes?.inlineContent || {}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { InputRule } from "@tiptap/core";
import { getCurrentBlockContentType } from "../../../api/getCurrentBlockContentType";
import {
PropSchema,
createBlockSpecFromStronglyTypedTiptapNode,
Expand All @@ -8,7 +9,6 @@ import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers";
import { defaultProps } from "../../defaultProps";
import { handleEnter } from "../ListItemKeyboardShortcuts";
import { NumberedListIndexingPlugin } from "./NumberedListIndexingPlugin";
import { getCurrentBlockContentType } from "../../../api/getCurrentBlockContentType";

export const numberedListItemPropSchema = {
...defaultProps,
Expand Down Expand Up @@ -145,6 +145,7 @@ const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
{
...(this.options.domAttributes?.blockContent || {}),
...HTMLAttributes,
role: "listitem",
},
this.options.domAttributes?.inlineContent || {}
);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/editor/BlockNoteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import {
PartialBlock,
} from "../blocks/defaultBlocks";
import { FormattingToolbarProsemirrorPlugin } from "../extensions/FormattingToolbar/FormattingToolbarPlugin";
import { ImagePanelProsemirrorPlugin } from "../extensions/ImagePanel/ImageToolbarPlugin";
import { LinkToolbarProsemirrorPlugin } from "../extensions/LinkToolbar/LinkToolbarPlugin";
import { SideMenuProsemirrorPlugin } from "../extensions/SideMenu/SideMenuPlugin";
import { SuggestionMenuProseMirrorPlugin } from "../extensions/SuggestionMenu/SuggestionPlugin";
import { ImagePanelProsemirrorPlugin } from "../extensions/ImagePanel/ImageToolbarPlugin";
import { TableHandlesProsemirrorPlugin } from "../extensions/TableHandles/TableHandlesPlugin";
import { UniqueID } from "../extensions/UniqueID/UniqueID";
import {
Expand Down Expand Up @@ -781,7 +781,7 @@ export class BlockNoteEditor<
* @param styles The styles to remove.
*/
public removeStyles(styles: Styles<SSchema>) {
this._tiptapEditor.view.focus();
// this._tiptapEditor.view.focus();

for (const style of Object.keys(styles)) {
this._tiptapEditor.commands.unsetMark(style);
Expand All @@ -793,7 +793,7 @@ export class BlockNoteEditor<
* @param styles The styles to toggle.
*/
public toggleStyles(styles: Styles<SSchema>) {
this._tiptapEditor.view.focus();
// this._tiptapEditor.view.focus();

for (const [style, value] of Object.entries(styles)) {
const config = this.schema.styleSchema[style];
Expand Down
16 changes: 14 additions & 2 deletions packages/core/src/editor/BlockNoteExtensions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Extensions, extensions } from "@tiptap/core";
import { Extension, Extensions, extensions } from "@tiptap/core";

import type { BlockNoteEditor } from "./BlockNoteEditor";

Expand Down Expand Up @@ -92,10 +92,22 @@ export const getBlockNoteExtensions = <
BackgroundColorExtension,
TextAlignmentExtension,

// make sure escape blurs editor, so that we can tab to other elements in the host page (accessibility)
Extension.create({
name: "OverrideEscape",
addKeyboardShortcuts() {
return {
Escape: () => {
return this.editor.commands.blur();
},
};
},
}),

// nodes
Doc,
BlockContainer.configure({
editor: opts.editor as any,
editor: opts.editor,
domAttributes: opts.domAttributes,
}),
BlockGroup.configure({
Expand Down
15 changes: 9 additions & 6 deletions packages/core/src/editor/BlockNoteTipTapEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ export class BlockNoteTipTapEditor extends TiptapEditor {
private createViewAlternative() {
// Without queueMicrotask, custom IC / styles will give a React FlushSync error
queueMicrotask(() => {
this.view = new EditorView(this.options.element, {
...this.options.editorProps,
// @ts-ignore
dispatchTransaction: this.dispatchTransaction.bind(this),
state: this.state,
});
this.view = new EditorView(
{ mount: this.options.element as any },
{
...this.options.editorProps,
// @ts-ignore
dispatchTransaction: this.dispatchTransaction.bind(this),
state: this.state,
}
);

// `editor.view` is not yet available at this time.
// Therefore we will add all plugins and node views directly afterwards.
Expand Down
Loading