-
-
Notifications
You must be signed in to change notification settings - Fork 763
fix: expose first suggestion as active descendant #2965
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
Merged
nperez0111
merged 2 commits into
TypeCellOS:main
from
pupuking723:fix/suggestion-menu-active-descendant-zero
Aug 12, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
packages/react/src/components/SuggestionMenu/SuggestionMenuWrapper.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import { act } from "react"; | ||
| import { createRoot, type Root } from "react-dom/client"; | ||
| import { | ||
| afterEach, | ||
| beforeEach, | ||
| describe, | ||
| expect, | ||
| it, | ||
| vi, | ||
| } from "vite-plus/test"; | ||
|
|
||
| import { GridSuggestionMenuWrapper } from "./GridSuggestionMenu/GridSuggestionMenuWrapper.js"; | ||
| import { SuggestionMenuWrapper } from "./SuggestionMenuWrapper.js"; | ||
|
|
||
| const mocks = vi.hoisted(() => ({ | ||
| selectedIndex: undefined as number | undefined, | ||
| setContentEditableProps: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("../../editor/BlockNoteContext.js", () => ({ | ||
| useBlockNoteContext: () => ({ | ||
| setContentEditableProps: mocks.setContentEditableProps, | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("../../hooks/useBlockNoteEditor.js", () => ({ | ||
| useBlockNoteEditor: () => ({}), | ||
| })); | ||
|
|
||
| vi.mock("./hooks/useLoadSuggestionMenuItems.js", () => ({ | ||
| useLoadSuggestionMenuItems: () => ({ | ||
| items: ["first", "second", "third"], | ||
| usedQuery: "", | ||
| loadingState: "loaded", | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("./hooks/useCloseSuggestionMenuNoItems.js", () => ({ | ||
| useCloseSuggestionMenuNoItems: () => undefined, | ||
| })); | ||
|
|
||
| vi.mock("./hooks/useSuggestionMenuKeyboardNavigation.js", () => ({ | ||
| useSuggestionMenuKeyboardNavigation: () => ({ | ||
| selectedIndex: mocks.selectedIndex, | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock( | ||
| "./GridSuggestionMenu/hooks/useGridSuggestionMenuKeyboardNavigation.js", | ||
| () => ({ | ||
| useGridSuggestionMenuKeyboardNavigation: () => ({ | ||
| selectedIndex: mocks.selectedIndex, | ||
| }), | ||
| }), | ||
| ); | ||
|
|
||
| type ContentEditableProps = { | ||
| "aria-activedescendant"?: string; | ||
| "aria-controls"?: string; | ||
| "aria-expanded"?: boolean; | ||
| }; | ||
|
|
||
| let container: HTMLDivElement; | ||
| let root: Root; | ||
| let contentEditableProps: ContentEditableProps; | ||
|
|
||
| beforeEach(() => { | ||
| container = document.createElement("div"); | ||
| document.body.appendChild(container); | ||
| root = createRoot(container); | ||
| contentEditableProps = {}; | ||
| mocks.selectedIndex = undefined; | ||
| mocks.setContentEditableProps.mockImplementation( | ||
| (update: (props: ContentEditableProps) => ContentEditableProps) => { | ||
| contentEditableProps = update(contentEditableProps); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await act(async () => root.unmount()); | ||
| document.body.removeChild(container); | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| function Menu() { | ||
| return null; | ||
| } | ||
|
|
||
| function renderWrapper(type: "list" | "grid") { | ||
| const commonProps = { | ||
| query: "", | ||
| closeMenu: vi.fn(), | ||
| clearQuery: vi.fn(), | ||
| getItems: async () => ["first", "second", "third"], | ||
| }; | ||
|
|
||
| return act(async () => { | ||
| root.render( | ||
| type === "list" ? ( | ||
| <SuggestionMenuWrapper | ||
| {...commonProps} | ||
| suggestionMenuComponent={Menu} | ||
| /> | ||
| ) : ( | ||
| <GridSuggestionMenuWrapper | ||
| {...commonProps} | ||
| columns={2} | ||
| gridSuggestionMenuComponent={Menu} | ||
| /> | ||
| ), | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| describe.each(["list", "grid"] as const)( | ||
| "%s suggestion menu wrapper", | ||
| (type) => { | ||
| it("updates and clears aria-activedescendant", async () => { | ||
| mocks.selectedIndex = 0; | ||
| await renderWrapper(type); | ||
| expect(contentEditableProps["aria-activedescendant"]).toBe( | ||
| "bn-suggestion-menu-item-0", | ||
| ); | ||
|
|
||
| mocks.selectedIndex = 2; | ||
| await renderWrapper(type); | ||
| expect(contentEditableProps["aria-activedescendant"]).toBe( | ||
| "bn-suggestion-menu-item-2", | ||
| ); | ||
|
|
||
| mocks.selectedIndex = undefined; | ||
| await renderWrapper(type); | ||
| expect(contentEditableProps["aria-activedescendant"]).toBeUndefined(); | ||
|
|
||
| mocks.selectedIndex = 0; | ||
| await renderWrapper(type); | ||
| await act(async () => root.unmount()); | ||
| expect(contentEditableProps["aria-activedescendant"]).toBeUndefined(); | ||
| }); | ||
| }, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/react/src/components/SuggestionMenu/getSuggestionMenuItemId.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export function getSuggestionMenuItemId(selectedIndex: number | undefined) { | ||
| return selectedIndex !== undefined | ||
| ? "bn-suggestion-menu-item-" + selectedIndex | ||
| : undefined; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 20042
🏁 Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 212
🏁 Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 11649
🏁 Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 6723
Add wrapper-level
aria-activedescendantcoverageNo test file covers either wrapper or this attribute. Add tests for index
0, a later index,undefined, and cleanup through both wrappers.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added direct wrapper coverage in 00624ef. The tests render both the list and grid wrappers, exercise index 0, a later index, and undefined, and verify unmount cleanup clears aria-activedescendant. The full @blocknote/react test and lint commands pass locally.