Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: remove extra comments & add description for handleKeyDown
  • Loading branch information
filippovskii09 committed Oct 29, 2025
commit 5199cee319e77e561218c0e65fc33373ca3d7cf5
Copy link
Author

@filippovskii09 filippovskii09 Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added this custom hook useSidebarFocusAndKeyboard.js to separate the logic which we added in this PR
because a lot of logic interfered with orientation in the component

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export const useSidebarFocusAndKeyboard = (sidebarId, triggerButtonSelector = '.
focusSidebarTriggerBtn();
}, [toggleSidebar, focusSidebarTriggerBtn]);

/**
* Handles Tab key navigation when focus is on the standard sidebar close button.
* Implements the logic for moving focus out of the sidebar to specific elements
* on the main page in a predefined sequence, or back to the trigger button on Shift+Tab.
*
* @param {KeyboardEvent} event - The keyboard event object.
*/
const handleKeyDown = useCallback((event) => {
if (event.key !== 'Tab') {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// hooks/useSidebarFocusAndKeyboard.test.js (або .jsx)
import { renderHook, act } from '@testing-library/react';
import SidebarContext from '../../SidebarContext';
import { useSidebarFocusAndKeyboard } from './useSidebarFocusAndKeyboard';
Expand Down Expand Up @@ -165,7 +164,6 @@ describe('useSidebarFocusAndKeyboard', () => {
});

expect(mockEvent.preventDefault).toHaveBeenCalledTimes(1);
// Перевіряємо фокус тригера
act(() => { jest.runAllTimers(); });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
act(() => { jest.runAllTimers(); });
act(() => jest.runAllTimers());

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

expect(triggerButtonMock.focus).toHaveBeenCalledTimes(1);
expect(tryFocusAndPreventDefault).not.toHaveBeenCalled();
Expand Down