Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 15 additions & 0 deletions code/core/src/manager-api/modules/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,13 @@ export const init: ModuleFn = ({ store, fullAPI, provider }) => {
}
});
}

if (!wasPanelShown) {
fullAPI.focusOnUIElement(focusableUIElements.addonPanel, {
forceFocus: true,
poll: true,
});
}
break;
}

Expand All @@ -402,6 +409,14 @@ export const init: ModuleFn = ({ store, fullAPI, provider }) => {
}
});
}

if (!wasNavShown) {
fullAPI.focusOnUIElement(focusableUIElements.sidebarRegion, {
forceFocus: true,
poll: true,
});
}

break;
}

Expand Down
2 changes: 1 addition & 1 deletion code/core/src/manager/components/panel/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const AddonPanel = React.memo<{
Addon panel
</h2>
<StatelessTabsView
id="storybook-panel-root"
id={focusableUIElements.storyPanelRoot}
showToolsWhenEmpty
emptyState={emptyState}
selected={selectedPanel ?? undefined}
Expand Down
16 changes: 5 additions & 11 deletions code/core/src/manager/components/preview/tools/addons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,19 @@ import { Consumer, types } from 'storybook/manager-api';
import type { Combo } from 'storybook/manager-api';

import { focusableUIElements } from '../../../../manager-api/modules/layout';
import { useRegionFocusAnimation } from '../../layout/useLandmarkIndicator';

const SHOW_ADDON_PANEL_BUTTON_ID = 'storybook-show-addon-panel';

const menuMapper = ({ api, state }: Combo) => ({
isVisible: api.getIsPanelShown(),
singleStory: state.singleStory,
panelPosition: state.layout.panelPosition,
showPanel: async (animateLandmark?: (e: HTMLElement | null) => void) => {
showPanel: async (forceFocus: boolean) => {
api.togglePanel(true);
const success = await api.focusOnUIElement(focusableUIElements.addonPanel, {
forceFocus: true,
api.focusOnUIElement(focusableUIElements.addonPanel, {
forceFocus,
poll: true,
Comment thread
Sidnioulz marked this conversation as resolved.
});
if (success) {
animateLandmark?.(document.getElementById(focusableUIElements.addonPanel));
}
},
});

Expand All @@ -35,8 +31,6 @@ export const addonsTool: Addon_BaseType = {
type: types.TOOL,
match: ({ viewMode, tabId }) => viewMode === 'story' && !tabId,
render: () => {
const animateLandmark = useRegionFocusAnimation();

return (
<Consumer filter={menuMapper}>
{({ isVisible, showPanel, singleStory, panelPosition }) =>
Expand All @@ -49,11 +43,11 @@ export const addonsTool: Addon_BaseType = {
ariaLabel="Show addon panel"
id={SHOW_ADDON_PANEL_BUTTON_ID}
key="addons"
onClick={() => showPanel()}
onClick={() => showPanel(false)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
showPanel(animateLandmark);
showPanel(true);
}
}}
>
Expand Down
16 changes: 5 additions & 11 deletions code/core/src/manager/components/preview/tools/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@ import { Consumer, types } from 'storybook/manager-api';
import type { Combo } from 'storybook/manager-api';

import { focusableUIElements } from '../../../../manager-api/modules/layout';
import { useRegionFocusAnimation } from '../../layout/useLandmarkIndicator';

const menuMapper = ({ api, state }: Combo) => ({
isVisible: api.getIsNavShown(),
singleStory: state.singleStory,
viewMode: state.viewMode,
showSidebar: async (animateLandmark?: (e: HTMLElement | null) => void) => {
showSidebar: async (forceFocus: boolean) => {
api.toggleNav(true);
const success = await api.focusOnUIElement(focusableUIElements.sidebarRegion, {
forceFocus: true,
api.focusOnUIElement(focusableUIElements.sidebarRegion, {
forceFocus,
poll: true,
});
Comment thread
Sidnioulz marked this conversation as resolved.
if (success) {
animateLandmark?.(document.getElementById(focusableUIElements.sidebarRegion));
}
},
});

Expand All @@ -34,8 +30,6 @@ export const menuTool: Addon_BaseType = {
// @ts-expect-error (non strict)
match: ({ viewMode }) => ['story', 'docs'].includes(viewMode),
render: () => {
const animateLandmark = useRegionFocusAnimation();

return (
<Consumer filter={menuMapper}>
{({ isVisible, showSidebar, singleStory }) =>
Expand All @@ -48,11 +42,11 @@ export const menuTool: Addon_BaseType = {
ariaLabel="Show sidebar"
id={focusableUIElements.showSidebar}
key="menu"
onClick={() => showSidebar()}
onClick={() => showSidebar(false)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
showSidebar(animateLandmark);
showSidebar(true);
}
}}
>
Expand Down
Loading