Skip to content

Commit 08bfcc1

Browse files
MDSAM05jbpenrathmatthewlipski
authored
Fix PageDown/PageUp scroll when slash menu is open (#2317)
* fix: update CreateLinkButton to be able to toggle popover visibility Resolve #2313 * Fix PageDown/PageUp scroll when slash menu is open * Small fix * Moved page up/down handling to keyboard navigation hook * Added e2e test --------- Co-authored-by: jbpenrath <jb.penrath@gmail.com> Co-authored-by: Matthew Lipski <matthewlipski@gmail.com> Co-authored-by: Matthew Lipski <50169049+matthewlipski@users.noreply.github.com>
1 parent 6f4239f commit 08bfcc1

File tree

8 files changed

+31
-3
lines changed

8 files changed

+31
-3
lines changed

packages/react/src/components/SuggestionMenu/hooks/useSuggestionMenuKeyboardHandler.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { useState } from "react";
44
// & down arrow keys are used to select an item, enter is used to execute it.
55
export function useSuggestionMenuKeyboardHandler<Item>(
66
items: Item[],
7-
onItemClick?: (item: Item) => void
7+
onItemClick?: (item: Item) => void,
88
) {
99
const [selectedIndex, setSelectedIndex] = useState<number>(0);
1010

@@ -23,7 +23,6 @@ export function useSuggestionMenuKeyboardHandler<Item>(
2323
}
2424

2525
if (event.key === "ArrowDown") {
26-
// debugger;
2726
event.preventDefault();
2827

2928
if (items.length) {
@@ -33,6 +32,26 @@ export function useSuggestionMenuKeyboardHandler<Item>(
3332
return true;
3433
}
3534

35+
if (event.key === "PageUp") {
36+
event.preventDefault();
37+
38+
if (items.length) {
39+
setSelectedIndex(0);
40+
}
41+
42+
return true;
43+
}
44+
45+
if (event.key === "PageDown") {
46+
event.preventDefault();
47+
48+
if (items.length) {
49+
setSelectedIndex(items.length - 1);
50+
}
51+
52+
return true;
53+
}
54+
3655
const isComposing = isReactEvent(event)
3756
? event.nativeEvent.isComposing
3857
: event.isComposing;
@@ -53,7 +72,7 @@ export function useSuggestionMenuKeyboardHandler<Item>(
5372
}
5473

5574
function isReactEvent(
56-
event: KeyboardEvent | React.KeyboardEvent
75+
event: KeyboardEvent | React.KeyboardEvent,
5776
): event is React.KeyboardEvent {
5877
return (event as React.KeyboardEvent).nativeEvent !== undefined;
5978
}

tests/src/end-to-end/slashmenu/slashmenu.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ test.describe("Check SlashMenu Functionality", () => {
2727
await focusOnEditor(page);
2828
await openSlashMenu(page);
2929
});
30+
test("Should be able to use PageUp/Down to navigate", async ({ page }) => {
31+
await focusOnEditor(page);
32+
await openSlashMenu(page);
33+
await page.waitForTimeout(500);
34+
await page.keyboard.press("PageDown");
35+
expect(await page.screenshot()).toMatchSnapshot("slash_menu_page_down.png");
36+
await page.keyboard.press("PageUp");
37+
expect(await page.screenshot()).toMatchSnapshot("slash_menu_page_up.png");
38+
});
3039
test("Should be able to create h1", async ({ page }) => {
3140
await focusOnEditor(page);
3241
await executeSlashCommand(page, "h1");
44.6 KB
Loading
72.9 KB
Loading
151 KB
Loading
49.5 KB
Loading
75.8 KB
Loading
158 KB
Loading

0 commit comments

Comments
 (0)