mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-31 06:41:35 +00:00
* [accessibility-2262594]: [Keyboard Navigation - Azure Cosmos DB - Data Explorer]: Keyboard focus is not retaining back to 'more' button after closing 'Delete container' dialog. * Optimize closeSidePanel: add timeout cleanup to prevent memory leaks and ensure proper focus behavior --------- Co-authored-by: Satyapriya Bai <v-satybai@microsoft.com>
27 lines
1004 B
TypeScript
27 lines
1004 B
TypeScript
import create, { UseStore } from "zustand";
|
|
|
|
export interface SidePanelState {
|
|
isOpen: boolean;
|
|
panelWidth: string;
|
|
panelContent?: JSX.Element;
|
|
headerText?: string;
|
|
openSidePanel: (headerText: string, panelContent: JSX.Element, panelWidth?: string, onClose?: () => void) => void;
|
|
closeSidePanel: () => void;
|
|
getRef?: React.RefObject<HTMLElement>; // Optional ref for focusing the last element.
|
|
}
|
|
export const useSidePanel: UseStore<SidePanelState> = create((set) => ({
|
|
isOpen: false,
|
|
panelWidth: "440px",
|
|
openSidePanel: (headerText, panelContent, panelWidth = "440px") =>
|
|
set((state) => ({ ...state, headerText, panelContent, panelWidth, isOpen: true })),
|
|
closeSidePanel: () => {
|
|
const lastFocusedElement = useSidePanel.getState().getRef;
|
|
set((state) => ({ ...state, isOpen: false }));
|
|
const timeoutId = setTimeout(() => {
|
|
lastFocusedElement?.current?.focus();
|
|
set({ getRef: undefined });
|
|
}, 300);
|
|
return () => clearTimeout(timeoutId);
|
|
},
|
|
}));
|