Skip to content

Commit 657ef62

Browse files
authored
✨ add UseAccessibleKeybindings flag for better accessiblity (#55)
1 parent e6f89c8 commit 657ef62

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed

src/Spillgebees.Blazor.RichTextEditor.Assets/src/interfaces/spillgebees.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ interface EditorFunctions {
1919
theme: string,
2020
debugLevel: string,
2121
fonts: string[],
22-
eventDebounceIntervalInMilliseconds: number): Promise<void>;
22+
eventDebounceIntervalInMilliseconds: number,
23+
useAccessibleKeybindings: boolean): Promise<void>;
2324
setEditorEnabledState(quillContainer: HTMLElement, isEditorEnabled: boolean): void;
2425
getContent(quillContainer: HTMLElement): string;
2526
setContent(quillContainer: HTMLElement, content: string): void;

src/Spillgebees.Blazor.RichTextEditor.Assets/src/rich-text-editor.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ const createEditor = async (
4141
theme?: string | undefined,
4242
debugLevel?: string | boolean | undefined,
4343
fonts: string[] = new Array<string>,
44-
eventDebounceIntervalInMilliseconds: number = 500): Promise<void> => {
44+
eventDebounceIntervalInMilliseconds: number = 500,
45+
useAccessibleKeybindings: boolean = true): Promise<void> => {
4546

4647
Quill.register('modules/blotFormatter2', BlotFormatter2);
4748

@@ -53,8 +54,20 @@ const createEditor = async (
5354
Quill.register(fontAttributor, true);
5455
}
5556

56-
let quillOptions: any ={
57+
let customKeybindings = {};
58+
if (useAccessibleKeybindings)
59+
{
60+
customKeybindings = {
61+
// disables indenting with a tab character in favour of tabbing out of the component for accessibility
62+
tab: null
63+
};
64+
}
65+
66+
let quillOptions: any = {
5767
modules: {
68+
keyboard: {
69+
bindings: customKeybindings
70+
},
5871
toolbar: toolbar,
5972
blotFormatter2: {
6073
image: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<div>
2+
<h3>Setting the <code class="hljs">UseAccessibleKeybindings</code> parameter to <code class="hljs">true</code>
3+
overrides some of the Quill default keybindings for better accessibility. Currently this only overrides the
4+
default <code class="hljs">Tab</code> behaviour to tab out of the component instead of indenting the current
5+
line.</h3>
6+
<CodeSnippet Code="@Code">
7+
<Component>
8+
<CodeSnippet Code="@_content"
9+
CodeFormat="CodeFormat.Html"
10+
Summary="Show HTML">
11+
<Component>
12+
<RichTextEditor @bind-Content="@_content"
13+
UseAccessibleKeybindings="@true"
14+
ToolbarOptions="@ToolbarOptions.BasicToolbarOptions" />
15+
</Component>
16+
</CodeSnippet>
17+
</Component>
18+
</CodeSnippet>
19+
</div>
20+
21+
22+
@code {
23+
private const string Code =
24+
@"<RichTextEditor @bind-Content=""@_content""
25+
UseAccessibleKeybindings=""@true""
26+
ToolbarOptions=""@ToolbarOptions.BasicToolbarOptions"" />";
27+
28+
private string _content = "<b>Hello from an accessible editor! \ud83d\udc4b</b>";
29+
}

src/Spillgebees.Blazor.RichTextEditor.Samples/Spillgebees.Blazor.RichTextEditor.Samples.Shared/Pages/RichTextEditorExamplesPageContent.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
<IsEditorEnabledRichTextEditorExample />
3030

3131
<NoToolbarExample />
32+
33+
<AccessibleKeybindingsExample />
3234
</div>
3335

3436
<a href="other"

src/Spillgebees.Blazor.RichTextEditor/Components/BaseRichTextEditor.razor.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ public string? Text
8282
[Parameter]
8383
public int DebounceIntervalInMilliseconds { get; set; } = 500;
8484

85+
/// <summary>
86+
/// <para>
87+
/// This replaces default Quill keybindings for better accessibility, notably making the <c>Tab</c> character tab out of the component.
88+
/// </para>
89+
/// </summary>
90+
/// <remarks>
91+
/// Can only be set once. Defaults to <c>false</c> for backwards compatibility purposes but may be switched to <c>true</c> in future versions.
92+
/// </remarks>
93+
[Parameter]
94+
public bool UseAccessibleKeybindings { get; set; }
95+
8596
/// <summary>
8697
/// <para>
8798
/// Uses <see cref="Spillgebees.Blazor.RichTextEditor.Components.Toolbar.ToolbarOptions.BasicToolbarOptions"/> by default.
@@ -341,7 +352,8 @@ await RichTextEditorJs.CreateEditorAsync(
341352
theme: Theme.ToString().ToLower(),
342353
debugLevel: DebugLevel.ToString().ToLower(),
343354
fonts: ToolbarOptions.Fonts,
344-
DebounceIntervalInMilliseconds);
355+
DebounceIntervalInMilliseconds,
356+
UseAccessibleKeybindings);
345357

346358
InternalContent = Content;
347359
await SetContentAsync(Content);

src/Spillgebees.Blazor.RichTextEditor/Components/RichTextEditorJs.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ internal static ValueTask CreateEditorAsync(
2121
string theme,
2222
string debugLevel,
2323
List<string>? fonts,
24-
int debounceIntervalInMilliseconds = 0)
24+
int debounceIntervalInMilliseconds = 0,
25+
bool useAccessibleKeybindings = true)
2526
=> jsRuntime.SafeInvokeVoidAsync(
2627
logger,
2728
$"{JsNamespace}.createEditor",
@@ -35,7 +36,8 @@ internal static ValueTask CreateEditorAsync(
3536
theme,
3637
debugLevel,
3738
fonts,
38-
debounceIntervalInMilliseconds);
39+
debounceIntervalInMilliseconds,
40+
useAccessibleKeybindings);
3941

4042
internal static ValueTask<string> GetContentAsync(
4143
IJSRuntime jsRuntime,

0 commit comments

Comments
 (0)