Skip to content
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

[bug] Fixing search item in menu #6027

Merged
merged 4 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion lib/ui/src/containers/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const createMenu = memoize(1)((api, shortcutKeys, isFullscreen, showPanel, showN
{
id: '/',
title: 'Search',
onClick: () => {},
onClick: () => api.focusOnUIElement('storySearchField'),
right: shortcutToHumanString(shortcutKeys.search),
left: <ListItemIcon />,
},
Expand Down
18 changes: 18 additions & 0 deletions lib/ui/src/core/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import deprecate from 'util-deprecate';
import deepEqual from 'fast-deep-equal';

import { themes } from '@storybook/theming';
import { document } from 'global';
import merge from '../libs/merge';

const deprecatedThemeOptions = {
Expand Down Expand Up @@ -76,6 +77,12 @@ const initial = {
theme: themes.light,
};

const focusableUIElements = {
storySearchField: 'storybook-explorer-searchfield',
storyListMenu: 'storybook-explorer-menu',
storyPanelRoot: 'storybook-panel-root',
};

let hasSetOptions = false;
export default function({ store }) {
const api = {
Expand Down Expand Up @@ -149,6 +156,17 @@ export default function({ store }) {
});
},

focusOnUIElement(elementId) {
const focusableElementId = focusableUIElements[elementId];
if (focusableElementId == null) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: even if undefined == null can we change this check to be !focusableElements

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, it's what it was before, I was unsure of JS' best practices for that. Thanks!

return;
}
const element = document.getElementById(focusableElementId);
if (element) {
element.focus();
}
},

setOptions: options => {
// The very first time the user sets their options, we don't consider what is in the store.
// At this point in time, what is in the store is what we *persisted*. We did that in order
Expand Down
18 changes: 3 additions & 15 deletions lib/ui/src/core/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ export default function initShortcuts({ store }) {
if (!showNav) {
fullApi.toggleNav();
}
const element = document.getElementById('storybook-explorer-menu');

if (element) {
element.focus();
}
fullApi.focusOnUIElement('storyListMenu');
Copy link
Member

Choose a reason for hiding this comment

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

can you pull these constants out to be shared between modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, on it. 👍

Copy link
Member

@ndelangen ndelangen Mar 12, 2019

Choose a reason for hiding this comment

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

Yes, we'll change it to an enum later 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm then do you want me to just export them for now?

break;
}

Expand All @@ -103,11 +99,7 @@ export default function initShortcuts({ store }) {
}

setTimeout(() => {
const element = document.getElementById('storybook-explorer-searchfield');

if (element) {
element.focus();
}
fullApi.focusOnUIElement('storySearchField');
}, 0);
break;
}
Expand All @@ -133,11 +125,7 @@ export default function initShortcuts({ store }) {
if (!showPanel) {
fullApi.togglePanel();
}
const element = document.getElementById('storybook-panel-root');

if (element) {
element.focus();
}
fullApi.focusOnUIElement('storyPanelRoot');
break;
}

Expand Down