mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-22 10:21:37 +00:00
[Keyboard Navigation - Azure Cosmos DB - Data Explorer]: Keyboard focus is not retaining back to 'more' button after closing 'Delete container' dialog. (#1978)
* [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>
This commit is contained in:
@@ -7,12 +7,20 @@ export interface SidePanelState {
|
||||
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: () => set((state) => ({ ...state, isOpen: false })),
|
||||
closeSidePanel: () => {
|
||||
const lastFocusedElement = useSidePanel.getState().getRef;
|
||||
set((state) => ({ ...state, isOpen: false }));
|
||||
const timeoutId = setTimeout(() => {
|
||||
lastFocusedElement?.current?.focus();
|
||||
set({ getRef: undefined });
|
||||
}, 300);
|
||||
return () => clearTimeout(timeoutId);
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user